@@ -25,6 +25,7 @@ public abstract class ChainNodeBase : IChainNode
2525 protected readonly INodeDataService _nodeDataService ;
2626 protected readonly TransactionProcessor _transactionProcessor ;
2727 protected readonly ITransactionVerificationAndRecovery _txVerifier ;
28+ protected readonly TransactionExecutor _executor ;
2829
2930 protected ChainNodeBase (
3031 IBlockStore blockStore ,
@@ -36,7 +37,8 @@ protected ChainNodeBase(
3637 TransactionProcessor transactionProcessor ,
3738 ITransactionVerificationAndRecovery txVerifier ,
3839 INodeDataService nodeDataService = null ,
39- ITrieNodeStore trieNodeStore = null )
40+ ITrieNodeStore trieNodeStore = null ,
41+ HardforkConfig hardforkConfig = null )
4042 {
4143 _blockStore = blockStore ?? throw new ArgumentNullException ( nameof ( blockStore ) ) ;
4244 _transactionStore = transactionStore ?? throw new ArgumentNullException ( nameof ( transactionStore ) ) ;
@@ -48,6 +50,7 @@ protected ChainNodeBase(
4850 _txVerifier = txVerifier ?? throw new ArgumentNullException ( nameof ( txVerifier ) ) ;
4951 _nodeDataService = nodeDataService ?? new StateStoreNodeDataService ( _stateStore , _blockStore ) ;
5052 _trieNodeStore = trieNodeStore ;
53+ _executor = new TransactionExecutor ( hardforkConfig ?? HardforkConfig . Default ) ;
5154 }
5255
5356 public abstract ChainConfig Config { get ; }
@@ -129,49 +132,44 @@ public virtual async Task<CallResult> CallAsync(string to, byte[] data, string f
129132 var blockContext = await GetBlockContextForCallAsync ( ) ;
130133 var executionStateService = new ExecutionStateService ( _nodeDataService ) ;
131134
132- var code = await _nodeDataService . GetCodeAsync ( to ) ;
133- if ( code == null || code . Length == 0 )
134- {
135- return new CallResult { Success = true , ReturnData = Array . Empty < byte > ( ) , GasUsed = 0 } ;
136- }
135+ var isContractCreation = string . IsNullOrEmpty ( to ) ;
137136
138137 var callerBalance = await _nodeDataService . GetBalanceAsync ( from ) ;
139138 executionStateService . SetInitialChainBalance ( from , callerBalance ) ;
140139
141- var callInput = new CallInput
140+ var ctx = new TransactionExecutionContext
142141 {
143- From = from ,
144- To = to ,
145- Value = new Nethereum . Hex . HexTypes . HexBigInteger ( callValue ) ,
146- Data = data ? . ToHex ( true ) ?? "0x" ,
147- Gas = new Nethereum . Hex . HexTypes . HexBigInteger ( callGasLimit ) ,
148- GasPrice = new Nethereum . Hex . HexTypes . HexBigInteger ( 0 ) ,
149- ChainId = new Nethereum . Hex . HexTypes . HexBigInteger ( Config . ChainId )
142+ Mode = ExecutionMode . Call ,
143+ Sender = from ,
144+ To = isContractCreation ? null : to ,
145+ Data = data ,
146+ Value = callValue ,
147+ GasLimit = callGasLimit ,
148+ GasPrice = 0 ,
149+ MaxFeePerGas = 0 ,
150+ MaxPriorityFeePerGas = 0 ,
151+ Nonce = 0 ,
152+ IsEip1559 = false ,
153+ IsContractCreation = isContractCreation ,
154+ BlockNumber = ( long ) blockContext . BlockNumber ,
155+ Timestamp = blockContext . Timestamp ,
156+ Coinbase = blockContext . Coinbase ,
157+ BaseFee = blockContext . BaseFee ,
158+ Difficulty = blockContext . Difficulty ,
159+ BlockGasLimit = blockContext . GasLimit ,
160+ ChainId = blockContext . ChainId ,
161+ ExecutionState = executionStateService ,
162+ TraceEnabled = false
150163 } ;
151164
152- var programContext = new ProgramContext (
153- callInput ,
154- executionStateService ,
155- from ,
156- to ,
157- ( long ) blockContext . BlockNumber ,
158- blockContext . Timestamp ,
159- blockContext . Coinbase ,
160- ( long ) blockContext . BaseFee ) ;
161-
162- programContext . GasLimit = blockContext . GasLimit ;
163- programContext . Difficulty = blockContext . Difficulty ;
164-
165- var program = new Program ( code , programContext ) ;
166- var simulator = new EVMSimulator ( ) ;
167- await simulator . ExecuteWithCallStackAsync ( program , traceEnabled : false ) ;
165+ var result = await _executor . ExecuteAsync ( ctx ) ;
168166
169167 return new CallResult
170168 {
171- Success = ! program . ProgramResult . IsRevert ,
172- ReturnData = program . ProgramResult . Result ?? Array . Empty < byte > ( ) ,
173- RevertReason = program . ProgramResult . GetRevertMessage ( ) ,
174- GasUsed = program . TotalGasUsed
169+ Success = result . Success ,
170+ ReturnData = result . ReturnData ?? Array . Empty < byte > ( ) ,
171+ RevertReason = result . RevertReason ?? result . Error ,
172+ GasUsed = result . GasUsed
175173 } ;
176174 }
177175
0 commit comments