diff options
author | johnliu-dexon <42129254+johnliu-dexon@users.noreply.github.com> | 2019-01-17 16:37:15 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:21 +0800 |
commit | 65e94faf4e9cb6ba1f3c9ab4035e84e8add0aa14 (patch) | |
tree | f3a0aec1d94e9b4b2b6a4160b2d58e878b4c744f /common | |
parent | fe51a95f23652e36b361d50de733397c4e28c26d (diff) | |
download | go-tangerine-65e94faf4e9cb6ba1f3c9ab4035e84e8add0aa14.tar go-tangerine-65e94faf4e9cb6ba1f3c9ab4035e84e8add0aa14.tar.gz go-tangerine-65e94faf4e9cb6ba1f3c9ab4035e84e8add0aa14.tar.bz2 go-tangerine-65e94faf4e9cb6ba1f3c9ab4035e84e8add0aa14.tar.lz go-tangerine-65e94faf4e9cb6ba1f3c9ab4035e84e8add0aa14.tar.xz go-tangerine-65e94faf4e9cb6ba1f3c9ab4035e84e8add0aa14.tar.zst go-tangerine-65e94faf4e9cb6ba1f3c9ab4035e84e8add0aa14.zip |
common: fix big scan from bytes (#157)
We store string of number, not bytes value into database
10 is stored as 0x3130, not 0x0a
Use UnmarshalText instead of SetBytes
Diffstat (limited to 'common')
-rw-r--r-- | common/big.go | 6 | ||||
-rw-r--r-- | common/big_test.go | 2 |
2 files changed, 6 insertions, 2 deletions
diff --git a/common/big.go b/common/big.go index ea3d4aba6..96a83661e 100644 --- a/common/big.go +++ b/common/big.go @@ -45,7 +45,11 @@ func (b *Big) Scan(src interface{}) error { case uint64: *b = Big(*newB.SetUint64(t)) case []byte: - *b = Big(*newB.SetBytes(t)) + err := newB.UnmarshalText(t) + if err != nil { + return err + } + *b = Big(*newB) case string: v, ok := newB.SetString(t, 10) if !ok { diff --git a/common/big_test.go b/common/big_test.go index 0339b4760..5ce9091ec 100644 --- a/common/big_test.go +++ b/common/big_test.go @@ -31,7 +31,7 @@ func TestBig_Scan(t *testing.T) { }, { name: "scan bytes", - args: args{src: []byte{0x0a}}, + args: args{src: []byte{0x31, 0x30}}, value: Big(*big.NewInt(10)), wantErr: false, }, |