github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/accounts/abi/numbers.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 package abi 13 14 import ( 15 "math/big" 16 "reflect" 17 18 "github.com/Sberex/go-sberex/common" 19 "github.com/Sberex/go-sberex/common/math" 20 ) 21 22 var ( 23 big_t = reflect.TypeOf(&big.Int{}) 24 derefbig_t = reflect.TypeOf(big.Int{}) 25 uint8_t = reflect.TypeOf(uint8(0)) 26 uint16_t = reflect.TypeOf(uint16(0)) 27 uint32_t = reflect.TypeOf(uint32(0)) 28 uint64_t = reflect.TypeOf(uint64(0)) 29 int_t = reflect.TypeOf(int(0)) 30 int8_t = reflect.TypeOf(int8(0)) 31 int16_t = reflect.TypeOf(int16(0)) 32 int32_t = reflect.TypeOf(int32(0)) 33 int64_t = reflect.TypeOf(int64(0)) 34 address_t = reflect.TypeOf(common.Address{}) 35 int_ts = reflect.TypeOf([]int(nil)) 36 int8_ts = reflect.TypeOf([]int8(nil)) 37 int16_ts = reflect.TypeOf([]int16(nil)) 38 int32_ts = reflect.TypeOf([]int32(nil)) 39 int64_ts = reflect.TypeOf([]int64(nil)) 40 ) 41 42 // U256 converts a big Int into a 256bit EVM number. 43 func U256(n *big.Int) []byte { 44 return math.PaddedBigBytes(math.U256(n), 32) 45 } 46 47 // checks whether the given reflect value is signed. This also works for slices with a number type 48 func isSigned(v reflect.Value) bool { 49 switch v.Type() { 50 case int_ts, int8_ts, int16_ts, int32_ts, int64_ts, int_t, int8_t, int16_t, int32_t, int64_t: 51 return true 52 } 53 return false 54 }