@@ -18,7 +18,7 @@ use crate::{
1818 evm:: { decode_revert_reason, CallLog , CallTrace , CallTracerConfig , CallType } ,
1919 primitives:: ExecReturnValue ,
2020 tracing:: Tracing ,
21- DispatchError , Weight ,
21+ Code , DispatchError , Weight ,
2222} ;
2323use alloc:: { format, string:: ToString , vec:: Vec } ;
2424use sp_core:: { H160 , H256 , U256 } ;
@@ -32,14 +32,22 @@ pub struct CallTracer<Gas, GasMapper> {
3232 traces : Vec < CallTrace < Gas > > ,
3333 /// Stack of indices to the current active traces.
3434 current_stack : Vec < usize > ,
35+ /// The code and salt used to instantiate the next contract.
36+ code_with_salt : Option < ( Code , bool ) > ,
3537 /// The tracer configuration.
3638 config : CallTracerConfig ,
3739}
3840
3941impl < Gas , GasMapper > CallTracer < Gas , GasMapper > {
4042 /// Create a new [`CallTracer`] instance.
4143 pub fn new ( config : CallTracerConfig , gas_mapper : GasMapper ) -> Self {
42- Self { gas_mapper, traces : Vec :: new ( ) , current_stack : Vec :: new ( ) , config }
44+ Self {
45+ gas_mapper,
46+ traces : Vec :: new ( ) ,
47+ code_with_salt : None ,
48+ current_stack : Vec :: new ( ) ,
49+ config,
50+ }
4351 }
4452
4553 /// Collect the traces and return them.
@@ -49,6 +57,10 @@ impl<Gas, GasMapper> CallTracer<Gas, GasMapper> {
4957}
5058
5159impl < Gas : Default , GasMapper : Fn ( Weight ) -> Gas > Tracing for CallTracer < Gas , GasMapper > {
60+ fn instantiate_code ( & mut self , code : & Code , salt : Option < & [ u8 ; 32 ] > ) {
61+ self . code_with_salt = Some ( ( code. clone ( ) , salt. is_some ( ) ) ) ;
62+ }
63+
5264 fn enter_child_span (
5365 & mut self ,
5466 from : H160 ,
@@ -60,20 +72,36 @@ impl<Gas: Default, GasMapper: Fn(Weight) -> Gas> Tracing for CallTracer<Gas, Gas
6072 gas_left : Weight ,
6173 ) {
6274 if self . traces . is_empty ( ) || !self . config . only_top_call {
63- let call_type = if is_read_only {
64- CallType :: StaticCall
65- } else if is_delegate_call {
66- CallType :: DelegateCall
67- } else {
68- CallType :: Call
75+ let ( call_type, input) = match self . code_with_salt . take ( ) {
76+ Some ( ( Code :: Upload ( v) , salt) ) => (
77+ if salt { CallType :: Create2 } else { CallType :: Create } ,
78+ v. into_iter ( ) . chain ( input. to_vec ( ) . into_iter ( ) ) . collect :: < Vec < _ > > ( ) ,
79+ ) ,
80+ Some ( ( Code :: Existing ( v) , salt) ) => (
81+ if salt { CallType :: Create2 } else { CallType :: Create } ,
82+ v. to_fixed_bytes ( )
83+ . into_iter ( )
84+ . chain ( input. to_vec ( ) . into_iter ( ) )
85+ . collect :: < Vec < _ > > ( ) ,
86+ ) ,
87+ None => {
88+ let call_type = if is_read_only {
89+ CallType :: StaticCall
90+ } else if is_delegate_call {
91+ CallType :: DelegateCall
92+ } else {
93+ CallType :: Call
94+ } ;
95+ ( call_type, input. to_vec ( ) )
96+ } ,
6997 } ;
7098
7199 self . traces . push ( CallTrace {
72100 from,
73101 to,
74102 value : if is_read_only { None } else { Some ( value) } ,
75103 call_type,
76- input : input. to_vec ( ) . into ( ) ,
104+ input : input. into ( ) ,
77105 gas : ( self . gas_mapper ) ( gas_left) ,
78106 ..Default :: default ( )
79107 } ) ;
@@ -102,6 +130,8 @@ impl<Gas: Default, GasMapper: Fn(Weight) -> Gas> Tracing for CallTracer<Gas, Gas
102130 }
103131
104132 fn exit_child_span ( & mut self , output : & ExecReturnValue , gas_used : Weight ) {
133+ self . code_with_salt = None ;
134+
105135 // Set the output of the current trace
106136 let current_index = self . current_stack . pop ( ) . unwrap ( ) ;
107137
@@ -126,6 +156,8 @@ impl<Gas: Default, GasMapper: Fn(Weight) -> Gas> Tracing for CallTracer<Gas, Gas
126156 }
127157 }
128158 fn exit_child_span_with_error ( & mut self , error : DispatchError , gas_used : Weight ) {
159+ self . code_with_salt = None ;
160+
129161 // Set the output of the current trace
130162 let current_index = self . current_stack . pop ( ) . unwrap ( ) ;
131163
0 commit comments