11//! EVM runtime events definitions.
22
3- // TODO: fix clippy.
4- #![ allow( missing_docs) ]
5-
63extern crate alloc;
74
85use codec:: { Decode , Encode } ;
@@ -11,11 +8,14 @@ use evm::ExitReason;
118use evm:: Opcode ;
129use sp_core:: { sp_std:: vec:: Vec , H160 , H256 , U256 } ;
1310
14- use crate :: Context ;
11+ use crate :: { Context , StepEventFilter } ;
1512
13+ /// EVM stack.
1614#[ derive( Clone , Debug , Encode , Decode , PartialEq , Eq ) ]
1715pub struct Stack {
16+ /// Data.
1817 pub data : Vec < H256 > ,
18+ /// Limit.
1919 pub limit : u64 ,
2020}
2121
@@ -28,10 +28,14 @@ impl From<&evm::Stack> for Stack {
2828 }
2929}
3030
31+ /// EVM memory.
3132#[ derive( Clone , Debug , Encode , Decode , PartialEq , Eq ) ]
3233pub struct Memory {
34+ /// Data.
3335 pub data : Vec < u8 > ,
36+ /// Effective length.
3437 pub effective_len : U256 ,
38+ /// Limit.
3539 pub limit : u64 ,
3640}
3741
@@ -45,6 +49,7 @@ impl From<&evm::Memory> for Memory {
4549 }
4650}
4751
52+ /// Capture represents the result of execution.
4853#[ derive( Clone , Copy , Debug , Eq , PartialEq , Encode , Decode ) ]
4954pub enum Capture < E , T > {
5055 /// The machine has exited. It cannot be executed again.
@@ -54,41 +59,57 @@ pub enum Capture<E, T> {
5459 Trap ( T ) ,
5560}
5661
57- pub type Trap = Vec < u8 > ; // Should hold the marshalled Opcode.
62+ /// A type alias representing trap data. Should hold the marshalled `Opcode`.
63+ pub type Trap = Vec < u8 > ;
5864
65+ /// EVM runtime event.
5966#[ derive( Debug , Clone , Encode , Decode , PartialEq , Eq ) ]
6067pub enum RuntimeEvent {
68+ /// Step.
6169 Step {
70+ /// Context.
6271 context : Context ,
63- // This needs to be marshalled in the runtime no matter what .
72+ /// Opcode .
6473 opcode : Vec < u8 > ,
65- // We can use ExitReason with `with-codec` feature,
74+ /// Position.
6675 position : Result < u64 , ExitReason > ,
76+ /// Stack.
6777 stack : Option < Stack > ,
78+ /// Memory.
6879 memory : Option < Memory > ,
6980 } ,
81+ /// Step result.
7082 StepResult {
83+ /// Result.
7184 result : Result < ( ) , Capture < ExitReason , Trap > > ,
85+ /// Return value.
7286 return_value : Vec < u8 > ,
7387 } ,
88+ /// Storage load.
7489 SLoad {
90+ /// Address.
7591 address : H160 ,
92+ /// Index.
7693 index : H256 ,
94+ /// Value.
7795 value : H256 ,
7896 } ,
97+ /// Storage store.
7998 SStore {
99+ /// Address.
80100 address : H160 ,
101+ /// Index.
81102 index : H256 ,
103+ /// Value.
82104 value : H256 ,
83105 } ,
84106}
85107
86108#[ cfg( feature = "evm-tracing" ) ]
87109impl RuntimeEvent {
88- pub fn from_evm_event (
89- event : evm_runtime:: tracing:: Event < ' _ > ,
90- filter : crate :: StepEventFilter ,
91- ) -> Self {
110+ /// Obtain `RuntimeEvent` from [`evm_runtime::tracing::Event`] based on provided
111+ /// step event filter.
112+ pub fn from_evm_event ( event : evm_runtime:: tracing:: Event < ' _ > , filter : StepEventFilter ) -> Self {
92113 match event {
93114 evm_runtime:: tracing:: Event :: Step {
94115 context,
@@ -149,7 +170,7 @@ impl RuntimeEvent {
149170 }
150171}
151172
152- /// Converts an Opcode into its name, stored in a `Vec<u8>`.
173+ /// Converts an ` Opcode` into its name, stored in a `Vec<u8>`.
153174#[ cfg( feature = "evm-tracing" ) ]
154175pub fn opcodes_string ( opcode : Opcode ) -> Vec < u8 > {
155176 let tmp;
0 commit comments