diff options
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) |