Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UTXO changes full API #1776

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
kwek20 marked this conversation as resolved.
Show resolved Hide resolved
/// Index of the commitment to look up.
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
}
Expand Down
7 changes: 6 additions & 1 deletion bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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),
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
/// Response for:
/// - [`GetBlockWithMetadata`](crate::method::ClientMethod::GetBlockWithMetadata)
BlockWithMetadata(BlockWithMetadataResponse),
/// Response for:
Expand Down
22 changes: 21 additions & 1 deletion sdk/src/client/node_api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
&self,
slot_commitment_id: &SlotCommitmentId,
) -> Result<UtxoChangesFullResponse> {
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<SlotCommitment> {
Expand All @@ -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<UtxoChangesFullResponse> {
let path = &format!("api/core/v3/commitments/by-slot/{slot_index}/utxo-changes/full");

self.get_request(path, None, false, false).await
}
}

impl Client {
Expand Down
20 changes: 20 additions & 0 deletions sdk/src/types/api/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,26 @@ pub struct UtxoChangesResponse {
pub consumed_outputs: Vec<OutputId>,
}

/// 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<OutputWithId>,
pub consumed_outputs: Vec<OutputWithId>,
}

/// 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")]
Expand Down
Loading