mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
accounts/abi: fix vet, megacheck
This commit is contained in:
parent
c156f68092
commit
f5e3630a79
5 changed files with 10 additions and 60 deletions
|
|
@ -20,9 +20,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// The ABI holds information about a contract's context and available
|
// 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
|
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
|
// Unpack output in v according to the abi specification
|
||||||
func (abi ABI) Unpack(v interface{}, name string, output []byte) (err error) {
|
func (abi ABI) Unpack(v interface{}, name string, output []byte) (err error) {
|
||||||
|
|
||||||
if err = bytesAreProper(output); err != nil {
|
if err = bytesAreProper(output); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// since there can't be naming collisions with contracts and events,
|
// since there can't be naming collisions with contracts and events,
|
||||||
// we need to decide whether we're calling a method or an event
|
// we need to decide whether we're calling a method or an event
|
||||||
var unpack unpacker
|
var unpack unpacker
|
||||||
|
|
|
||||||
|
|
@ -29,25 +29,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"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 = `
|
const jsondata = `
|
||||||
[
|
[
|
||||||
{ "type" : "function", "name" : "balance", "constant" : true },
|
{ "type" : "function", "name" : "balance", "constant" : true },
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// typeErr returns a formatted type casting error.
|
||||||
func typeErr(expected, got interface{}) error {
|
func typeErr(expected, got interface{}) error {
|
||||||
return fmt.Errorf("abi: cannot use %v as type %v as argument", got, expected)
|
return fmt.Errorf("abi: cannot use %v as type %v as argument", got, expected)
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,6 @@ import (
|
||||||
var (
|
var (
|
||||||
big_t = reflect.TypeOf(&big.Int{})
|
big_t = reflect.TypeOf(&big.Int{})
|
||||||
derefbig_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))
|
uint8_t = reflect.TypeOf(uint8(0))
|
||||||
uint16_t = reflect.TypeOf(uint16(0))
|
uint16_t = reflect.TypeOf(uint16(0))
|
||||||
uint32_t = reflect.TypeOf(uint32(0))
|
uint32_t = reflect.TypeOf(uint32(0))
|
||||||
|
|
@ -39,22 +36,12 @@ var (
|
||||||
int16_t = reflect.TypeOf(int16(0))
|
int16_t = reflect.TypeOf(int16(0))
|
||||||
int32_t = reflect.TypeOf(int32(0))
|
int32_t = reflect.TypeOf(int32(0))
|
||||||
int64_t = reflect.TypeOf(int64(0))
|
int64_t = reflect.TypeOf(int64(0))
|
||||||
hash_t = reflect.TypeOf(common.Hash{})
|
|
||||||
address_t = reflect.TypeOf(common.Address{})
|
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))
|
int_ts = reflect.TypeOf([]int(nil))
|
||||||
int8_ts = reflect.TypeOf([]int8(nil))
|
int8_ts = reflect.TypeOf([]int8(nil))
|
||||||
int16_ts = reflect.TypeOf([]int16(nil))
|
int16_ts = reflect.TypeOf([]int16(nil))
|
||||||
int32_ts = reflect.TypeOf([]int32(nil))
|
int32_ts = reflect.TypeOf([]int32(nil))
|
||||||
int64_ts = reflect.TypeOf([]int64(nil))
|
int64_ts = reflect.TypeOf([]int64(nil))
|
||||||
big_ts = reflect.TypeOf([]*big.Int(nil))
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// U256 converts a big Int into a 256bit EVM number.
|
// U256 converts a big Int into a 256bit EVM number.
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"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{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[]", 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]"}},
|
{"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
|
// TODO when fixed types are implemented properly
|
||||||
// {"fixed", Type{}},
|
// {"fixed", Type{}},
|
||||||
// {"fixed128x128", Type{}},
|
// {"fixed128x128", Type{}},
|
||||||
|
|
@ -95,13 +95,14 @@ func TestTypeRegexp(t *testing.T) {
|
||||||
// {"fixed128x128[]", Type{}},
|
// {"fixed128x128[]", Type{}},
|
||||||
// {"fixed128x128[2]", Type{}},
|
// {"fixed128x128[2]", Type{}},
|
||||||
}
|
}
|
||||||
for i, tt := range tests {
|
|
||||||
|
for _, tt := range tests {
|
||||||
typ, err := NewType(tt.blob)
|
typ, err := NewType(tt.blob)
|
||||||
if err != nil {
|
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) {
|
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)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue