Skip to content

Commit

Permalink
Core/Indexer API changes (#1672)
Browse files Browse the repository at this point in the history
* by-index -> by-slot

* indexer changes

* Renames

* Nit
  • Loading branch information
thibault-martinez authored Nov 27, 2023
1 parent a116dbf commit 94c5d35
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
29 changes: 16 additions & 13 deletions sdk/src/client/node_api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{
ValidatorResponse, ValidatorsResponse,
},
block::{
address::ToBech32Ext,
output::{dto::OutputDto, AccountId, Output, OutputId, OutputMetadata},
payload::signed_transaction::TransactionId,
slot::{EpochIndex, SlotCommitment, SlotCommitmentId, SlotIndex},
Expand Down Expand Up @@ -86,9 +87,10 @@ impl ClientInner {
}

/// Checks if the account is ready to issue a block.
/// GET /api/core/v3/accounts/{accountId}/congestion
/// GET /api/core/v3/accounts/{bech32Address}/congestion
pub async fn get_account_congestion(&self, account_id: &AccountId) -> Result<CongestionResponse> {
let path = &format!("api/core/v3/accounts/{account_id}/congestion");
let bech32_address = account_id.to_bech32(self.get_bech32_hrp().await?);
let path = &format!("api/core/v3/accounts/{bech32_address}/congestion");

self.get_request(path, None, false, false).await
}
Expand Down Expand Up @@ -147,9 +149,10 @@ impl ClientInner {
}

/// Return information about a validator.
/// GET /api/core/v3/validators/{accountId}
/// GET /api/core/v3/validators/{bech32Address}
pub async fn get_validator(&self, account_id: &AccountId) -> Result<ValidatorResponse> {
let path = &format!("api/core/v3/validators/{account_id}");
let bech32_address = account_id.to_bech32(self.get_bech32_hrp().await?);
let path = &format!("api/core/v3/validators/{bech32_address}");

self.get_request(path, None, false, false).await
}
Expand Down Expand Up @@ -306,25 +309,25 @@ 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<SlotCommitment> {
let path = &format!("api/core/v3/commitments/by-index/{slot_index}");
/// GET /api/core/v3/commitments/by-slot/{slot}
pub async fn get_slot_commitment_by_slot(&self, slot_index: SlotIndex) -> Result<SlotCommitment> {
let path = &format!("api/core/v3/commitments/by-slot/{slot_index}");

self.get_request(path, None, false, true).await
}

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

self.get_request_bytes(path, None).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");
/// GET /api/core/v3/commitments/by-slot/{slot}/utxo-changes
pub async fn get_utxo_changes_by_slot(&self, slot_index: SlotIndex) -> Result<UtxoChangesResponse> {
let path = &format!("api/core/v3/commitments/by-slot/{slot_index}/utxo-changes");

self.get_request(path, None, false, false).await
}
Expand Down
20 changes: 13 additions & 7 deletions sdk/src/client/node_api/indexer/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use crate::{
},
types::{
api::plugins::indexer::OutputIdsResponse,
block::output::{AccountId, AnchorId, DelegationId, FoundryId, NftId, OutputId},
block::{
address::ToBech32Ext,
output::{AccountId, AnchorId, DelegationId, FoundryId, NftId, OutputId},
},
},
};

Expand Down Expand Up @@ -53,9 +56,10 @@ impl ClientInner {
}

/// Get account output by its accountID.
/// api/indexer/v2/outputs/account/:{AccountId}
/// api/indexer/v2/outputs/account/{bech32Address}
pub async fn account_output_id(&self, account_id: AccountId) -> Result<OutputId> {
let route = format!("api/indexer/v2/outputs/account/{account_id}");
let bech32_address = account_id.to_bech32(self.get_bech32_hrp().await?);
let route = format!("api/indexer/v2/outputs/account/{bech32_address}");

Ok(*(self
.get_output_ids(&route, AccountOutputQueryParameters::new(), true, false)
Expand All @@ -75,9 +79,10 @@ impl ClientInner {
}

/// Get anchor output by its anchorID.
/// api/indexer/v2/outputs/anchor/:{AnchorId}
/// api/indexer/v2/outputs/anchor/{bech32Address}
pub async fn anchor_output_id(&self, anchor_id: AnchorId) -> Result<OutputId> {
let route = format!("api/indexer/v2/outputs/anchor/{anchor_id}");
let bech32_address = anchor_id.to_bech32(self.get_bech32_hrp().await?);
let route = format!("api/indexer/v2/outputs/anchor/{bech32_address}");

Ok(*(self
.get_output_ids(&route, AnchorOutputQueryParameters::new(), true, false)
Expand Down Expand Up @@ -146,9 +151,10 @@ impl ClientInner {
}

/// Get NFT output by its nftID.
/// api/indexer/v2/outputs/nft/:{NftId}
/// api/indexer/v2/outputs/nft/{bech32Address}
pub async fn nft_output_id(&self, nft_id: NftId) -> Result<OutputId> {
let route = format!("api/indexer/v2/outputs/nft/{nft_id}");
let bech32_address = nft_id.to_bech32(self.get_bech32_hrp().await?);
let route = format!("api/indexer/v2/outputs/nft/{bech32_address}");

Ok(*(self
.get_output_ids(&route, NftOutputQueryParameters::new(), true, false)
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/api/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ pub struct RoutesResponse {

/// Response of
/// - GET /api/core/v3/commitments/{commitmentId}/utxo-changes
/// - GET /api/core/v3/commitments/by-index/{index}/utxo-changes
/// - GET /api/core/v3/commitments/by-slot/{slot}/utxo-changes
/// Returns all UTXO changes that happened at a specific slot.
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl MinimumOutputAmount for Output {}
pub trait MinimumOutputAmount: StorageScore {
/// Computes the minimum amount of this output given [`StorageScoreParameters`].
fn minimum_amount(&self, params: StorageScoreParameters) -> u64 {
params.storage_cost() * self.storage_score(params)
self.storage_score(params) * params.storage_cost()
}
}

Expand Down

0 comments on commit 94c5d35

Please sign in to comment.