diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-04-02 17:32:50 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-04-02 17:32:50 +0800 |
commit | c71ca1a089cc963848c5eee7391a53168adf188c (patch) | |
tree | 33d263ca9a3a3550f9eb098e8eac86e9db3c9057 /rpc | |
parent | 5d8be9c30d1f2334ecac0ddb92d82a878b35c51c (diff) | |
download | go-tangerine-c71ca1a089cc963848c5eee7391a53168adf188c.tar.gz go-tangerine-c71ca1a089cc963848c5eee7391a53168adf188c.tar.zst go-tangerine-c71ca1a089cc963848c5eee7391a53168adf188c.zip |
Better nil handling
Diffstat (limited to 'rpc')
-rw-r--r-- | rpc/types.go | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/rpc/types.go b/rpc/types.go index 75c4ba85f..53a2a0806 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -24,10 +24,12 @@ import ( "strings" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" ) type hexdata struct { - data []byte + data []byte + isNil bool } func (d *hexdata) String() string { @@ -35,6 +37,9 @@ func (d *hexdata) String() string { } func (d *hexdata) MarshalJSON() ([]byte, error) { + if d.isNil { + return json.Marshal(nil) + } return json.Marshal(d.String()) } @@ -56,11 +61,19 @@ func newHexData(input interface{}) *hexdata { case common.Hash: d.data = input.Bytes() case *common.Hash: - d.data = input.Bytes() + if input == nil { + d.isNil = true + } else { + d.data = input.Bytes() + } case common.Address: d.data = input.Bytes() - // case *common.Address: - // d.data = input.Bytes() + case *common.Address: + if input == nil { + d.isNil = true + } else { + d.data = input.Bytes() + } case *big.Int: d.data = input.Bytes() case int64: @@ -83,7 +96,8 @@ func newHexData(input interface{}) *hexdata { } type hexnum struct { - data []byte + data []byte + isNil bool } func (d *hexnum) String() string { @@ -99,6 +113,9 @@ func (d *hexnum) String() string { } func (d *hexnum) MarshalJSON() ([]byte, error) { + if d.isNil { + return json.Marshal(nil) + } return json.Marshal(d.String()) } |