Skip to main content

clear_signing/
provider.rs

1//! Unified async data provider trait for external data resolution.
2//!
3//! Wallets implement [`DataProvider`] to supply token metadata, address names,
4//! and NFT collection names during formatting.
5
6use std::future::Future;
7use std::pin::Pin;
8
9use crate::token::TokenMeta;
10
11/// Async data provider for external data resolution during formatting.
12///
13/// Wallets implement this trait to supply token metadata, ENS/local address names,
14/// and NFT collection names. All methods have default implementations returning `None`,
15/// so implementors only need to override the methods they support.
16pub trait DataProvider: Send + Sync {
17    /// Resolve token metadata (symbol, decimals, name) for a given chain and address.
18    fn resolve_token(
19        &self,
20        chain_id: u64,
21        address: &str,
22    ) -> Pin<Box<dyn Future<Output = Option<TokenMeta>> + Send + '_>> {
23        let _ = (chain_id, address);
24        Box::pin(async { None })
25    }
26
27    /// Resolve an ENS name for an address.
28    ///
29    /// `types` hints the expected address role (e.g. `["eoa"]`, `["contract"]`).
30    fn resolve_ens_name(
31        &self,
32        address: &str,
33        chain_id: u64,
34        types: Option<&[String]>,
35    ) -> Pin<Box<dyn Future<Output = Option<String>> + Send + '_>> {
36        let _ = (address, chain_id, types);
37        Box::pin(async { None })
38    }
39
40    /// Resolve a local/contact name for an address.
41    ///
42    /// `types` hints the expected address role (e.g. `["eoa"]`, `["contract"]`).
43    fn resolve_local_name(
44        &self,
45        address: &str,
46        chain_id: u64,
47        types: Option<&[String]>,
48    ) -> Pin<Box<dyn Future<Output = Option<String>> + Send + '_>> {
49        let _ = (address, chain_id, types);
50        Box::pin(async { None })
51    }
52
53    /// Resolve an NFT collection name for a collection contract address.
54    fn resolve_nft_collection_name(
55        &self,
56        collection_address: &str,
57        chain_id: u64,
58    ) -> Pin<Box<dyn Future<Output = Option<String>> + Send + '_>> {
59        let _ = (collection_address, chain_id);
60        Box::pin(async { None })
61    }
62
63    /// Resolve an approximate unix timestamp for a given block number.
64    fn resolve_block_timestamp(
65        &self,
66        chain_id: u64,
67        block_number: u64,
68    ) -> Pin<Box<dyn Future<Output = Option<u64>> + Send + '_>> {
69        let _ = (chain_id, block_number);
70        Box::pin(async { None })
71    }
72}
73
74/// No-op data provider — all methods return `None`.
75pub struct EmptyDataProvider;
76
77impl DataProvider for EmptyDataProvider {}