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 authored and Alex Coats committed Jul 24, 2023
1 parent 08f4e72 commit e4e7737
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::{dto::OutputDto, Output, OutputId, OutputMetadata},
Expand Down Expand Up @@ -366,9 +367,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 @@ -380,7 +396,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 @@ -390,6 +406,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 @@ -4,7 +4,7 @@
use alloc::{string::String, vec::Vec};

use crate::types::block::{
output::{dto::OutputDto, OutputMetadata, OutputWithMetadata},
output::{dto::OutputDto, OutputId, OutputMetadata, OutputWithMetadata},
protocol::ProtocolParameters,
slot::SlotIndex,
BlockId, IssuerId,
Expand Down Expand Up @@ -276,3 +276,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 e4e7737

Please sign in to comment.