github.com/waltonchain/waltonchain_gwtc_src@v1.1.4-0.20201225072101-8a298c95a819/accounts/abi/numbers.go (about) 1 // Copyright 2015 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-wtc library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-wtc library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package abi 18 19 import ( 20 "math/big" 21 "reflect" 22 23 "github.com/wtc/go-wtc/common" 24 "github.com/wtc/go-wtc/common/math" 25 ) 26 27 var ( 28 big_t = reflect.TypeOf(big.Int{}) 29 ubig_t = reflect.TypeOf(big.Int{}) 30 byte_t = reflect.TypeOf(byte(0)) 31 byte_ts = reflect.TypeOf([]byte(nil)) 32 uint_t = reflect.TypeOf(uint(0)) 33 uint8_t = reflect.TypeOf(uint8(0)) 34 uint16_t = reflect.TypeOf(uint16(0)) 35 uint32_t = reflect.TypeOf(uint32(0)) 36 uint64_t = reflect.TypeOf(uint64(0)) 37 int_t = reflect.TypeOf(int(0)) 38 int8_t = reflect.TypeOf(int8(0)) 39 int16_t = reflect.TypeOf(int16(0)) 40 int32_t = reflect.TypeOf(int32(0)) 41 int64_t = reflect.TypeOf(int64(0)) 42 hash_t = reflect.TypeOf(common.Hash{}) 43 address_t = reflect.TypeOf(common.Address{}) 44 45 uint_ts = reflect.TypeOf([]uint(nil)) 46 uint8_ts = reflect.TypeOf([]uint8(nil)) 47 uint16_ts = reflect.TypeOf([]uint16(nil)) 48 uint32_ts = reflect.TypeOf([]uint32(nil)) 49 uint64_ts = reflect.TypeOf([]uint64(nil)) 50 ubig_ts = reflect.TypeOf([]*big.Int(nil)) 51 52 int_ts = reflect.TypeOf([]int(nil)) 53 int8_ts = reflect.TypeOf([]int8(nil)) 54 int16_ts = reflect.TypeOf([]int16(nil)) 55 int32_ts = reflect.TypeOf([]int32(nil)) 56 int64_ts = reflect.TypeOf([]int64(nil)) 57 big_ts = reflect.TypeOf([]*big.Int(nil)) 58 ) 59 60 // U256 converts a big Int into a 256bit EVM number. 61 func U256(n *big.Int) []byte { 62 return math.PaddedBigBytes(math.U256(n), 32) 63 } 64 65 // checks whether the given reflect value is signed. This also works for slices with a number type 66 func isSigned(v reflect.Value) bool { 67 switch v.Type() { 68 case int_ts, int8_ts, int16_ts, int32_ts, int64_ts, int_t, int8_t, int16_t, int32_t, int64_t: 69 return true 70 } 71 return false 72 }