alchemy_api/types/
common.rs

1use derive_builder::Builder;
2use ethers_core::types::{Address, U256};
3use serde::{Deserialize, Serialize};
4use serde_with::{serde_as, skip_serializing_none};
5
6/// Cursor object.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct Cursor {
9    after: Option<String>,
10}
11
12/// Information for pagination.
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct PaginationObject {
15    cursors: Cursor,
16    total_count: u64,
17}
18
19/// NFT information for webhook filtering.
20#[serde_as]
21#[skip_serializing_none]
22#[derive(Default, Builder, Debug, Clone, Serialize, Deserialize)]
23#[builder(setter(into, strip_option), build_fn(validate = "Self::validate"))]
24pub struct NftFilter {
25    /// Contract address for an NFT. If this field and the `token_id` aren't set all metadata
26    /// updates will be sent.
27    contract_address: Address,
28    /// Token ID for an NFT. Can be decimal or "0x" prefixed hex integer string. If this field and
29    /// the `token_id` aren't set all metadata updates will be sent. This field can't be set if the
30    /// `contract_address` field isn't set.
31    #[builder(default)]
32    token_id: Option<U256>,
33}
34
35impl NftFilter {
36    /// Create a builder for the endpoint.
37    pub fn builder() -> NftFilterBuilder {
38        NftFilterBuilder::default()
39    }
40}
41
42impl NftFilterBuilder {
43    fn validate(&self) -> Result<(), String> {
44        if self.token_id.is_some() && self.contract_address.is_none() {
45            return Err("cannot set token_id if the contract_address is not set".to_string());
46        }
47        Ok(())
48    }
49}