diff options
author | Felix Lange <fjl@twurst.com> | 2016-08-04 07:40:50 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-08-04 07:40:50 +0800 |
commit | b0d9f7372a04fa8f0ffc391f0997e2e062d465ef (patch) | |
tree | c78c4ee8bd261cd1b1d8b896a39c8612f435f154 /rpc/types.go | |
parent | 704fde01e8ed28877fe0f69fc8059b1f0c850d04 (diff) | |
download | go-tangerine-b0d9f7372a04fa8f0ffc391f0997e2e062d465ef.tar.gz go-tangerine-b0d9f7372a04fa8f0ffc391f0997e2e062d465ef.tar.zst go-tangerine-b0d9f7372a04fa8f0ffc391f0997e2e062d465ef.zip |
internal/ethapi: add missing output fields
- returned headers didn't include mixHash
- returned transactions didn't include signature fields
- empty transaction input was returned as "", but should be "0x"
- returned receipts didn't include the bloom filter
- "root" in receipts was missing 0x prefix
Diffstat (limited to 'rpc/types.go')
-rw-r--r-- | rpc/types.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/rpc/types.go b/rpc/types.go index 89c5b5bc9..ebe388373 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -17,6 +17,8 @@ package rpc import ( + "bytes" + "encoding/hex" "fmt" "math" "math/big" @@ -272,3 +274,31 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error { func (bn BlockNumber) Int64() int64 { return (int64)(bn) } + +// HexBytes JSON-encodes as hex with 0x prefix. +type HexBytes []byte + +func (b HexBytes) MarshalJSON() ([]byte, error) { + result := make([]byte, len(b)*2+4) + copy(result, `"0x`) + hex.Encode(result[3:], b) + result[len(result)-1] = '"' + return result, nil +} + +func (b *HexBytes) UnmarshalJSON(input []byte) error { + if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' { + input = input[1 : len(input)-1] + } + if !bytes.HasPrefix(input, []byte("0x")) { + return fmt.Errorf("missing 0x prefix for hex byte array") + } + input = input[2:] + if len(input) == 0 { + *b = nil + return nil + } + *b = make([]byte, len(input)/2) + _, err := hex.Decode(*b, input) + return err +} |