-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
94 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use primitives::{Address, B256}; | ||
|
||
/// Access list type is introduced in EIP-2930, and every | ||
/// transaction after it contains access list. | ||
/// | ||
/// Note | ||
/// | ||
/// Iterator over access list returns account address and storage slot keys that | ||
/// are warm loaded before transaction execution. | ||
/// | ||
/// Number of account and storage slots is used to calculate initial tx gas cost. | ||
pub trait AccessListTrait { | ||
/// Iterate over access list. | ||
fn iter(&self) -> impl Iterator<Item = (Address, impl Iterator<Item = B256>)>; | ||
|
||
/// Returns number of account and storage slots. | ||
fn num_account_storages(&self) -> (usize, usize) { | ||
let storage_num = self.iter().map(|i| i.1.count()).sum(); | ||
let account_num = self.iter().count(); | ||
|
||
(account_num, storage_num) | ||
} | ||
} | ||
|
||
// TODO move to default context | ||
use specification::eip2930::AccessList; | ||
|
||
impl AccessListTrait for AccessList { | ||
fn iter(&self) -> impl Iterator<Item = (Address, impl Iterator<Item = B256>)> { | ||
self.0.iter().map(|item| { | ||
let slots = item.storage_keys.iter().copied(); | ||
(item.address, slots) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,19 @@ | ||
use crate::CommonTxFields; | ||
use primitives::{Address, TxKind, B256}; | ||
|
||
// TODO move to specs impl iterator trait | ||
pub trait AccessListInterface { | ||
fn iter(&self) -> impl Iterator<Item = (Address, impl Iterator<Item = B256>)>; | ||
|
||
/// Not performant way to count number of account and storages. | ||
fn num_account_storages(&self) -> (usize, usize) { | ||
let storage_num = self.iter().map(|i| i.1.count()).sum(); | ||
let account_num = self.iter().count(); | ||
|
||
(account_num, storage_num) | ||
} | ||
} | ||
use crate::{AccessListTrait, CommonTxFields}; | ||
use primitives::TxKind; | ||
|
||
/// EIP-2930: Optional access lists | ||
pub trait Eip2930Tx: CommonTxFields { | ||
type AccessList: AccessListInterface; | ||
type AccessList: AccessListTrait; | ||
|
||
/// The chain ID of the chain the transaction is intended for. | ||
fn chain_id(&self) -> u64; | ||
|
||
/// The gas price of the transaction. | ||
fn gas_price(&self) -> u128; | ||
|
||
/// The kind of transaction. | ||
fn kind(&self) -> TxKind; | ||
|
||
/// The access list of the transaction. | ||
fn access_list(&self) -> &Self::AccessList; | ||
} | ||
|
||
// TODO move to default context | ||
use specification::eip2930::AccessList; | ||
|
||
impl AccessListInterface for AccessList { | ||
fn iter(&self) -> impl Iterator<Item = (Address, impl Iterator<Item = B256>)> { | ||
self.0.iter().map(|item| { | ||
let slots = item.storage_keys.iter().copied(); | ||
(item.address, slots) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
use crate::CommonTxFields; | ||
use primitives::TxKind; | ||
|
||
/// Legacy transaction trait before introduction of EIP-2929 | ||
pub trait LegacyTx: CommonTxFields { | ||
/// Legacy transaction kind | ||
/// Transaction kind. | ||
fn kind(&self) -> TxKind; | ||
|
||
/// Chain Id is optional for legacy transactions | ||
/// As it was introduced in EIP-155. | ||
fn chain_id(&self) -> Option<u64>; | ||
|
||
/// Gas price for the transaction | ||
/// Gas price for the transaction. | ||
fn gas_price(&self) -> u128; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters