kona_executor/db/
account.rs1use alloy_primitives::{B256, U256};
4use alloy_rlp::{RlpDecodable, RlpEncodable};
5use revm::primitives::{Account, AccountInfo};
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)]
9pub struct TrieAccount {
10 pub nonce: u64,
12 pub balance: U256,
14 pub storage_root: B256,
16 pub code_hash: B256,
18}
19
20impl From<(Account, B256)> for TrieAccount {
21 fn from((account, storage_root): (Account, B256)) -> Self {
22 Self {
23 nonce: account.info.nonce,
24 balance: account.info.balance,
25 storage_root,
26 code_hash: account.info.code_hash,
27 }
28 }
29}
30
31impl From<(AccountInfo, B256)> for TrieAccount {
32 fn from((account, storage_root): (AccountInfo, B256)) -> Self {
33 Self {
34 nonce: account.nonce,
35 balance: account.balance,
36 storage_root,
37 code_hash: account.code_hash,
38 }
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45 use alloy_primitives::uint;
46
47 #[test]
48 fn test_trie_account_from_account() {
49 let account = Account {
50 info: AccountInfo {
51 nonce: 1,
52 balance: uint!(2_U256),
53 code_hash: B256::default(),
54 code: Default::default(),
55 },
56 status: Default::default(),
57 storage: Default::default(),
58 };
59 let storage_root = B256::default();
60 let trie_account = TrieAccount::from((account, storage_root));
61 assert_eq!(trie_account.nonce, 1);
62 assert_eq!(trie_account.balance, uint!(2_U256));
63 assert_eq!(trie_account.storage_root, B256::default());
64 assert_eq!(trie_account.code_hash, B256::default());
65 }
66
67 #[test]
68 fn test_trie_account_from_account_info() {
69 let account_info = AccountInfo {
70 nonce: 1,
71 balance: uint!(2_U256),
72 code_hash: B256::default(),
73 code: Default::default(),
74 };
75 let storage_root = B256::default();
76 let trie_account = TrieAccount::from((account_info, storage_root));
77 assert_eq!(trie_account.nonce, 1);
78 assert_eq!(trie_account.balance, uint!(2_U256));
79 assert_eq!(trie_account.storage_root, B256::default());
80 assert_eq!(trie_account.code_hash, B256::default());
81 }
82}