From 16ffe1da7625efa180e893c89606d4bb6db54554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Rosales?= Date: Fri, 17 Sep 2021 16:08:21 -0500 Subject: [PATCH] adds aliased types needed to describe EVM environment --- chain-evm/src/machine.rs | 43 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/chain-evm/src/machine.rs b/chain-evm/src/machine.rs index d56fe6fe7..ca5fb9ad5 100644 --- a/chain-evm/src/machine.rs +++ b/chain-evm/src/machine.rs @@ -9,7 +9,10 @@ //! ## StackState<'config> //! -use std::rc::Rc; +use std::{ + rc::Rc, + time::{SystemTime, UNIX_EPOCH}, +}; use evm::{ backend::{Apply, ApplyBackend, Backend, Basic, Log, MemoryVicinity}, @@ -23,6 +26,42 @@ use crate::state::AccountTrie; /// EVM Configuration. pub use evm::Config; +/// A block's chain ID. +pub type ChainId = U256; + +/// A block hash. +pub type BlockHash = H256; + +/// A block hash. +pub type BlockHashes = Vec; + +/// A block's number. +pub type BlockNumber = U256; + +/// A block's timestamp. +pub struct BlockTimestamp; + +impl BlockTimestamp { + /// Returns the time since `UNIX_EPOCH` as `U256` + pub fn now() -> U256 { + U256::from( + SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_secs(), + ) + } +} + +/// A block's difficulty. +pub type BlockDifficulty = U256; + +/// A block's gas limit. +pub type BlockGasLimit = U256; + +/// A block's origin +pub type Origin = H160; + /// Gas quantity integer for EVM operations. pub type Gas = U256; @@ -30,7 +69,7 @@ pub type Gas = U256; pub type GasPrice = U256; /// Gas limit for EVM operations. -pub type GasLimit = u64; +pub type GasLimit = U256; /// Integer of the value sent with an EVM transaction. pub type Value = U256;