pub enum NetworkTime {
EVM(NetworkId, BlockNumber, RpcProvider),
Fiat(u64),
}Expand description
A single point-in-time on a specific network.
Each variant carries the information needed to query a rate at that moment:
| Variant | Use case | Payload |
|---|---|---|
EVM(chain_id, block, provider) | On-chain asset quotes | chain ID, block height, RPC provider |
Fiat(timestamp) | ECB / off-chain fiat rates | Unix timestamp (seconds) |
§Converting to a NetworkInstant
Use instant() to wrap a single NetworkTime into a
NetworkInstant
use eth_prices::network::NetworkTime;
let time = NetworkTime::EVM(1, 20_000_000, provider);
let networks = time.instant();For multi-network scenarios (e.g. different EVM chains + a fiat timestamp) build a
NetworkInstant directly with its builder methods instead.
Variants§
EVM(NetworkId, BlockNumber, RpcProvider)
An EVM chain at a specific block height.
Fields: (chain_id, block_number, provider)
Fiat(u64)
An off-chain fiat timestamp (Unix seconds).
Implementations§
Source§impl NetworkTime
impl NetworkTime
Sourcepub fn as_evm(&self) -> Option<(&NetworkId, &BlockNumber, &RpcProvider)>
pub fn as_evm(&self) -> Option<(&NetworkId, &BlockNumber, &RpcProvider)>
Extract the EVM fields, if this is the EVM variant.
Sourcepub fn instant(self) -> NetworkInstant
pub fn instant(self) -> NetworkInstant
Convert this single NetworkTime into a NetworkInstant.
This is the simplest way to create a NetworkInstant when only one network
is needed. For multi-network scenarios build the NetworkInstant directly
with its default + builder methods.
pub async fn from_provider_latest( provider: RpcProvider, network_id: NetworkId, ) -> Result<Self, EthPricesError>
pub fn from_provider( provider: RpcProvider, network_id: NetworkId, block_number: BlockNumber, ) -> Self
Sourcepub fn with_fiat_now() -> Self
pub fn with_fiat_now() -> Self
Set a fiat timestamp to the current time.
Trait Implementations§
Source§impl Clone for NetworkTime
impl Clone for NetworkTime
Source§fn clone(&self) -> NetworkTime
fn clone(&self) -> NetworkTime
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for NetworkTime
impl !UnwindSafe for NetworkTime
impl Freeze for NetworkTime
impl Send for NetworkTime
impl Sync for NetworkTime
impl Unpin for NetworkTime
impl UnsafeUnpin for NetworkTime
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