Skip to content

Commit

Permalink
pallet-ethereum: add number to hash mapping for Ethereum headers (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas authored Jun 8, 2020
1 parent 84940c0 commit af245f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ decl_storage! {
// storage items are isolated from other pallets.
// ---------------------------------vvvvvvv
trait Store for Module<T: Trait> as Example {
BlocksAndReceipts: map hasher(blake2_128_concat) T::BlockNumber => Option<(ethereum::Block, Vec<ethereum::Receipt>)>;
BlocksAndReceipts: map hasher(blake2_128_concat) H256 => Option<(ethereum::Block, Vec<ethereum::Receipt>)>;
BlockNumbers: map hasher(blake2_128_concat) T::BlockNumber => H256;
PendingTransactionsAndReceipts: Vec<(ethereum::Transaction, ethereum::Receipt)>;
TransactionStatuses: map hasher(blake2_128_concat) H256 => Option<TransactionStatus>;
}
Expand Down Expand Up @@ -182,14 +183,16 @@ decl_module! {
mix_hash: H256::default(),
nonce: H64::default(),
};
let hash = H256::from_slice(Keccak256::digest(&rlp::encode(&header)).as_slice());

let block = ethereum::Block {
header,
transactions,
ommers,
};

BlocksAndReceipts::<T>::insert(n, (block, receipts));
BlocksAndReceipts::insert(hash, (block, receipts));
BlockNumbers::<T>::insert(n, hash);
}

// A runtime code run after every block and have access to extended set of APIs.
Expand Down

0 comments on commit af245f2

Please sign in to comment.