archway_bindings/
query.rs

1use cosmwasm_schema::{cw_serde, QueryResponses};
2use cosmwasm_std::CustomQuery;
3
4use crate::pagination::PageRequest;
5use crate::types::{gov, rewards};
6
7/// Queries for Archway's bindings.
8#[cw_serde]
9#[derive(QueryResponses)]
10pub enum ArchwayQuery {
11    /// Returns a [rewards::ContractMetadataResponse] for the given contract address.
12    #[returns(rewards::ContractMetadataResponse)]
13    ContractMetadata { contract_address: String },
14    /// Returns a [rewards::FlatFeeResponse for the given contract address.
15    #[returns(rewards::FlatFeeResponse)]
16    FlatFee { contract_address: String },
17    /// Returns a [rewards::RewardsRecordsResponse] containing a list of [rewards::RewardsRecord]
18    /// objects that are credited for the account and are ready to be withdrawn. The request is
19    /// paginated. If the limit field is not set, the governance param `rewards.MaxWithdrawRecords`
20    /// is used.
21    #[returns(rewards::RewardsRecordsResponse)]
22    RewardsRecords {
23        rewards_address: String,
24        pagination: Option<PageRequest>,
25    },
26    /// Returns a [gov::VoteResponse] for the given proposal ID and voter.
27    #[returns(gov::VoteResponse)]
28    GovVote { proposal_id: u64, voter: String },
29}
30
31impl CustomQuery for ArchwayQuery {}
32
33impl ArchwayQuery {
34    /// Builds a query to get the contract metadata for the given contract address.
35    pub fn contract_metadata(contract_address: impl Into<String>) -> Self {
36        ArchwayQuery::ContractMetadata {
37            contract_address: contract_address.into(),
38        }
39    }
40
41    /// Builds a query to get the flat fee for the given contract address.
42    pub fn flat_fee(contract_address: impl Into<String>) -> Self {
43        ArchwayQuery::FlatFee {
44            contract_address: contract_address.into(),
45        }
46    }
47
48    /// Builds a query to list the rewards records for the given rewards address.
49    pub fn rewards_records(rewards_address: impl Into<String>) -> Self {
50        ArchwayQuery::RewardsRecords {
51            rewards_address: rewards_address.into(),
52            pagination: None,
53        }
54    }
55
56    /// Builds a query to get a list of rewards records for the given rewards address with
57    /// pagination.
58    pub fn rewards_records_with_pagination(
59        rewards_address: impl Into<String>,
60        pagination: PageRequest,
61    ) -> Self {
62        ArchwayQuery::RewardsRecords {
63            rewards_address: rewards_address.into(),
64            pagination: Some(pagination),
65        }
66    }
67
68    /// Builds a query to get the vote for the given proposal ID and voter.
69    pub fn gov_vote(proposal_id: u64, voter: impl Into<String>) -> Self {
70        ArchwayQuery::GovVote {
71            proposal_id,
72            voter: voter.into(),
73        }
74    }
75}