From 639dba96138564c618729c6701518c9c9dc8b982 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 13 Dec 2023 15:21:31 +0100 Subject: [PATCH] Add UTXO changes full API --- bindings/core/src/method/client.rs | 11 +++++++++++ bindings/core/src/method_handler/client.rs | 8 ++++++++ bindings/core/src/response.rs | 7 ++++++- sdk/src/client/node_api/core/routes.rs | 22 +++++++++++++++++++++- sdk/src/types/api/core.rs | 20 ++++++++++++++++++++ 5 files changed, 66 insertions(+), 2 deletions(-) diff --git a/bindings/core/src/method/client.rs b/bindings/core/src/method/client.rs index 90c3b593c7..9fd4892db9 100644 --- a/bindings/core/src/method/client.rs +++ b/bindings/core/src/method/client.rs @@ -273,6 +273,12 @@ pub enum ClientMethod { /// Commitment ID of the commitment to look up. commitment_id: SlotCommitmentId, }, + /// Get all full UTXO changes of a given slot by Commitment ID. + #[serde(rename_all = "camelCase")] + GetUtxoChangesFull { + /// Commitment ID of the commitment to look up. + commitment_id: SlotCommitmentId, + }, /// Look up a commitment by a given commitment index. GetCommitmentByIndex { /// Index of the commitment to look up. @@ -283,6 +289,11 @@ pub enum ClientMethod { /// Index of the commitment to look up. index: SlotIndex, }, + /// Get all full UTXO changes of a given slot by commitment index. + GetUtxoChangesFullByIndex { + /// Index of the commitment to look up. + index: SlotIndex, + }, ////////////////////////////////////////////////////////////////////// // Node indexer API diff --git a/bindings/core/src/method_handler/client.rs b/bindings/core/src/method_handler/client.rs index b2f6094c7d..b5f2ae738f 100644 --- a/bindings/core/src/method_handler/client.rs +++ b/bindings/core/src/method_handler/client.rs @@ -236,12 +236,20 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM ClientMethod::GetUtxoChanges { commitment_id } => { Response::UtxoChanges(client.get_utxo_changes_by_slot_commitment_id(&commitment_id).await?) } + ClientMethod::GetUtxoChangesFull { commitment_id } => Response::UtxoChangesFull( + client + .get_utxo_changes_full_by_slot_commitment_id(&commitment_id) + .await?, + ), ClientMethod::GetCommitmentByIndex { index } => { Response::SlotCommitment(client.get_slot_commitment_by_slot(index).await?) } ClientMethod::GetUtxoChangesByIndex { index } => { Response::UtxoChanges(client.get_utxo_changes_by_slot(index).await?) } + ClientMethod::GetUtxoChangesFullByIndex { index } => { + Response::UtxoChangesFull(client.get_utxo_changes_full_by_slot(index).await?) + } ClientMethod::OutputIds { query_parameters } => { Response::OutputIdsResponse(client.output_ids(query_parameters).await?) } diff --git a/bindings/core/src/response.rs b/bindings/core/src/response.rs index 8fe5a1761d..89cac737a3 100644 --- a/bindings/core/src/response.rs +++ b/bindings/core/src/response.rs @@ -18,7 +18,8 @@ use iota_sdk::{ core::{ BlockMetadataResponse, BlockWithMetadataResponse, CommitteeResponse, CongestionResponse, InfoResponse as NodeInfo, IssuanceBlockHeaderResponse, ManaRewardsResponse, OutputWithMetadataResponse, - TransactionMetadataResponse, UtxoChangesResponse, ValidatorResponse, ValidatorsResponse, + TransactionMetadataResponse, UtxoChangesFullResponse, UtxoChangesResponse, ValidatorResponse, + ValidatorsResponse, }, plugins::indexer::OutputIdsResponse, }, @@ -142,6 +143,10 @@ pub enum Response { /// - [`GetUtxoChangesByIndex`](crate::method::ClientMethod::GetUtxoChangesByIndex) UtxoChanges(UtxoChangesResponse), /// Response for: + /// - [`GetUtxoChangesFull`](crate::method::ClientMethod::GetUtxoChangesFull) + /// - [`GetUtxoChangesFullByIndex`](crate::method::ClientMethod::GetUtxoChangesFullByIndex) + UtxoChangesFull(UtxoChangesFullResponse), + /// Response for: /// - [`GetBlockWithMetadata`](crate::method::ClientMethod::GetBlockWithMetadata) BlockWithMetadata(BlockWithMetadataResponse), /// Response for: diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index db4e6d591b..39f7072303 100644 --- a/sdk/src/client/node_api/core/routes.rs +++ b/sdk/src/client/node_api/core/routes.rs @@ -18,7 +18,8 @@ use crate::{ api::core::{ BlockMetadataResponse, BlockWithMetadataResponse, CommitteeResponse, CongestionResponse, InfoResponse, IssuanceBlockHeaderResponse, ManaRewardsResponse, OutputResponse, RoutesResponse, SubmitBlockResponse, - TransactionMetadataResponse, UtxoChangesResponse, ValidatorResponse, ValidatorsResponse, + TransactionMetadataResponse, UtxoChangesFullResponse, UtxoChangesResponse, ValidatorResponse, + ValidatorsResponse, }, block::{ address::ToBech32Ext, @@ -333,6 +334,17 @@ impl ClientInner { self.get_request(path, None, false, false).await } + /// Get all full UTXO changes of a given slot by slot commitment ID. + /// GET /api/core/v3/commitments/{commitmentId}/utxo-changes/full + pub async fn get_utxo_changes_full_by_slot_commitment_id( + &self, + slot_commitment_id: &SlotCommitmentId, + ) -> Result { + let path = &format!("api/core/v3/commitments/{slot_commitment_id}/utxo-changes/full"); + + self.get_request(path, None, false, false).await + } + /// Finds a slot commitment by slot index and returns it as object. /// GET /api/core/v3/commitments/by-slot/{slot} pub async fn get_slot_commitment_by_slot(&self, slot_index: SlotIndex) -> Result { @@ -356,6 +368,14 @@ impl ClientInner { self.get_request(path, None, false, false).await } + + /// Get all full UTXO changes of a given slot by its index. + /// GET /api/core/v3/commitments/by-slot/{slot}/utxo-changes/full + pub async fn get_utxo_changes_full_by_slot(&self, slot_index: SlotIndex) -> Result { + let path = &format!("api/core/v3/commitments/by-slot/{slot_index}/utxo-changes/full"); + + self.get_request(path, None, false, false).await + } } impl Client { diff --git a/sdk/src/types/api/core.rs b/sdk/src/types/api/core.rs index a944bc01ca..39cee0fb51 100644 --- a/sdk/src/types/api/core.rs +++ b/sdk/src/types/api/core.rs @@ -468,6 +468,26 @@ pub struct UtxoChangesResponse { pub consumed_outputs: Vec, } +/// Response of +/// - GET /api/core/v3/commitments/{commitmentId}/utxo-changes/full +/// - GET /api/core/v3/commitments/by-slot/{slot}/utxo-changes/full +/// Returns all full UTXO changes that happened at a specific slot. +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct UtxoChangesFullResponse { + pub commitment_id: SlotCommitmentId, + pub created_outputs: Vec, + pub consumed_outputs: Vec, +} + +/// An Output and its ID. +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct OutputWithId { + pub output_id: OutputId, + pub output: Output, +} + /// Contains the generic [`Output`] with associated [`OutputIdProof`]. #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")]