pub struct NetworkInstant(pub HashMap<Network, NetworkTime>);Expand description
A snapshot of network states across multiple chains / data sources.
Internally a HashMap<Network, NetworkTime>, where:
NetworkTimestores the actual point-in-time (block height or unix timestamp) together with the provider needed to query it.
use eth_prices::network::NetworkInstant;
let networks = NetworkInstant::default()
.with_evm_provider_latest(eth_provider).await?
.with_evm_provider_latest(sep_provider).await?
.with_now();Note that the above example makes a eth_chainId and eth_blockNumber query per provider supplied.
§Quoting at a given network time
Start with Default::default() and chain builder methods. Each builder consumes
and returns self, enabling a fluent style:
use eth_prices::network::NetworkInstant;
let networks = NetworkInstant::default()
.with_evm_block(1.into(), 123_456_789, eth_provider)
.with_evm_block(11155111.into(), 123_456_789, sep_provider)
.with_fiat_timestamp(time);For single-network convenience, start with NetworkTime::instant() instead.
Tuple Fields§
§0: HashMap<Network, NetworkTime>Implementations§
Source§impl NetworkInstant
impl NetworkInstant
Sourcepub fn get(&self, network_id: &Network) -> Option<&NetworkTime>
pub fn get(&self, network_id: &Network) -> Option<&NetworkTime>
Look up the NetworkTime for a given network.
Sourcepub fn get_evm_block(
&self,
network_id: Network,
) -> Option<(&NetworkId, &BlockNumber, &RpcProvider)>
pub fn get_evm_block( &self, network_id: Network, ) -> Option<(&NetworkId, &BlockNumber, &RpcProvider)>
Convenience accessor: extract the EVM fields for a specific chain.
Returns (chain_id, block_number, provider) if the network exists and is
an EVM variant.
Sourcepub fn get_fiat_timestamp(&self) -> Option<&u64>
pub fn get_fiat_timestamp(&self) -> Option<&u64>
Convenience accessor: extract the fiat timestamp (network id 0).
Sourcepub fn with_fiat_timestamp(self, timestamp: u64) -> Self
pub fn with_fiat_timestamp(self, timestamp: u64) -> Self
Set a fiat timestamp at network id 0.
Used by ecb quoters to pick a date.
Sourcepub fn with_now(self) -> Result<Self, EthPricesError>
pub fn with_now(self) -> Result<Self, EthPricesError>
Set a fiat timestamp to the current time.
Sourcepub fn with_evm_block(
self,
network_id: NetworkId,
block_number: BlockNumber,
provider: RpcProvider,
) -> Self
pub fn with_evm_block( self, network_id: NetworkId, block_number: BlockNumber, provider: RpcProvider, ) -> Self
Set an EVM network to a specific block number.
Use this when you already know the block height (e.g. from a historical query or configuration).
Sourcepub async fn with_evm_latest(
self,
network_id: NetworkId,
provider: RpcProvider,
) -> Result<Self, EthPricesError>
pub async fn with_evm_latest( self, network_id: NetworkId, provider: RpcProvider, ) -> Result<Self, EthPricesError>
Set an EVM network to the latest block, fetched from the RPC.
This is an async builder — it must be .awaited before further chaining:
let networks = NetworkInstant::default()
.with_evm_latest(1, eth_provider).await?
.with_evm_latest(42161, arb_provider).await?;pub async fn with_evm_provider( self, provider: RpcProvider, ) -> Result<Self, EthPricesError>
Trait Implementations§
Source§impl Clone for NetworkInstant
impl Clone for NetworkInstant
Source§fn clone(&self) -> NetworkInstant
fn clone(&self) -> NetworkInstant
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NetworkInstant
impl Debug for NetworkInstant
Source§impl Default for NetworkInstant
impl Default for NetworkInstant
Source§fn default() -> NetworkInstant
fn default() -> NetworkInstant
Auto Trait Implementations§
impl !RefUnwindSafe for NetworkInstant
impl !UnwindSafe for NetworkInstant
impl Freeze for NetworkInstant
impl Send for NetworkInstant
impl Sync for NetworkInstant
impl Unpin for NetworkInstant
impl UnsafeUnpin for NetworkInstant
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more