diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index 2d43b631c2..11bf693a02 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -55,6 +55,87 @@ const jsondata2 = ` { "type" : "function", "name" : "sliceMultiAddress", "constant" : false, "inputs" : [ { "name" : "a", "type" : "address[]" }, { "name" : "b", "type" : "address[]" } ] } ]` +const NettingChannelLibraryABI = ` +[ + { + "constant": false, + "inputs": [ + { + "name": "locked_encoded", + "type": "bytes" + }, + { + "name": "merkle_proof", + "type": "bytes" + }, + { + "name": "secret", + "type": "bytes32" + } + ], + "name": "withdraw", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "self", + "type": "NettingChannelLibrary.Data storage" + }, + { + "name": "amount", + "type": "uint256" + } + ], + "name": "deposit", + "outputs": [ + { + "name": "success", + "type": "bool" + }, + { + "name": "balance", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "contract_version", + "outputs": [ + { + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] +` + +func TestNewUserType(t *testing.T) { + _, err := NewType("NettingChannelLibrary.Data storage") + if err != nil { + t.Error(err) + } + abi, err := JSON(strings.NewReader(NettingChannelLibraryABI)) + if err != nil { + t.Error(err) + } + if _, err := abi.Pack("withdraw", []byte{1, 2, 3}, []byte{1, 2, 3}, [32]byte{1, 2, 3}); err != nil { + t.Error(err) + } +} func TestReader(t *testing.T) { Uint256, _ := NewType("uint256") exp := ABI{ diff --git a/accounts/abi/bind/bind.go b/accounts/abi/bind/bind.go index 8175e3cb9b..cf430477a4 100644 --- a/accounts/abi/bind/bind.go +++ b/accounts/abi/bind/bind.go @@ -26,7 +26,6 @@ import ( "regexp" "strings" "text/template" - "unicode" "github.com/ethereum/go-ethereum/accounts/abi" "golang.org/x/tools/imports" @@ -55,20 +54,22 @@ func Bind(types []string, abis []string, bytecodes []string, pkg string, lang La if err != nil { return "", err } - // Strip any whitespace from the JSON ABI - strippedABI := strings.Map(func(r rune) rune { - if unicode.IsSpace(r) { - return -1 - } - return r - }, abis[i]) - // Extract the call and transact methods, and sort them alphabetically var ( calls = make(map[string]*tmplMethod) transacts = make(map[string]*tmplMethod) ) for _, original := range evmABI.Methods { + skipMethodWithUserType := false + for _, input := range original.Inputs { + if input.Type.T == abi.UserTy { + skipMethodWithUserType = true + break + } + } + if skipMethodWithUserType { + continue //skip this method + } // Normalize the method for capital cases and non-anonymous inputs/outputs normalized := original normalized.Name = methodNormalizer[lang](original.Name) @@ -96,7 +97,7 @@ func Bind(types []string, abis []string, bytecodes []string, pkg string, lang La } contracts[types[i]] = &tmplContract{ Type: capitalise(types[i]), - InputABI: strings.Replace(strippedABI, "\"", "\\\"", -1), + InputABI: strings.Replace(abis[i], "\"", "\\\"", -1), InputBin: strings.TrimSpace(bytecodes[i]), Constructor: evmABI.Constructor, Calls: calls, diff --git a/accounts/abi/type.go b/accounts/abi/type.go index a1f13ffa29..74dfd30a03 100644 --- a/accounts/abi/type.go +++ b/accounts/abi/type.go @@ -38,6 +38,7 @@ const ( HashTy FixedPointTy FunctionTy + UserTy ) // Type is the reflection of the supported argument type @@ -159,7 +160,13 @@ func NewType(t string) (typ Type, err error) { typ.Size = 24 typ.Type = reflect.ArrayOf(24, reflect.TypeOf(byte(0))) default: - return Type{}, fmt.Errorf("unsupported arg type: %s", t) + //user defined types + typ.Kind = reflect.Struct + typ.T = UserTy + typ.Size = -1 + typ.Type = reflect.TypeOf(struct{}{}) + //default: + // return Type{}, fmt.Errorf("unsupported arg type: %s", t) } return