Skip to content

Commit

Permalink
Add UTXO changes 2.0 endpoints (#695)
Browse files Browse the repository at this point in the history
* Add UTXO changes endpoints

* Remove index refs
  • Loading branch information
thibault-martinez committed Jul 17, 2023
1 parent 890c04a commit 4bf5870
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
32 changes: 30 additions & 2 deletions sdk/src/client/node_api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
types::{
api::core::response::{
BlockMetadataResponse, InfoResponse, PeerResponse, RoutesResponse, SubmitBlockResponse, TipsResponse,
UtxoChangesResponse,
},
block::{
output::{
Expand Down Expand Up @@ -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<UtxoChangesResponse> {
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<SlotCommitment> {
pub async fn get_slot_commitment_by_index(&self, slot_index: SlotIndex) -> Result<SlotCommitment> {
let path = &format!("api/core/v3/commitments/by-index/{slot_index}");

self.node_manager
Expand All @@ -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<Vec<u8>> {
pub async fn get_slot_commitment_by_index_raw(&self, slot_index: SlotIndex) -> Result<Vec<u8>> {
let path = &format!("api/core/v3/commitments/by-index/{slot_index}");

self.node_manager
Expand All @@ -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<UtxoChangesResponse> {
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
Expand Down
18 changes: 17 additions & 1 deletion sdk/src/types/api/core/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -279,3 +279,19 @@ pub struct PeerResponse {
pub struct RoutesResponse {
pub routes: Vec<String>,
}

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

0 comments on commit 4bf5870

Please sign in to comment.