From 65b34f272e6000299399125f73759e76dc564c79 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Sun, 18 Jun 2017 20:10:35 -0500 Subject: [PATCH] accounts/abi: move packNumbers into pack.go. Signed-off-by: RJ Catalano --- accounts/abi/numbers.go | 13 ------------- accounts/abi/pack.go | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/accounts/abi/numbers.go b/accounts/abi/numbers.go index 10afa6511f..5d3efff52e 100644 --- a/accounts/abi/numbers.go +++ b/accounts/abi/numbers.go @@ -62,19 +62,6 @@ func U256(n *big.Int) []byte { return math.PaddedBigBytes(math.U256(n), 32) } -// packNum packs the given number (using the reflect value) and will cast it to appropriate number representation -func packNum(value reflect.Value) []byte { - switch kind := value.Kind(); kind { - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - return U256(new(big.Int).SetUint64(value.Uint())) - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return U256(big.NewInt(value.Int())) - case reflect.Ptr: - return U256(value.Interface().(*big.Int)) - } - return nil -} - // checks whether the given reflect value is signed. This also works for slices with a number type func isSigned(v reflect.Value) bool { switch v.Type() { diff --git a/accounts/abi/pack.go b/accounts/abi/pack.go index 1d7f85e2ba..4d8a3f0318 100644 --- a/accounts/abi/pack.go +++ b/accounts/abi/pack.go @@ -17,6 +17,7 @@ package abi import ( + "math/big" "reflect" "github.com/ethereum/go-ethereum/common" @@ -59,8 +60,20 @@ func packElement(t Type, reflectValue reflect.Value) []byte { if reflectValue.Kind() == reflect.Array { reflectValue = mustArrayToByteSlice(reflectValue) } - return common.RightPadBytes(reflectValue.Bytes(), 32) } panic("abi: fatal error") } + +// packNum packs the given number (using the reflect value) and will cast it to appropriate number representation +func packNum(value reflect.Value) []byte { + switch kind := value.Kind(); kind { + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return U256(new(big.Int).SetUint64(value.Uint())) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return U256(big.NewInt(value.Int())) + case reflect.Ptr: + return U256(value.Interface().(*big.Int)) + } + return nil +}