diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 8045ece4a3..205dc300b0 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -20,9 +20,6 @@ import ( "encoding/json" "fmt" "io" - "reflect" - - "github.com/ethereum/go-ethereum/common" ) // The ABI holds information about a contract's context and available @@ -75,22 +72,11 @@ func (abi ABI) Pack(name string, args ...interface{}) ([]byte, error) { return append(method.Id(), arguments...), nil } -// these variable are used to determine certain types during type assertion for -// assignment. -var ( - r_interSlice = reflect.TypeOf([]interface{}{}) - r_hash = reflect.TypeOf(common.Hash{}) - r_bytes = reflect.TypeOf([]byte{}) - r_byte = reflect.TypeOf(byte(0)) -) - // Unpack output in v according to the abi specification func (abi ABI) Unpack(v interface{}, name string, output []byte) (err error) { - if err = bytesAreProper(output); err != nil { return err } - // since there can't be naming collisions with contracts and events, // we need to decide whether we're calling a method or an event var unpack unpacker diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index 2f687969bc..79c4d4a163 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -29,25 +29,6 @@ import ( "github.com/ethereum/go-ethereum/crypto" ) -// formatSilceOutput add padding to the value and adds a size -func formatSliceOutput(v ...[]byte) []byte { - off := common.LeftPadBytes(big.NewInt(int64(len(v))).Bytes(), 32) - output := append(off, make([]byte, 0, len(v)*32)...) - - for _, value := range v { - output = append(output, common.LeftPadBytes(value, 32)...) - } - return output -} - -// quick helper padding -func pad(input []byte, size int, left bool) []byte { - if left { - return common.LeftPadBytes(input, size) - } - return common.RightPadBytes(input, size) -} - const jsondata = ` [ { "type" : "function", "name" : "balance", "constant" : true }, diff --git a/accounts/abi/error.go b/accounts/abi/error.go index 2333b8bfa0..9d8674ad08 100644 --- a/accounts/abi/error.go +++ b/accounts/abi/error.go @@ -78,11 +78,6 @@ func typeCheck(t Type, value reflect.Value) error { } -// varErr returns a formatted error. -func varErr(expected, got reflect.Kind) error { - return typeErr(expected, got) -} - // typeErr returns a formatted type casting error. func typeErr(expected, got interface{}) error { return fmt.Errorf("abi: cannot use %v as type %v as argument", got, expected) diff --git a/accounts/abi/numbers.go b/accounts/abi/numbers.go index 91f2c5d2a4..9ad99f90d2 100644 --- a/accounts/abi/numbers.go +++ b/accounts/abi/numbers.go @@ -27,9 +27,6 @@ import ( var ( big_t = reflect.TypeOf(&big.Int{}) derefbig_t = reflect.TypeOf(big.Int{}) - byte_t = reflect.TypeOf(byte(0)) - byte_ts = reflect.TypeOf([]byte(nil)) - uint_t = reflect.TypeOf(uint(0)) uint8_t = reflect.TypeOf(uint8(0)) uint16_t = reflect.TypeOf(uint16(0)) uint32_t = reflect.TypeOf(uint32(0)) @@ -39,22 +36,12 @@ var ( int16_t = reflect.TypeOf(int16(0)) int32_t = reflect.TypeOf(int32(0)) int64_t = reflect.TypeOf(int64(0)) - hash_t = reflect.TypeOf(common.Hash{}) address_t = reflect.TypeOf(common.Address{}) - - uint_ts = reflect.TypeOf([]uint(nil)) - uint8_ts = reflect.TypeOf([]uint8(nil)) - uint16_ts = reflect.TypeOf([]uint16(nil)) - uint32_ts = reflect.TypeOf([]uint32(nil)) - uint64_ts = reflect.TypeOf([]uint64(nil)) - ubig_ts = reflect.TypeOf([]*big.Int(nil)) - - int_ts = reflect.TypeOf([]int(nil)) - int8_ts = reflect.TypeOf([]int8(nil)) - int16_ts = reflect.TypeOf([]int16(nil)) - int32_ts = reflect.TypeOf([]int32(nil)) - int64_ts = reflect.TypeOf([]int64(nil)) - big_ts = reflect.TypeOf([]*big.Int(nil)) + int_ts = reflect.TypeOf([]int(nil)) + int8_ts = reflect.TypeOf([]int8(nil)) + int16_ts = reflect.TypeOf([]int16(nil)) + int32_ts = reflect.TypeOf([]int32(nil)) + int64_ts = reflect.TypeOf([]int64(nil)) ) // U256 converts a big Int into a 256bit EVM number. diff --git a/accounts/abi/type_test.go b/accounts/abi/type_test.go index 7e85a3c513..e55af12939 100644 --- a/accounts/abi/type_test.go +++ b/accounts/abi/type_test.go @@ -21,6 +21,7 @@ import ( "reflect" "testing" + "github.com/davecgh/go-spew/spew" "github.com/ethereum/go-ethereum/common" ) @@ -86,7 +87,6 @@ func TestTypeRegexp(t *testing.T) { {"address", Type{Kind: reflect.Array, Type: address_t, Size: 20, T: AddressTy, stringKind: "address"}}, {"address[]", Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]common.Address{}), Elem: &Type{Kind: reflect.Array, Type: address_t, Size: 20, T: AddressTy, stringKind: "address"}, stringKind: "address[]"}}, {"address[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]common.Address{}), Elem: &Type{Kind: reflect.Array, Type: address_t, Size: 20, T: AddressTy, stringKind: "address"}, stringKind: "address[2]"}}, - // TODO when fixed types are implemented properly // {"fixed", Type{}}, // {"fixed128x128", Type{}}, @@ -95,13 +95,14 @@ func TestTypeRegexp(t *testing.T) { // {"fixed128x128[]", Type{}}, // {"fixed128x128[2]", Type{}}, } - for i, tt := range tests { + + for _, tt := range tests { typ, err := NewType(tt.blob) if err != nil { - t.Errorf("type %d: failed to parse type string: %v", i, err) + t.Errorf("type %q: failed to parse type string: %v", tt.blob, err) } if !reflect.DeepEqual(typ, tt.kind) { - t.Errorf("type %d: parsed type mismatch:\n have %+v\n want %+v.\n more details:\n have %v\n want %v\n have %v\n want %v\n ", i, typeWithoutStringer(typ), typeWithoutStringer(tt.kind), typeWithoutStringer(*typ.Elem), typeWithoutStringer(*tt.kind.Elem)) + t.Errorf("type %q: parsed type mismatch:\nGOT %s\nWANT %s ", tt.blob, spew.Sdump(typeWithoutStringer(typ)), spew.Sdump(typeWithoutStringer(tt.kind))) } } }