Skip to content

Commit

Permalink
Add AnchorOutputQueryParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Oct 29, 2023
1 parent 9714589 commit 30ab60a
Showing 1 changed file with 70 additions and 42 deletions.
112 changes: 70 additions & 42 deletions sdk/src/client/node_api/indexer/query_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ pub struct AccountOutputQueryParameters {

impl_query_parameters_methods!(AccountOutputQueryParameters);

/// Query parameters for nft output requests.
/// Query parameters for anchor output requests.
#[derive(Setters, Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
#[setters(strip_option)]
#[serde(rename_all = "camelCase")]
pub struct NftOutputQueryParameters {
pub struct AnchorOutputQueryParameters {
/// Returns outputs that were created after a certain slot index.
created_after: Option<SlotIndex>,
/// Returns outputs that were created before a certain slot index.
Expand All @@ -186,50 +186,40 @@ pub struct NftOutputQueryParameters {
page_size: Option<usize>,
/// Returns outputs that are unlockable by the bech32 address.
unlockable_by_address: Option<Bech32Address>,
/// Bech32-encoded address that should be searched for.
address: Option<Bech32Address>,
/// Filters outputs based on the presence of a specific Bech32-encoded return address in the expiration unlock
/// condition.
expiration_return_address: Option<Bech32Address>,
/// Returns outputs that expire after a certain slot index.
expires_after: Option<SlotIndex>,
/// Returns outputs that expire before a certain slot index.
expires_before: Option<SlotIndex>,
/// Filters outputs based on the presence of expiration unlock condition.
has_expiration: Option<bool>,
/// Filters outputs based on the presence of storage deposit return unlock condition.
has_storage_deposit_return: Option<bool>,
/// Filters outputs based on the presence of timelock unlock condition.
has_timelock: Option<bool>,
/// Filters outputs based on the presence of validated Sender (bech32 encoded).
sender: Option<Bech32Address>,
/// Filters outputs based on bech32-encoded issuer address.
issuer: Option<Bech32Address>,
/// Filters outputs based on the presence of a specific return address in the storage deposit return unlock
/// condition.
storage_deposit_return_address: Option<Bech32Address>,
/// Filters outputs based on matching Tag Block.
tag: Option<String>,
/// Returns outputs that are timelocked after a certain slot index.
timelocked_after: Option<SlotIndex>,
/// Returns outputs that are timelocked before a certain slot index.
timelocked_before: Option<SlotIndex>,
/// Filters outputs based on bech32-encoded governor (governance controller) address.
governor: Option<Bech32Address>,
/// Filters outputs based on bech32-encoded state controller address.
state_controller: Option<Bech32Address>,
}

impl_query_parameters_methods!(NftOutputQueryParameters);
impl_query_parameters_methods!(AnchorOutputQueryParameters);

impl NftOutputQueryParameters {
/// Sets `.address(address).has_expiration(false).has_storage_deposit_return(false).has_timelock(false)` to only
/// get outputs that can be unlocked by the address without potential further restrictions.
pub fn only_address_unlock_condition(address: impl Into<Bech32Address>) -> Self {
Self::default()
.address(address.into())
.has_expiration(false)
.has_storage_deposit_return(false)
.has_timelock(false)
}
/// Query parameters for delegation output requests.
#[derive(Setters, Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
#[setters(strip_option)]
#[serde(rename_all = "camelCase")]
pub struct DelegationOutputQueryParameters {
/// Returns outputs that were created after a certain slot index.
created_after: Option<SlotIndex>,
/// Returns outputs that were created before a certain slot index.
created_before: Option<SlotIndex>,
/// Starts the search from the cursor (createdSlotIndex+outputId.pageSize).
cursor: Option<String>,
/// The maximum amount of items returned in one call. If there are more items, a cursor to the next page is
/// returned too. The parameter is ignored when pageSize is defined via the cursor parameter.
page_size: Option<usize>,
/// Bech32-encoded address that should be searched for.
address: Option<Bech32Address>,
/// Filter foundry outputs based on bech32-encoded address of the validator.
validator: Option<Bech32Address>,
}

impl_query_parameters_methods!(DelegationOutputQueryParameters);

/// Query parameters for foundry output requests.
#[derive(Setters, Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
#[setters(strip_option)]
Expand All @@ -254,11 +244,11 @@ pub struct FoundryOutputQueryParameters {

impl_query_parameters_methods!(FoundryOutputQueryParameters);

/// Query parameters for delegation output requests.
/// Query parameters for nft output requests.
#[derive(Setters, Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
#[setters(strip_option)]
#[serde(rename_all = "camelCase")]
pub struct DelegationOutputQueryParameters {
pub struct NftOutputQueryParameters {
/// Returns outputs that were created after a certain slot index.
created_after: Option<SlotIndex>,
/// Returns outputs that were created before a certain slot index.
Expand All @@ -268,13 +258,51 @@ pub struct DelegationOutputQueryParameters {
/// The maximum amount of items returned in one call. If there are more items, a cursor to the next page is
/// returned too. The parameter is ignored when pageSize is defined via the cursor parameter.
page_size: Option<usize>,
/// Returns outputs that are unlockable by the bech32 address.
unlockable_by_address: Option<Bech32Address>,
/// Bech32-encoded address that should be searched for.
address: Option<Bech32Address>,
/// Filter foundry outputs based on bech32-encoded address of the validator.
validator: Option<Bech32Address>,
/// Filters outputs based on the presence of a specific Bech32-encoded return address in the expiration unlock
/// condition.
expiration_return_address: Option<Bech32Address>,
/// Returns outputs that expire after a certain slot index.
expires_after: Option<SlotIndex>,
/// Returns outputs that expire before a certain slot index.
expires_before: Option<SlotIndex>,
/// Filters outputs based on the presence of expiration unlock condition.
has_expiration: Option<bool>,
/// Filters outputs based on the presence of storage deposit return unlock condition.
has_storage_deposit_return: Option<bool>,
/// Filters outputs based on the presence of timelock unlock condition.
has_timelock: Option<bool>,
/// Filters outputs based on the presence of validated Sender (bech32 encoded).
sender: Option<Bech32Address>,
/// Filters outputs based on bech32-encoded issuer address.
issuer: Option<Bech32Address>,
/// Filters outputs based on the presence of a specific return address in the storage deposit return unlock
/// condition.
storage_deposit_return_address: Option<Bech32Address>,
/// Filters outputs based on matching Tag Block.
tag: Option<String>,
/// Returns outputs that are timelocked after a certain slot index.
timelocked_after: Option<SlotIndex>,
/// Returns outputs that are timelocked before a certain slot index.
timelocked_before: Option<SlotIndex>,
}

impl_query_parameters_methods!(DelegationOutputQueryParameters);
impl_query_parameters_methods!(NftOutputQueryParameters);

impl NftOutputQueryParameters {
/// Sets `.address(address).has_expiration(false).has_storage_deposit_return(false).has_timelock(false)` to only
/// get outputs that can be unlocked by the address without potential further restrictions.
pub fn only_address_unlock_condition(address: impl Into<Bech32Address>) -> Self {
Self::default()
.address(address.into())
.has_expiration(false)
.has_storage_deposit_return(false)
.has_timelock(false)
}
}

#[cfg(test)]
mod tests {
Expand Down

0 comments on commit 30ab60a

Please sign in to comment.