Skip to main content

r402_protocol/network/
mod.rs

1//! CAIP-2 network identifiers and chain-provider metadata.
2
3mod id;
4mod pattern;
5
6use std::sync::Arc;
7
8pub use id::{ChainId, ChainIdFormatError, NetworkInfo};
9pub use pattern::ChainIdPattern;
10
11/// Amount in the token's smallest unit plus the deployment it refers to.
12#[derive(Debug, Clone)]
13pub struct DeployedTokenAmount<TAmount, TToken> {
14    /// Amount in the token's smallest unit (wei, lamports, …).
15    pub amount: TAmount,
16    /// Token deployment (chain, address, decimals).
17    pub token: TToken,
18}
19
20/// Common operations available on all chain providers.
21pub trait ChainProvider {
22    /// Addresses of configured signers for this chain.
23    fn signer_addresses(&self) -> Vec<String>;
24
25    /// CAIP-2 chain identifier for this provider.
26    fn chain_id(&self) -> ChainId;
27}
28
29impl<T: ChainProvider> ChainProvider for Arc<T> {
30    fn signer_addresses(&self) -> Vec<String> {
31        (**self).signer_addresses()
32    }
33
34    fn chain_id(&self) -> ChainId {
35        (**self).chain_id()
36    }
37}