From 4bf587084393d996a838978c359a6ae4ae2f2ae9 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 29 Jun 2023 12:43:08 +0200 Subject: [PATCH] Add UTXO changes 2.0 endpoints (#695) * Add UTXO changes endpoints * Remove index refs --- sdk/src/client/node_api/core/routes.rs | 32 ++++++++++++++++++++++++-- sdk/src/types/api/core/response.rs | 18 ++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index f1b255db24..44fdf8697b 100644 --- a/sdk/src/client/node_api/core/routes.rs +++ b/sdk/src/client/node_api/core/routes.rs @@ -16,6 +16,7 @@ use crate::{ types::{ api::core::response::{ BlockMetadataResponse, InfoResponse, PeerResponse, RoutesResponse, SubmitBlockResponse, TipsResponse, + UtxoChangesResponse, }, block::{ output::{ @@ -365,9 +366,24 @@ impl ClientInner { .await } + /// Get all UTXO changes of a given slot by slot commitment ID. + /// GET /api/core/v3/commitments/{commitmentId}/utxo-changes + pub async fn get_utxo_changes_by_slot_commitment_id( + &self, + slot_commitment_id: &SlotCommitmentId, + ) -> Result { + let path = &format!("api/core/v3/commitments/{slot_commitment_id}/utxo-changes"); + + self.node_manager + .read() + .await + .get_request(path, None, self.get_timeout().await, false, false) + .await + } + /// Finds a slot commitment by slot index and returns it as object. /// GET /api/core/v3/commitments/by-index/{index} - pub async fn get_slot_commitment_by_index(&self, slot_index: &SlotIndex) -> Result { + pub async fn get_slot_commitment_by_index(&self, slot_index: SlotIndex) -> Result { let path = &format!("api/core/v3/commitments/by-index/{slot_index}"); self.node_manager @@ -379,7 +395,7 @@ impl ClientInner { /// Finds a slot commitment by slot index and returns it as raw bytes. /// GET /api/core/v3/commitments/by-index/{index} - pub async fn get_slot_commitment_by_index_raw(&self, slot_index: &SlotIndex) -> Result> { + pub async fn get_slot_commitment_by_index_raw(&self, slot_index: SlotIndex) -> Result> { let path = &format!("api/core/v3/commitments/by-index/{slot_index}"); self.node_manager @@ -389,6 +405,18 @@ impl ClientInner { .await } + /// Get all UTXO changes of a given slot by its index. + /// GET /api/core/v3/commitments/by-index/{index}/utxo-changes + pub async fn get_utxo_changes_by_slot_index(&self, slot_index: SlotIndex) -> Result { + let path = &format!("api/core/v3/commitments/by-index/{slot_index}/utxo-changes"); + + self.node_manager + .read() + .await + .get_request(path, None, self.get_timeout().await, false, false) + .await + } + // Peers routes. /// GET /api/core/v3/peers diff --git a/sdk/src/types/api/core/response.rs b/sdk/src/types/api/core/response.rs index 495e63c506..64d9d6387e 100644 --- a/sdk/src/types/api/core/response.rs +++ b/sdk/src/types/api/core/response.rs @@ -6,7 +6,7 @@ use alloc::{string::String, vec::Vec}; use crate::types::block::{ output::{ dto::{OutputDto, OutputMetadataDto}, - OutputWithMetadata, + OutputId, OutputWithMetadata, }, protocol::dto::ProtocolParametersDto, slot::SlotIndex, @@ -279,3 +279,19 @@ pub struct PeerResponse { pub struct RoutesResponse { pub routes: Vec, } + +/// Response of +/// - GET /api/core/v3/commitments/{commitmentId}/utxo-changes +/// - GET /api/core/v3/commitments/by-index/{index}/utxo-changes +/// Returns all UTXO changes that happened at a specific slot. +#[derive(Clone, Debug, Eq, PartialEq)] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "camelCase") +)] +pub struct UtxoChangesResponse { + pub index: u32, + pub created_outputs: Vec, + pub consumed_outputs: Vec, +}