1use serde::{Deserialize, Serialize};
2use yevm_misc::buf::Buf;
3
4use crate::{Acc, Head, Int, chain::Fetched, trace::Event};
5
6#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
7pub struct Account {
8 pub value: Int,
9 pub nonce: Int,
10 pub code: (Buf, Int),
11}
12
13pub trait State {
14 fn get(&mut self, acc: &Acc, key: &Int) -> Option<(Int, Int)>;
15 fn put(&mut self, acc: &Acc, key: &Int, val: Int) -> Option<Int>;
16 fn init(&mut self, acc: &Acc, key: &Int, val: Int);
17
18 fn tget(&mut self, acc: &Acc, key: &Int) -> Option<Int>;
19 fn tput(&mut self, acc: Acc, key: Int, val: Int) -> Option<Int>;
20
21 fn inc_nonce(&mut self, acc: &Acc, nonce: Int) -> Int;
22 fn set_value(&mut self, acc: &Acc, value: Int) -> Int;
23 fn set_code(&mut self, acc: &Acc, code: Buf, hash: Int) -> Int;
24 fn set_auth(&mut self, src: &Acc, dst: &Acc);
25
26 fn merge(&mut self, acc: &Acc, chain: Account);
27
28 fn balance(&mut self, acc: &Acc) -> Option<Int>;
29 fn nonce(&mut self, acc: &Acc) -> Option<Int>;
30 fn code(&mut self, acc: &Acc) -> Option<(Buf, Int)>;
31 fn acc(&mut self, acc: &Acc) -> Option<Account>;
32
33 fn is_cold_acc(&self, acc: &Acc) -> bool;
34 fn is_cold_key(&self, acc: &Acc, key: &Int) -> bool;
35
36 fn warm_acc(&mut self, acc: &Acc) -> bool;
37 fn warm_key(&mut self, acc: &Acc, key: &Int) -> bool;
38
39 fn create(&mut self, acc: Acc, info: Account);
40 fn destroy(&mut self, acc: &Acc);
41
42 fn hash(&mut self, number: u64, hash: Int);
43 fn log(&mut self, data: Buf, topics: Vec<Int>);
44
45 fn head(&self, number: u64) -> Option<Head>;
46 fn auth(&self, acc: &Acc) -> Option<Acc>;
47 fn created(&self) -> Vec<Acc>;
48 fn destroyed(&self) -> Vec<Acc>;
49 fn apply(&mut self);
50
51 fn get_depth(&mut self) -> usize {
52 0
53 }
54 fn set_depth(&mut self, _depth: usize) {}
55 fn emit(&mut self, event: Event) -> usize;
56
57 fn save_fetched(&mut self, _fetched: Fetched) {}
58 fn next_fetched(&mut self) -> Option<Fetched> {
59 None
60 }
61 fn prefetched(&mut self, _: Vec<Fetched>) {}
62 fn is_offline(&self) -> bool {
63 false
64 }
65
66 fn reset(&mut self) {}
67
68 fn checkpoint(&mut self) -> usize {
70 0
71 }
72 fn revert_to(&mut self, _checkpoint: usize) {}
74
75 fn set_chain_id(&mut self, _id: u64) {}
76 fn get_chain_id(&self) -> u64 {
77 0
78 }
79
80 fn is_tracing(&self) -> bool {
81 true
82 }
83}