@@ -31,13 +31,24 @@ import (
3131)
3232
3333var (
34- contextAddressType , _ = abi .NewType ("address" , "" , nil )
35- contextUint256Type , _ = abi .NewType ("uint256" , "" , nil )
36- contextStringArrayType , _ = abi .NewType ("string[]" , "" , nil )
37- contextStringArray2DType , _ = abi .NewType ("string[][]" , "" , nil )
38- contextBytesType , _ = abi .NewType ("bytes" , "" , nil )
34+ createDataSetArgs = mustABIArguments ("address" , "uint256" , "string[]" , "string[]" , "bytes" )
35+ addPiecesArgs = mustABIArguments ("uint256" , "string[][]" , "string[][]" , "bytes" )
36+ createAndAddArgs = mustABIArguments ("bytes" , "bytes" )
37+ bytesArgs = mustABIArguments ("bytes" )
3938)
4039
40+ func mustABIArguments (typeNames ... string ) abi.Arguments {
41+ args := make (abi.Arguments , len (typeNames ))
42+ for i , typeName := range typeNames {
43+ t , err := abi .NewType (typeName , "" , nil )
44+ if err != nil {
45+ panic ("storage: failed to parse " + typeName + " ABI type: " + err .Error ())
46+ }
47+ args [i ] = abi.Argument {Type : t }
48+ }
49+ return args
50+ }
51+
4152var randReader io.Reader = rand .Reader
4253
4354const (
@@ -829,14 +840,7 @@ func encodeCreateDataSetExtraData(payer common.Address, clientDataSetID *big.Int
829840 keys = append (keys , m .Key )
830841 values = append (values , m .Value )
831842 }
832- args := abi.Arguments {
833- {Type : contextAddressType },
834- {Type : contextUint256Type },
835- {Type : contextStringArrayType },
836- {Type : contextStringArrayType },
837- {Type : contextBytesType },
838- }
839- out , err := args .Pack (payer , clientDataSetID , keys , values , signature )
843+ out , err := createDataSetArgs .Pack (payer , clientDataSetID , keys , values , signature )
840844 if err != nil {
841845 return nil , fmt .Errorf ("storage: encode create dataset extraData: %w" , err )
842846 }
@@ -854,22 +858,15 @@ func encodeAddPiecesExtraData(nonce *big.Int, metadata [][]ityped.MetadataEntry,
854858 values [i ][j ] = m .Value
855859 }
856860 }
857- args := abi.Arguments {
858- {Type : contextUint256Type },
859- {Type : contextStringArray2DType },
860- {Type : contextStringArray2DType },
861- {Type : contextBytesType },
862- }
863- out , err := args .Pack (nonce , keys , values , signature )
861+ out , err := addPiecesArgs .Pack (nonce , keys , values , signature )
864862 if err != nil {
865863 return nil , fmt .Errorf ("storage: encode add pieces extraData: %w" , err )
866864 }
867865 return out , nil
868866}
869867
870868func encodeCreateAndAddExtraData (createPayload , addPayload []byte ) ([]byte , error ) {
871- args := abi.Arguments {{Type : contextBytesType }, {Type : contextBytesType }}
872- out , err := args .Pack (createPayload , addPayload )
869+ out , err := createAndAddArgs .Pack (createPayload , addPayload )
873870 if err != nil {
874871 return nil , fmt .Errorf ("storage: encode create+add extraData: %w" , err )
875872 }
0 commit comments