github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/accounts/abi/numbers.go (about)

     1  package abi
     2  
     3  import (
     4  	"math/big"
     5  	"reflect"
     6  
     7  	"github.com/quickchainproject/quickchain/common"
     8  	"github.com/quickchainproject/quickchain/common/math"
     9  )
    10  
    11  var (
    12  	bigT      = reflect.TypeOf(&big.Int{})
    13  	derefbigT = reflect.TypeOf(big.Int{})
    14  	uint8T    = reflect.TypeOf(uint8(0))
    15  	uint16T   = reflect.TypeOf(uint16(0))
    16  	uint32T   = reflect.TypeOf(uint32(0))
    17  	uint64T   = reflect.TypeOf(uint64(0))
    18  	intT      = reflect.TypeOf(int(0))
    19  	int8T     = reflect.TypeOf(int8(0))
    20  	int16T    = reflect.TypeOf(int16(0))
    21  	int32T    = reflect.TypeOf(int32(0))
    22  	int64T    = reflect.TypeOf(int64(0))
    23  	addressT  = reflect.TypeOf(common.Address{})
    24  	intTS     = reflect.TypeOf([]int(nil))
    25  	int8TS    = reflect.TypeOf([]int8(nil))
    26  	int16TS   = reflect.TypeOf([]int16(nil))
    27  	int32TS   = reflect.TypeOf([]int32(nil))
    28  	int64TS   = reflect.TypeOf([]int64(nil))
    29  )
    30  
    31  // U256 converts a big Int into a 256bit EVM number.
    32  func U256(n *big.Int) []byte {
    33  	return math.PaddedBigBytes(math.U256(n), 32)
    34  }
    35  
    36  // checks whether the given reflect value is signed. This also works for slices with a number type
    37  func isSigned(v reflect.Value) bool {
    38  	switch v.Type() {
    39  	case intTS, int8TS, int16TS, int32TS, int64TS, intT, int8T, int16T, int32T, int64T:
    40  		return true
    41  	}
    42  	return false
    43  }