@@ -5,61 +5,30 @@ import (
55 "encoding/binary"
66 "encoding/hex"
77 "errors"
8+ "fmt"
89
910 "github.com/ethereum/go-ethereum/common"
1011 "github.com/ethereum/go-ethereum/crypto"
1112 "github.com/ethereum/go-ethereum/log"
1213)
1314
14- type stateManagerFunctionAndGasCost struct {
15- smFunction stateManagerFunction
16- smGasCost uint64
17- }
1815type stateManagerFunction func (* EVM , * Contract , []byte ) ([]byte , error )
1916
20- var funcs = map [string ]stateManagerFunctionAndGasCost {
21- "getStorage(address,bytes32)" : {
22- smFunction : getStorage ,
23- smGasCost : 20000 ,
24- },
25- "setStorage(address,bytes32,bytes32)" : {
26- smFunction : setStorage ,
27- smGasCost : 20000 ,
28- },
29- "getOvmContractNonce(address)" : {
30- smFunction : getOvmContractNonce ,
31- smGasCost : 20000 ,
32- },
33- "incrementOvmContractNonce(address)" : {
34- smFunction : incrementOvmContractNonce ,
35- smGasCost : 20000 ,
36- },
37- "getCodeContractBytecode(address)" : {
38- smFunction : getCodeContractBytecode ,
39- smGasCost : 20000 ,
40- },
41- "getCodeContractHash(address)" : {
42- smFunction : getCodeContractHash ,
43- smGasCost : 20000 ,
44- },
45- "getCodeContractAddressFromOvmAddress(address)" : {
46- smFunction : getCodeContractAddress ,
47- smGasCost : 20000 ,
48- },
49- "associateCodeContract(address,address)" : {
50- smFunction : associateCodeContract ,
51- smGasCost : 20000 ,
52- },
53- "registerCreatedContract(address)" : {
54- smFunction : registerCreatedContract ,
55- smGasCost : 20000 ,
56- },
17+ var funcs = map [string ]stateManagerFunction {
18+ "getStorage(address,bytes32)" : getStorage ,
19+ "setStorage(address,bytes32,bytes32)" : setStorage ,
20+ "getOvmContractNonce(address)" : getOvmContractNonce ,
21+ "incrementOvmContractNonce(address)" : incrementOvmContractNonce ,
22+ "getCodeContractBytecode(address)" : getCodeContractBytecode ,
23+ "getCodeContractHash(address)" : getCodeContractHash ,
24+ "getCodeContractAddressFromOvmAddress(address)" : getCodeContractAddress ,
25+ "associateCodeContract(address,address)" : associateCodeContract ,
26+ "registerCreatedContract(address)" : registerCreatedContract ,
5727}
58-
59- var methodIds map [[4 ]byte ]stateManagerFunctionAndGasCost
28+ var methodIds map [[4 ]byte ]stateManagerFunction
6029
6130func init () {
62- methodIds = make (map [[4 ]byte ]stateManagerFunctionAndGasCost , len (funcs ))
31+ methodIds = make (map [[4 ]byte ]stateManagerFunction , len (funcs ))
6332 for methodSignature , f := range funcs {
6433 methodIds [methodSignatureToMethodID (methodSignature )] = f
6534 }
@@ -71,23 +40,20 @@ func methodSignatureToMethodID(methodSignature string) [4]byte {
7140 return methodID
7241}
7342
74- func stateManagerRequiredGas (input []byte ) (gas uint64 ) {
75- var methodID [4 ]byte
76- copy (methodID [:], input [:4 ])
77- gas = methodIds [methodID ].smGasCost
78- return gas
79- }
80-
8143func callStateManager (input []byte , evm * EVM , contract * Contract ) (ret []byte , err error ) {
8244 var methodID [4 ]byte
45+ if len (input ) == 0 {
46+ return nil , nil
47+ }
8348 copy (methodID [:], input [:4 ])
84- ret , err = methodIds [methodID ].smFunction (evm , contract , input )
85- return ret , err
86- }
8749
88- /*
89- * StateManager functions
90- */
50+ if method , ok := methodIds [methodID ]; ok {
51+ return method (evm , contract , input )
52+ }
53+
54+ ret , err = methodIds [methodID ](evm , contract , input )
55+ return nil , fmt .Errorf ("state manager call not found: %s" , methodID )
56+ }
9157
9258func setStorage (evm * EVM , contract * Contract , input []byte ) (ret []byte , err error ) {
9359 address := common .BytesToAddress (input [4 :36 ])
0 commit comments