@@ -739,6 +739,42 @@ type CallArgs struct {
739
739
Data * hexutil.Bytes `json:"data"`
740
740
}
741
741
742
+ // ToMessage converts CallArgs to the Message type used by the core evm
743
+ func (args * CallArgs ) ToMessage (globalGasCap * big.Int ) types.Message {
744
+ // Set sender address or use zero address if none specified.
745
+ var addr common.Address
746
+ if args .From != nil {
747
+ addr = * args .From
748
+ }
749
+
750
+ // Set default gas & gas price if none were set
751
+ gas := uint64 (math .MaxUint64 / 2 )
752
+ if args .Gas != nil {
753
+ gas = uint64 (* args .Gas )
754
+ }
755
+ if globalGasCap != nil && globalGasCap .Uint64 () < gas {
756
+ log .Warn ("Caller gas above allowance, capping" , "requested" , gas , "cap" , globalGasCap )
757
+ gas = globalGasCap .Uint64 ()
758
+ }
759
+ gasPrice := new (big.Int )
760
+ if args .GasPrice != nil {
761
+ gasPrice = args .GasPrice .ToInt ()
762
+ }
763
+
764
+ value := new (big.Int )
765
+ if args .Value != nil {
766
+ value = args .Value .ToInt ()
767
+ }
768
+
769
+ var data []byte
770
+ if args .Data != nil {
771
+ data = []byte (* args .Data )
772
+ }
773
+
774
+ msg := types .NewMessage (addr , args .To , 0 , value , gas , gasPrice , data , false )
775
+ return msg
776
+ }
777
+
742
778
// account indicates the overriding fields of account during the execution of
743
779
// a message call.
744
780
// Note, state and stateDiff can't be specified at the same time. If state is
@@ -761,12 +797,6 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
761
797
return nil , 0 , false , err
762
798
}
763
799
764
- // Set sender address or use zero address if none specified.
765
- var addr common.Address
766
- if args .From != nil {
767
- addr = * args .From
768
- }
769
-
770
800
// Override the fields of specified contracts before execution.
771
801
for addr , account := range overrides {
772
802
// Override account nonce.
@@ -795,32 +825,6 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
795
825
}
796
826
}
797
827
}
798
- // Set default gas & gas price if none were set
799
- gas := uint64 (math .MaxUint64 / 2 )
800
- if args .Gas != nil {
801
- gas = uint64 (* args .Gas )
802
- }
803
- if globalGasCap != nil && globalGasCap .Uint64 () < gas {
804
- log .Warn ("Caller gas above allowance, capping" , "requested" , gas , "cap" , globalGasCap )
805
- gas = globalGasCap .Uint64 ()
806
- }
807
- gasPrice := new (big.Int )
808
- if args .GasPrice != nil {
809
- gasPrice = args .GasPrice .ToInt ()
810
- }
811
-
812
- value := new (big.Int )
813
- if args .Value != nil {
814
- value = args .Value .ToInt ()
815
- }
816
-
817
- var data []byte
818
- if args .Data != nil {
819
- data = []byte (* args .Data )
820
- }
821
-
822
- // Create new call message
823
- msg := types .NewMessage (addr , args .To , 0 , value , gas , gasPrice , data , false )
824
828
825
829
// Setup context so it may be cancelled the call has completed
826
830
// or, in case of unmetered gas, setup a context with a timeout.
@@ -835,6 +839,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
835
839
defer cancel ()
836
840
837
841
// Get a new instance of the EVM.
842
+ msg := args .ToMessage (globalGasCap )
838
843
evm , vmError , err := b .GetEVM (ctx , msg , state , header )
839
844
if err != nil {
840
845
return nil , 0 , false , err
0 commit comments