From 90955d9814bbc1b6418fffc00f4449f56aac4666 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 21 Jun 2023 21:43:36 +0200 Subject: [PATCH 1/2] Add UTXO changes endpoints --- Cargo.lock | 24 +++++++++++----------- sdk/src/client/node_api/core/routes.rs | 28 ++++++++++++++++++++++++++ sdk/src/types/api/core/response.rs | 18 ++++++++++++++++- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ee0deaca0..f991e87800 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,15 +97,15 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" +checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" [[package]] name = "anstyle-parse" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" dependencies = [ "utf8parse", ] @@ -478,9 +478,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.4" +version = "4.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80672091db20273a15cf9fdd4e47ed43b5091ec9841bf4c6145c9dfbbcae09ed" +checksum = "2686c4115cb0810d9a984776e197823d08ec94f176549a89a9efded477c456dc" dependencies = [ "clap_builder", "clap_derive", @@ -489,9 +489,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.3.4" +version = "4.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1458a1df40e1e2afebb7ab60ce55c1fa8f431146205aa5f4887e0b111c27636" +checksum = "2e53afce1efce6ed1f633cf0e57612fe51db54a1ee4fd8f8503d078fe02d69ae" dependencies = [ "anstream", "anstyle", @@ -2328,9 +2328,9 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2b0377b720bde721213a46cda1289b2f34abf0a436907cad91578c20de0454d" +checksum = "9825a04601d60621feed79c4e6b56d65db77cdca55cef43b46b0de1096d1c282" dependencies = [ "proc-macro2", "syn 2.0.18", @@ -3173,9 +3173,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "target-lexicon" -version = "0.12.7" +version = "0.12.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd1ba337640d60c3e96bc6f0638a939b9c9a7f2c316a1598c279828b3d1dc8c5" +checksum = "1b1c7f239eb94671427157bd93b3694320f3668d4e1eff08c7285366fd777fac" [[package]] name = "thiserror" diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index 4b726cba49..407bb85316 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,6 +366,21 @@ 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 { @@ -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, +} From 62b88cd68b473e41839424a5e1b665f24b0d3b84 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 22 Jun 2023 09:58:03 +0200 Subject: [PATCH 2/2] Remove index refs --- sdk/src/client/node_api/core/routes.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index 407bb85316..0fbf348a7c 100644 --- a/sdk/src/client/node_api/core/routes.rs +++ b/sdk/src/client/node_api/core/routes.rs @@ -383,7 +383,7 @@ impl ClientInner { /// 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 @@ -395,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 @@ -407,7 +407,7 @@ impl ClientInner { /// 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 { + 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