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 2.0 endpoints #656

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 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,7 @@ use crate::{
types::{
api::core::response::{
BlockMetadataResponse, BlockResponse, InfoResponse, OutputWithMetadataResponse, PeerResponse,
RoutesResponse, SubmitBlockResponse, TipsResponse,
RoutesResponse, SubmitBlockResponse, TipsResponse, UtxoChangesResponse,
},
block::{
output::{dto::OutputMetadataDto, Output, OutputId, OutputMetadata, OutputWithMetadata},
Expand Down Expand Up @@ -374,6 +374,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,
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
) -> 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
}

/// Gets the slot commitment by the given slot index.
/// GET /api/core/v3/commitments/by-index/{index}
pub async fn get_slot_commitment_by_index(&self, slot_index: &SlotIndex) -> Result<SlotCommitment> {
Expand All @@ -398,6 +413,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> {
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
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::{boxed::Box, string::String, vec::Vec};
use crate::types::block::{
output::{
dto::{OutputDto, OutputMetadataDto},
OutputWithMetadata,
OutputId, OutputWithMetadata,
},
protocol::dto::ProtocolParametersDto,
slot::SlotIndex,
Expand Down Expand Up @@ -300,3 +300,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>,
}