aboutsummaryrefslogtreecommitdiffstats
path: root/common/hexutil/json.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2017-02-27 02:40:33 +0800
committerFelix Lange <fjl@twurst.com>2017-03-02 21:05:46 +0800
commit280f08be84325924ea7628a8187fd84e7cc39145 (patch)
treec7b5a3c639e5c617004630a0ea98248c3211f5d3 /common/hexutil/json.go
parentd304da380382245190f33878363696cd151201a9 (diff)
downloaddexon-280f08be84325924ea7628a8187fd84e7cc39145.tar
dexon-280f08be84325924ea7628a8187fd84e7cc39145.tar.gz
dexon-280f08be84325924ea7628a8187fd84e7cc39145.tar.bz2
dexon-280f08be84325924ea7628a8187fd84e7cc39145.tar.lz
dexon-280f08be84325924ea7628a8187fd84e7cc39145.tar.xz
dexon-280f08be84325924ea7628a8187fd84e7cc39145.tar.zst
dexon-280f08be84325924ea7628a8187fd84e7cc39145.zip
common/hexutil: ensure negative big.Int is encoded sensibly
Restricting encoding is silly.
Diffstat (limited to 'common/hexutil/json.go')
-rw-r--r--common/hexutil/json.go18
1 files changed, 3 insertions, 15 deletions
diff --git a/common/hexutil/json.go b/common/hexutil/json.go
index ce6a2b048..23393ed2c 100644
--- a/common/hexutil/json.go
+++ b/common/hexutil/json.go
@@ -25,9 +25,8 @@ import (
)
var (
- textZero = []byte(`0x0`)
- errNonString = errors.New("cannot unmarshal non-string as hex data")
- errNegativeBigInt = errors.New("hexutil.Big: can't marshal negative integer")
+ textZero = []byte(`0x0`)
+ errNonString = errors.New("cannot unmarshal non-string as hex data")
)
// Bytes marshals/unmarshals as a JSON string with 0x prefix.
@@ -101,18 +100,7 @@ type Big big.Int
// MarshalText implements encoding.TextMarshaler
func (b Big) MarshalText() ([]byte, error) {
- bigint := (big.Int)(b)
- if bigint.Sign() == -1 {
- return nil, errNegativeBigInt
- }
- nbits := bigint.BitLen()
- if nbits == 0 {
- return textZero, nil
- }
- enc := make([]byte, 2, nbits/4+2)
- copy(enc, "0x")
- enc = bigint.Append(enc, 16)
- return enc, nil
+ return []byte(EncodeBig((*big.Int)(&b))), nil
}
// UnmarshalJSON implements json.Unmarshaler.