diff options
author | Felix Lange <fjl@twurst.com> | 2016-12-17 22:39:55 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-12-20 21:41:58 +0800 |
commit | cf71f5cd604f4d5c94d9e9b12b121a614d662dc7 (patch) | |
tree | a89491c26dc19fc39bb6d8273eeefa2778ff5ec2 /rpc/types.go | |
parent | adab2e16bdf24c2eaf498722187fb36c04a5376b (diff) | |
download | dexon-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.tar dexon-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.tar.gz dexon-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.tar.bz2 dexon-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.tar.lz dexon-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.tar.xz dexon-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.tar.zst dexon-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.zip |
rpc: remove HexNumber, replace all uses with hexutil types
This change couldn't be automated because HexNumber was used for numbers
of all sizes.
Diffstat (limited to 'rpc/types.go')
-rw-r--r-- | rpc/types.go | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/rpc/types.go b/rpc/types.go index 89c5b5bc9..01b95a170 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -121,91 +121,6 @@ type ServerCodec interface { Closed() <-chan interface{} } -// HexNumber serializes a number to hex format using the "%#x" format -type HexNumber big.Int - -// NewHexNumber creates a new hex number instance which will serialize the given val with `%#x` on marshal. -func NewHexNumber(val interface{}) *HexNumber { - if val == nil { - return nil // note, this doesn't catch nil pointers, only passing nil directly! - } - - if v, ok := val.(*big.Int); ok { - if v != nil { - return (*HexNumber)(new(big.Int).Set(v)) - } - return nil - } - - rval := reflect.ValueOf(val) - - var unsigned uint64 - utype := reflect.TypeOf(unsigned) - if t := rval.Type(); t.ConvertibleTo(utype) { - hn := new(big.Int).SetUint64(rval.Convert(utype).Uint()) - return (*HexNumber)(hn) - } - - var signed int64 - stype := reflect.TypeOf(signed) - if t := rval.Type(); t.ConvertibleTo(stype) { - hn := new(big.Int).SetInt64(rval.Convert(stype).Int()) - return (*HexNumber)(hn) - } - - return nil -} - -func (h *HexNumber) UnmarshalJSON(input []byte) error { - length := len(input) - if length >= 2 && input[0] == '"' && input[length-1] == '"' { - input = input[1 : length-1] - } - - hn := (*big.Int)(h) - if _, ok := hn.SetString(string(input), 0); ok { - return nil - } - - return fmt.Errorf("Unable to parse number") -} - -// MarshalJSON serialize the hex number instance to a hex representation. -func (h *HexNumber) MarshalJSON() ([]byte, error) { - if h != nil { - hn := (*big.Int)(h) - if hn.BitLen() == 0 { - return []byte(`"0x0"`), nil - } - return []byte(fmt.Sprintf(`"0x%x"`, hn)), nil - } - return nil, nil -} - -func (h *HexNumber) Int() int { - hn := (*big.Int)(h) - return int(hn.Int64()) -} - -func (h *HexNumber) Int64() int64 { - hn := (*big.Int)(h) - return hn.Int64() -} - -func (h *HexNumber) Uint() uint { - hn := (*big.Int)(h) - return uint(hn.Uint64()) -} - -func (h *HexNumber) Uint64() uint64 { - hn := (*big.Int)(h) - return hn.Uint64() -} - -func (h *HexNumber) BigInt() *big.Int { - return (*big.Int)(h) -} - var ( pendingBlockNumber = big.NewInt(-2) latestBlockNumber = big.NewInt(-1) |