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 #695

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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.

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>,
}
Loading