Skip to main content

NetworkInstant

Struct NetworkInstant 

Source
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:

  • NetworkTime stores 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

Source

pub fn get(&self, network_id: &Network) -> Option<&NetworkTime>

Look up the NetworkTime for a given network.

Source

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.

Source

pub fn get_fiat_timestamp(&self) -> Option<&u64>

Convenience accessor: extract the fiat timestamp (network id 0).

Source

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.

Source

pub fn with_now(self) -> Result<Self, EthPricesError>

Set a fiat timestamp to the current time.

Source

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).

Source

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?;
Source

pub async fn with_evm_provider( self, provider: RpcProvider, ) -> Result<Self, EthPricesError>

Trait Implementations§

Source§

impl Clone for NetworkInstant

Source§

fn clone(&self) -> NetworkInstant

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NetworkInstant

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NetworkInstant

Source§

fn default() -> NetworkInstant

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more