core, core/types: regenerate JSON marshaling, add "hash" to headers (#13868)

* Makefile: fix devtools target

* core: regenerate genesis marshaling with fjl/gencodec@cbfa5be5a8a8

* core/types: regenerate marshaling methods with fjl/gencodec@cbfa5be5a8a8

* core/types: add "hash" to JSON headers
pull/3773/head
Felix Lange 8 years ago committed by Péter Szilágyi
parent 24b9860c1b
commit 3d8de95f99
  1. 8
      Makefile
  2. 76
      core/gen_genesis.go
  3. 34
      core/gen_genesis_account.go
  4. 28
      core/genesis.go
  5. 31
      core/types/block.go
  6. 106
      core/types/gen_header_json.go
  7. 64
      core/types/gen_log_json.go
  8. 52
      core/types/gen_receipt_json.go
  9. 70
      core/types/gen_tx_json.go
  10. 18
      core/types/log.go
  11. 14
      core/types/receipt.go
  12. 20
      core/types/transaction.go

@ -44,10 +44,10 @@ clean:
# You need to put $GOBIN (or $GOPATH/bin) in your PATH to use 'go generate'. # You need to put $GOBIN (or $GOPATH/bin) in your PATH to use 'go generate'.
devtools: devtools:
go get -u golang.org/x/tools/cmd/stringer env GOBIN= go get -u golang.org/x/tools/cmd/stringer
go get -u github.com/jteeuwen/go-bindata/go-bindata env GOBIN= go get -u github.com/jteeuwen/go-bindata/go-bindata
go get -u github.com/fjl/gencodec env GOBIN= go get -u github.com/fjl/gencodec
go install ./cmd/abigen env GOBIN= go install ./cmd/abigen
# Cross Compilation Targets (xgo) # Cross Compilation Targets (xgo)

@ -14,19 +14,19 @@ import (
) )
func (g Genesis) MarshalJSON() ([]byte, error) { func (g Genesis) MarshalJSON() ([]byte, error) {
type GenesisJSON struct { type Genesis struct {
Config *params.ChainConfig `json:"config" optional:"true"` Config *params.ChainConfig `json:"config"`
Nonce math.HexOrDecimal64 `json:"nonce" optional:"true"` Nonce math.HexOrDecimal64 `json:"nonce"`
Timestamp math.HexOrDecimal64 `json:"timestamp" optional:"true"` Timestamp math.HexOrDecimal64 `json:"timestamp"`
ParentHash common.Hash `json:"parentHash" optional:"true"` ParentHash common.Hash `json:"parentHash"`
ExtraData hexutil.Bytes `json:"extraData" optional:"true"` ExtraData hexutil.Bytes `json:"extraData"`
GasLimit math.HexOrDecimal64 `json:"gasLimit"` GasLimit math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"`
Difficulty *math.HexOrDecimal256 `json:"difficulty"` Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"`
Mixhash common.Hash `json:"mixHash" optional:"true"` Mixhash common.Hash `json:"mixHash"`
Coinbase common.Address `json:"coinbase" optional:"true"` Coinbase common.Address `json:"coinbase"`
Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc"` Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"`
} }
var enc GenesisJSON var enc Genesis
enc.Config = g.Config enc.Config = g.Config
enc.Nonce = math.HexOrDecimal64(g.Nonce) enc.Nonce = math.HexOrDecimal64(g.Nonce)
enc.Timestamp = math.HexOrDecimal64(g.Timestamp) enc.Timestamp = math.HexOrDecimal64(g.Timestamp)
@ -46,59 +46,57 @@ func (g Genesis) MarshalJSON() ([]byte, error) {
} }
func (g *Genesis) UnmarshalJSON(input []byte) error { func (g *Genesis) UnmarshalJSON(input []byte) error {
type GenesisJSON struct { type Genesis struct {
Config *params.ChainConfig `json:"config" optional:"true"` Config *params.ChainConfig `json:"config"`
Nonce *math.HexOrDecimal64 `json:"nonce" optional:"true"` Nonce *math.HexOrDecimal64 `json:"nonce"`
Timestamp *math.HexOrDecimal64 `json:"timestamp" optional:"true"` Timestamp *math.HexOrDecimal64 `json:"timestamp"`
ParentHash *common.Hash `json:"parentHash" optional:"true"` ParentHash *common.Hash `json:"parentHash"`
ExtraData hexutil.Bytes `json:"extraData" optional:"true"` ExtraData hexutil.Bytes `json:"extraData"`
GasLimit *math.HexOrDecimal64 `json:"gasLimit"` GasLimit *math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"`
Difficulty *math.HexOrDecimal256 `json:"difficulty"` Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"`
Mixhash *common.Hash `json:"mixHash" optional:"true"` Mixhash *common.Hash `json:"mixHash"`
Coinbase *common.Address `json:"coinbase" optional:"true"` Coinbase *common.Address `json:"coinbase"`
Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc"` Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"`
} }
var dec GenesisJSON var dec Genesis
if err := json.Unmarshal(input, &dec); err != nil { if err := json.Unmarshal(input, &dec); err != nil {
return err return err
} }
var x Genesis
if dec.Config != nil { if dec.Config != nil {
x.Config = dec.Config g.Config = dec.Config
} }
if dec.Nonce != nil { if dec.Nonce != nil {
x.Nonce = uint64(*dec.Nonce) g.Nonce = uint64(*dec.Nonce)
} }
if dec.Timestamp != nil { if dec.Timestamp != nil {
x.Timestamp = uint64(*dec.Timestamp) g.Timestamp = uint64(*dec.Timestamp)
} }
if dec.ParentHash != nil { if dec.ParentHash != nil {
x.ParentHash = *dec.ParentHash g.ParentHash = *dec.ParentHash
} }
if dec.ExtraData != nil { if dec.ExtraData != nil {
x.ExtraData = dec.ExtraData g.ExtraData = dec.ExtraData
} }
if dec.GasLimit == nil { if dec.GasLimit == nil {
return errors.New("missing required field 'gasLimit' for Genesis") return errors.New("missing required field 'gasLimit' for Genesis")
} }
x.GasLimit = uint64(*dec.GasLimit) g.GasLimit = uint64(*dec.GasLimit)
if dec.Difficulty == nil { if dec.Difficulty == nil {
return errors.New("missing required field 'difficulty' for Genesis") return errors.New("missing required field 'difficulty' for Genesis")
} }
x.Difficulty = (*big.Int)(dec.Difficulty) g.Difficulty = (*big.Int)(dec.Difficulty)
if dec.Mixhash != nil { if dec.Mixhash != nil {
x.Mixhash = *dec.Mixhash g.Mixhash = *dec.Mixhash
} }
if dec.Coinbase != nil { if dec.Coinbase != nil {
x.Coinbase = *dec.Coinbase g.Coinbase = *dec.Coinbase
} }
if dec.Alloc == nil { if dec.Alloc == nil {
return errors.New("missing required field 'alloc' for Genesis") return errors.New("missing required field 'alloc' for Genesis")
} }
x.Alloc = make(GenesisAlloc, len(dec.Alloc)) g.Alloc = make(GenesisAlloc, len(dec.Alloc))
for k, v := range dec.Alloc { for k, v := range dec.Alloc {
x.Alloc[common.Address(k)] = v g.Alloc[common.Address(k)] = v
} }
*g = x
return nil return nil
} }

@ -13,13 +13,13 @@ import (
) )
func (g GenesisAccount) MarshalJSON() ([]byte, error) { func (g GenesisAccount) MarshalJSON() ([]byte, error) {
type GenesisAccountJSON struct { type GenesisAccount struct {
Code hexutil.Bytes `json:"code,omitempty" optional:"true"` Code hexutil.Bytes `json:"code,omitempty"`
Storage map[common.Hash]common.Hash `json:"storage,omitempty" optional:"true"` Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
Balance *math.HexOrDecimal256 `json:"balance"` Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
Nonce math.HexOrDecimal64 `json:"nonce,omitempty" optional:"true"` Nonce math.HexOrDecimal64 `json:"nonce,omitempty"`
} }
var enc GenesisAccountJSON var enc GenesisAccount
enc.Code = g.Code enc.Code = g.Code
enc.Storage = g.Storage enc.Storage = g.Storage
enc.Balance = (*math.HexOrDecimal256)(g.Balance) enc.Balance = (*math.HexOrDecimal256)(g.Balance)
@ -28,30 +28,28 @@ func (g GenesisAccount) MarshalJSON() ([]byte, error) {
} }
func (g *GenesisAccount) UnmarshalJSON(input []byte) error { func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
type GenesisAccountJSON struct { type GenesisAccount struct {
Code hexutil.Bytes `json:"code,omitempty" optional:"true"` Code hexutil.Bytes `json:"code,omitempty"`
Storage map[common.Hash]common.Hash `json:"storage,omitempty" optional:"true"` Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
Balance *math.HexOrDecimal256 `json:"balance"` Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
Nonce *math.HexOrDecimal64 `json:"nonce,omitempty" optional:"true"` Nonce *math.HexOrDecimal64 `json:"nonce,omitempty"`
} }
var dec GenesisAccountJSON var dec GenesisAccount
if err := json.Unmarshal(input, &dec); err != nil { if err := json.Unmarshal(input, &dec); err != nil {
return err return err
} }
var x GenesisAccount
if dec.Code != nil { if dec.Code != nil {
x.Code = dec.Code g.Code = dec.Code
} }
if dec.Storage != nil { if dec.Storage != nil {
x.Storage = dec.Storage g.Storage = dec.Storage
} }
if dec.Balance == nil { if dec.Balance == nil {
return errors.New("missing required field 'balance' for GenesisAccount") return errors.New("missing required field 'balance' for GenesisAccount")
} }
x.Balance = (*big.Int)(dec.Balance) g.Balance = (*big.Int)(dec.Balance)
if dec.Nonce != nil { if dec.Nonce != nil {
x.Nonce = uint64(*dec.Nonce) g.Nonce = uint64(*dec.Nonce)
} }
*g = x
return nil return nil
} }

@ -41,16 +41,16 @@ var errGenesisNoConfig = errors.New("genesis has no chain configuration")
// Genesis specifies the header fields, state of a genesis block. It also defines hard // Genesis specifies the header fields, state of a genesis block. It also defines hard
// fork switch-over blocks through the chain configuration. // fork switch-over blocks through the chain configuration.
type Genesis struct { type Genesis struct {
Config *params.ChainConfig `json:"config" optional:"true"` Config *params.ChainConfig `json:"config"`
Nonce uint64 `json:"nonce" optional:"true"` Nonce uint64 `json:"nonce"`
Timestamp uint64 `json:"timestamp" optional:"true"` Timestamp uint64 `json:"timestamp"`
ParentHash common.Hash `json:"parentHash" optional:"true"` ParentHash common.Hash `json:"parentHash"`
ExtraData []byte `json:"extraData" optional:"true"` ExtraData []byte `json:"extraData"`
GasLimit uint64 `json:"gasLimit"` GasLimit uint64 `json:"gasLimit" gencodec:"required"`
Difficulty *big.Int `json:"difficulty"` Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Mixhash common.Hash `json:"mixHash" optional:"true"` Mixhash common.Hash `json:"mixHash"`
Coinbase common.Address `json:"coinbase" optional:"true"` Coinbase common.Address `json:"coinbase"`
Alloc GenesisAlloc `json:"alloc"` Alloc GenesisAlloc `json:"alloc" gencodec:"required"`
} }
// GenesisAlloc specifies the initial state that is part of the genesis block. // GenesisAlloc specifies the initial state that is part of the genesis block.
@ -58,10 +58,10 @@ type GenesisAlloc map[common.Address]GenesisAccount
// GenesisAccount is an account in the state of the genesis block. // GenesisAccount is an account in the state of the genesis block.
type GenesisAccount struct { type GenesisAccount struct {
Code []byte `json:"code,omitempty" optional:"true"` Code []byte `json:"code,omitempty"`
Storage map[common.Hash]common.Hash `json:"storage,omitempty" optional:"true"` Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
Balance *big.Int `json:"balance"` Balance *big.Int `json:"balance" gencodec:"required"`
Nonce uint64 `json:"nonce,omitempty" optional:"true"` Nonce uint64 `json:"nonce,omitempty"`
} }
// field type overrides for gencodec // field type overrides for gencodec

@ -68,21 +68,21 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
// Header represents a block header in the Ethereum blockchain. // Header represents a block header in the Ethereum blockchain.
type Header struct { type Header struct {
ParentHash common.Hash `json:"parentHash"` ParentHash common.Hash `json:"parentHash" gencodec:"required"`
UncleHash common.Hash `json:"sha3Uncles"` UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase common.Address `json:"miner"` Coinbase common.Address `json:"miner" gencodec:"required"`
Root common.Hash `json:"stateRoot"` Root common.Hash `json:"stateRoot" gencodec:"required"`
TxHash common.Hash `json:"transactionsRoot"` TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
ReceiptHash common.Hash `json:"receiptsRoot"` ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
Bloom Bloom `json:"logsBloom"` Bloom Bloom `json:"logsBloom" gencodec:"required"`
Difficulty *big.Int `json:"difficulty"` Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Number *big.Int `json:"number"` Number *big.Int `json:"number" gencodec:"required"`
GasLimit *big.Int `json:"gasLimit"` GasLimit *big.Int `json:"gasLimit" gencodec:"required"`
GasUsed *big.Int `json:"gasUsed"` GasUsed *big.Int `json:"gasUsed" gencodec:"required"`
Time *big.Int `json:"timestamp"` Time *big.Int `json:"timestamp" gencodec:"required"`
Extra []byte `json:"extraData"` Extra []byte `json:"extraData" gencodec:"required"`
MixDigest common.Hash `json:"mixHash"` MixDigest common.Hash `json:"mixHash" gencodec:"required"`
Nonce BlockNonce `json:"nonce"` Nonce BlockNonce `json:"nonce" gencodec:"required"`
} }
// field type overrides for gencodec // field type overrides for gencodec
@ -93,6 +93,7 @@ type headerMarshaling struct {
GasUsed *hexutil.Big GasUsed *hexutil.Big
Time *hexutil.Big Time *hexutil.Big
Extra hexutil.Bytes Extra hexutil.Bytes
Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON
} }
// Hash returns the block hash of the header, which is simply the keccak256 hash of its // Hash returns the block hash of the header, which is simply the keccak256 hash of its

@ -12,24 +12,25 @@ import (
) )
func (h Header) MarshalJSON() ([]byte, error) { func (h Header) MarshalJSON() ([]byte, error) {
type HeaderJSON struct { type Header struct {
ParentHash common.Hash `json:"parentHash"` ParentHash common.Hash `json:"parentHash" gencodec:"required"`
UncleHash common.Hash `json:"sha3Uncles"` UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase common.Address `json:"miner"` Coinbase common.Address `json:"miner" gencodec:"required"`
Root common.Hash `json:"stateRoot"` Root common.Hash `json:"stateRoot" gencodec:"required"`
TxHash common.Hash `json:"transactionsRoot"` TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
ReceiptHash common.Hash `json:"receiptsRoot"` ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
Bloom Bloom `json:"logsBloom"` Bloom Bloom `json:"logsBloom" gencodec:"required"`
Difficulty *hexutil.Big `json:"difficulty"` Difficulty *hexutil.Big `json:"difficulty" gencodec:"required"`
Number *hexutil.Big `json:"number"` Number *hexutil.Big `json:"number" gencodec:"required"`
GasLimit *hexutil.Big `json:"gasLimit"` GasLimit *hexutil.Big `json:"gasLimit" gencodec:"required"`
GasUsed *hexutil.Big `json:"gasUsed"` GasUsed *hexutil.Big `json:"gasUsed" gencodec:"required"`
Time *hexutil.Big `json:"timestamp"` Time *hexutil.Big `json:"timestamp" gencodec:"required"`
Extra hexutil.Bytes `json:"extraData"` Extra hexutil.Bytes `json:"extraData" gencodec:"required"`
MixDigest common.Hash `json:"mixHash"` MixDigest common.Hash `json:"mixHash" gencodec:"required"`
Nonce BlockNonce `json:"nonce"` Nonce BlockNonce `json:"nonce" gencodec:"required"`
} Hash common.Hash `json:"hash"`
var enc HeaderJSON }
var enc Header
enc.ParentHash = h.ParentHash enc.ParentHash = h.ParentHash
enc.UncleHash = h.UncleHash enc.UncleHash = h.UncleHash
enc.Coinbase = h.Coinbase enc.Coinbase = h.Coinbase
@ -45,92 +46,91 @@ func (h Header) MarshalJSON() ([]byte, error) {
enc.Extra = h.Extra enc.Extra = h.Extra
enc.MixDigest = h.MixDigest enc.MixDigest = h.MixDigest
enc.Nonce = h.Nonce enc.Nonce = h.Nonce
enc.Hash = h.Hash()
return json.Marshal(&enc) return json.Marshal(&enc)
} }
func (h *Header) UnmarshalJSON(input []byte) error { func (h *Header) UnmarshalJSON(input []byte) error {
type HeaderJSON struct { type Header struct {
ParentHash *common.Hash `json:"parentHash"` ParentHash *common.Hash `json:"parentHash" gencodec:"required"`
UncleHash *common.Hash `json:"sha3Uncles"` UncleHash *common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase *common.Address `json:"miner"` Coinbase *common.Address `json:"miner" gencodec:"required"`
Root *common.Hash `json:"stateRoot"` Root *common.Hash `json:"stateRoot" gencodec:"required"`
TxHash *common.Hash `json:"transactionsRoot"` TxHash *common.Hash `json:"transactionsRoot" gencodec:"required"`
ReceiptHash *common.Hash `json:"receiptsRoot"` ReceiptHash *common.Hash `json:"receiptsRoot" gencodec:"required"`
Bloom *Bloom `json:"logsBloom"` Bloom *Bloom `json:"logsBloom" gencodec:"required"`
Difficulty *hexutil.Big `json:"difficulty"` Difficulty *hexutil.Big `json:"difficulty" gencodec:"required"`
Number *hexutil.Big `json:"number"` Number *hexutil.Big `json:"number" gencodec:"required"`
GasLimit *hexutil.Big `json:"gasLimit"` GasLimit *hexutil.Big `json:"gasLimit" gencodec:"required"`
GasUsed *hexutil.Big `json:"gasUsed"` GasUsed *hexutil.Big `json:"gasUsed" gencodec:"required"`
Time *hexutil.Big `json:"timestamp"` Time *hexutil.Big `json:"timestamp" gencodec:"required"`
Extra hexutil.Bytes `json:"extraData"` Extra hexutil.Bytes `json:"extraData" gencodec:"required"`
MixDigest *common.Hash `json:"mixHash"` MixDigest *common.Hash `json:"mixHash" gencodec:"required"`
Nonce *BlockNonce `json:"nonce"` Nonce *BlockNonce `json:"nonce" gencodec:"required"`
} }
var dec HeaderJSON var dec Header
if err := json.Unmarshal(input, &dec); err != nil { if err := json.Unmarshal(input, &dec); err != nil {
return err return err
} }
var x Header
if dec.ParentHash == nil { if dec.ParentHash == nil {
return errors.New("missing required field 'parentHash' for Header") return errors.New("missing required field 'parentHash' for Header")
} }
x.ParentHash = *dec.ParentHash h.ParentHash = *dec.ParentHash
if dec.UncleHash == nil { if dec.UncleHash == nil {
return errors.New("missing required field 'sha3Uncles' for Header") return errors.New("missing required field 'sha3Uncles' for Header")
} }
x.UncleHash = *dec.UncleHash h.UncleHash = *dec.UncleHash
if dec.Coinbase == nil { if dec.Coinbase == nil {
return errors.New("missing required field 'miner' for Header") return errors.New("missing required field 'miner' for Header")
} }
x.Coinbase = *dec.Coinbase h.Coinbase = *dec.Coinbase
if dec.Root == nil { if dec.Root == nil {
return errors.New("missing required field 'stateRoot' for Header") return errors.New("missing required field 'stateRoot' for Header")
} }
x.Root = *dec.Root h.Root = *dec.Root
if dec.TxHash == nil { if dec.TxHash == nil {
return errors.New("missing required field 'transactionsRoot' for Header") return errors.New("missing required field 'transactionsRoot' for Header")
} }
x.TxHash = *dec.TxHash h.TxHash = *dec.TxHash
if dec.ReceiptHash == nil { if dec.ReceiptHash == nil {
return errors.New("missing required field 'receiptsRoot' for Header") return errors.New("missing required field 'receiptsRoot' for Header")
} }
x.ReceiptHash = *dec.ReceiptHash h.ReceiptHash = *dec.ReceiptHash
if dec.Bloom == nil { if dec.Bloom == nil {
return errors.New("missing required field 'logsBloom' for Header") return errors.New("missing required field 'logsBloom' for Header")
} }
x.Bloom = *dec.Bloom h.Bloom = *dec.Bloom
if dec.Difficulty == nil { if dec.Difficulty == nil {
return errors.New("missing required field 'difficulty' for Header") return errors.New("missing required field 'difficulty' for Header")
} }
x.Difficulty = (*big.Int)(dec.Difficulty) h.Difficulty = (*big.Int)(dec.Difficulty)
if dec.Number == nil { if dec.Number == nil {
return errors.New("missing required field 'number' for Header") return errors.New("missing required field 'number' for Header")
} }
x.Number = (*big.Int)(dec.Number) h.Number = (*big.Int)(dec.Number)
if dec.GasLimit == nil { if dec.GasLimit == nil {
return errors.New("missing required field 'gasLimit' for Header") return errors.New("missing required field 'gasLimit' for Header")
} }
x.GasLimit = (*big.Int)(dec.GasLimit) h.GasLimit = (*big.Int)(dec.GasLimit)
if dec.GasUsed == nil { if dec.GasUsed == nil {
return errors.New("missing required field 'gasUsed' for Header") return errors.New("missing required field 'gasUsed' for Header")
} }
x.GasUsed = (*big.Int)(dec.GasUsed) h.GasUsed = (*big.Int)(dec.GasUsed)
if dec.Time == nil { if dec.Time == nil {
return errors.New("missing required field 'timestamp' for Header") return errors.New("missing required field 'timestamp' for Header")
} }
x.Time = (*big.Int)(dec.Time) h.Time = (*big.Int)(dec.Time)
if dec.Extra == nil { if dec.Extra == nil {
return errors.New("missing required field 'extraData' for Header") return errors.New("missing required field 'extraData' for Header")
} }
x.Extra = dec.Extra h.Extra = dec.Extra
if dec.MixDigest == nil { if dec.MixDigest == nil {
return errors.New("missing required field 'mixHash' for Header") return errors.New("missing required field 'mixHash' for Header")
} }
x.MixDigest = *dec.MixDigest h.MixDigest = *dec.MixDigest
if dec.Nonce == nil { if dec.Nonce == nil {
return errors.New("missing required field 'nonce' for Header") return errors.New("missing required field 'nonce' for Header")
} }
x.Nonce = *dec.Nonce h.Nonce = *dec.Nonce
*h = x
return nil return nil
} }

@ -11,18 +11,18 @@ import (
) )
func (l Log) MarshalJSON() ([]byte, error) { func (l Log) MarshalJSON() ([]byte, error) {
type LogJSON struct { type Log struct {
Address common.Address `json:"address"` Address common.Address `json:"address" gencodec:"required"`
Topics []common.Hash `json:"topics"` Topics []common.Hash `json:"topics" gencodec:"required"`
Data hexutil.Bytes `json:"data"` Data hexutil.Bytes `json:"data" gencodec:"required"`
BlockNumber hexutil.Uint64 `json:"blockNumber" optional:"yes"` BlockNumber hexutil.Uint64 `json:"blockNumber"`
TxHash common.Hash `json:"transactionHash"` TxHash common.Hash `json:"transactionHash" gencodec:"required"`
TxIndex hexutil.Uint `json:"transactionIndex"` TxIndex hexutil.Uint `json:"transactionIndex" gencodec:"required"`
BlockHash common.Hash `json:"blockHash" optional:"yes"` BlockHash common.Hash `json:"blockHash"`
Index hexutil.Uint `json:"logIndex"` Index hexutil.Uint `json:"logIndex" gencodec:"required"`
Removed bool `json:"removed" optional:"yes"` Removed bool `json:"removed"`
} }
var enc LogJSON var enc Log
enc.Address = l.Address enc.Address = l.Address
enc.Topics = l.Topics enc.Topics = l.Topics
enc.Data = l.Data enc.Data = l.Data
@ -36,55 +36,53 @@ func (l Log) MarshalJSON() ([]byte, error) {
} }
func (l *Log) UnmarshalJSON(input []byte) error { func (l *Log) UnmarshalJSON(input []byte) error {
type LogJSON struct { type Log struct {
Address *common.Address `json:"address"` Address *common.Address `json:"address" gencodec:"required"`
Topics []common.Hash `json:"topics"` Topics []common.Hash `json:"topics" gencodec:"required"`
Data hexutil.Bytes `json:"data"` Data hexutil.Bytes `json:"data" gencodec:"required"`
BlockNumber *hexutil.Uint64 `json:"blockNumber" optional:"yes"` BlockNumber *hexutil.Uint64 `json:"blockNumber"`
TxHash *common.Hash `json:"transactionHash"` TxHash *common.Hash `json:"transactionHash" gencodec:"required"`
TxIndex *hexutil.Uint `json:"transactionIndex"` TxIndex *hexutil.Uint `json:"transactionIndex" gencodec:"required"`
BlockHash *common.Hash `json:"blockHash" optional:"yes"` BlockHash *common.Hash `json:"blockHash"`
Index *hexutil.Uint `json:"logIndex"` Index *hexutil.Uint `json:"logIndex" gencodec:"required"`
Removed *bool `json:"removed" optional:"yes"` Removed *bool `json:"removed"`
} }
var dec LogJSON var dec Log
if err := json.Unmarshal(input, &dec); err != nil { if err := json.Unmarshal(input, &dec); err != nil {
return err return err
} }
var x Log
if dec.Address == nil { if dec.Address == nil {
return errors.New("missing required field 'address' for Log") return errors.New("missing required field 'address' for Log")
} }
x.Address = *dec.Address l.Address = *dec.Address
if dec.Topics == nil { if dec.Topics == nil {
return errors.New("missing required field 'topics' for Log") return errors.New("missing required field 'topics' for Log")
} }
x.Topics = dec.Topics l.Topics = dec.Topics
if dec.Data == nil { if dec.Data == nil {
return errors.New("missing required field 'data' for Log") return errors.New("missing required field 'data' for Log")
} }
x.Data = dec.Data l.Data = dec.Data
if dec.BlockNumber != nil { if dec.BlockNumber != nil {
x.BlockNumber = uint64(*dec.BlockNumber) l.BlockNumber = uint64(*dec.BlockNumber)
} }
if dec.TxHash == nil { if dec.TxHash == nil {
return errors.New("missing required field 'transactionHash' for Log") return errors.New("missing required field 'transactionHash' for Log")
} }
x.TxHash = *dec.TxHash l.TxHash = *dec.TxHash
if dec.TxIndex == nil { if dec.TxIndex == nil {
return errors.New("missing required field 'transactionIndex' for Log") return errors.New("missing required field 'transactionIndex' for Log")
} }
x.TxIndex = uint(*dec.TxIndex) l.TxIndex = uint(*dec.TxIndex)
if dec.BlockHash != nil { if dec.BlockHash != nil {
x.BlockHash = *dec.BlockHash l.BlockHash = *dec.BlockHash
} }
if dec.Index == nil { if dec.Index == nil {
return errors.New("missing required field 'logIndex' for Log") return errors.New("missing required field 'logIndex' for Log")
} }
x.Index = uint(*dec.Index) l.Index = uint(*dec.Index)
if dec.Removed != nil { if dec.Removed != nil {
x.Removed = *dec.Removed l.Removed = *dec.Removed
} }
*l = x
return nil return nil
} }

@ -12,16 +12,16 @@ import (
) )
func (r Receipt) MarshalJSON() ([]byte, error) { func (r Receipt) MarshalJSON() ([]byte, error) {
type ReceiptJSON struct { type Receipt struct {
PostState hexutil.Bytes `json:"root"` PostState hexutil.Bytes `json:"root" gencodec:"required"`
CumulativeGasUsed *hexutil.Big `json:"cumulativeGasUsed"` CumulativeGasUsed *hexutil.Big `json:"cumulativeGasUsed" gencodec:"required"`
Bloom Bloom `json:"logsBloom"` Bloom Bloom `json:"logsBloom" gencodec:"required"`
Logs []*Log `json:"logs"` Logs []*Log `json:"logs" gencodec:"required"`
TxHash common.Hash `json:"transactionHash"` TxHash common.Hash `json:"transactionHash" gencodec:"required"`
ContractAddress common.Address `json:"contractAddress" optional:"true"` ContractAddress common.Address `json:"contractAddress"`
GasUsed *hexutil.Big `json:"gasUsed"` GasUsed *hexutil.Big `json:"gasUsed" gencodec:"required"`
} }
var enc ReceiptJSON var enc Receipt
enc.PostState = r.PostState enc.PostState = r.PostState
enc.CumulativeGasUsed = (*hexutil.Big)(r.CumulativeGasUsed) enc.CumulativeGasUsed = (*hexutil.Big)(r.CumulativeGasUsed)
enc.Bloom = r.Bloom enc.Bloom = r.Bloom
@ -33,47 +33,45 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
} }
func (r *Receipt) UnmarshalJSON(input []byte) error { func (r *Receipt) UnmarshalJSON(input []byte) error {
type ReceiptJSON struct { type Receipt struct {
PostState hexutil.Bytes `json:"root"` PostState hexutil.Bytes `json:"root" gencodec:"required"`
CumulativeGasUsed *hexutil.Big `json:"cumulativeGasUsed"` CumulativeGasUsed *hexutil.Big `json:"cumulativeGasUsed" gencodec:"required"`
Bloom *Bloom `json:"logsBloom"` Bloom *Bloom `json:"logsBloom" gencodec:"required"`
Logs []*Log `json:"logs"` Logs []*Log `json:"logs" gencodec:"required"`
TxHash *common.Hash `json:"transactionHash"` TxHash *common.Hash `json:"transactionHash" gencodec:"required"`
ContractAddress *common.Address `json:"contractAddress" optional:"true"` ContractAddress *common.Address `json:"contractAddress"`
GasUsed *hexutil.Big `json:"gasUsed"` GasUsed *hexutil.Big `json:"gasUsed" gencodec:"required"`
} }
var dec ReceiptJSON var dec Receipt
if err := json.Unmarshal(input, &dec); err != nil { if err := json.Unmarshal(input, &dec); err != nil {
return err return err
} }
var x Receipt
if dec.PostState == nil { if dec.PostState == nil {
return errors.New("missing required field 'root' for Receipt") return errors.New("missing required field 'root' for Receipt")
} }
x.PostState = dec.PostState r.PostState = dec.PostState
if dec.CumulativeGasUsed == nil { if dec.CumulativeGasUsed == nil {
return errors.New("missing required field 'cumulativeGasUsed' for Receipt") return errors.New("missing required field 'cumulativeGasUsed' for Receipt")
} }
x.CumulativeGasUsed = (*big.Int)(dec.CumulativeGasUsed) r.CumulativeGasUsed = (*big.Int)(dec.CumulativeGasUsed)
if dec.Bloom == nil { if dec.Bloom == nil {
return errors.New("missing required field 'logsBloom' for Receipt") return errors.New("missing required field 'logsBloom' for Receipt")
} }
x.Bloom = *dec.Bloom r.Bloom = *dec.Bloom
if dec.Logs == nil { if dec.Logs == nil {
return errors.New("missing required field 'logs' for Receipt") return errors.New("missing required field 'logs' for Receipt")
} }
x.Logs = dec.Logs r.Logs = dec.Logs
if dec.TxHash == nil { if dec.TxHash == nil {
return errors.New("missing required field 'transactionHash' for Receipt") return errors.New("missing required field 'transactionHash' for Receipt")
} }
x.TxHash = *dec.TxHash r.TxHash = *dec.TxHash
if dec.ContractAddress != nil { if dec.ContractAddress != nil {
x.ContractAddress = *dec.ContractAddress r.ContractAddress = *dec.ContractAddress
} }
if dec.GasUsed == nil { if dec.GasUsed == nil {
return errors.New("missing required field 'gasUsed' for Receipt") return errors.New("missing required field 'gasUsed' for Receipt")
} }
x.GasUsed = (*big.Int)(dec.GasUsed) r.GasUsed = (*big.Int)(dec.GasUsed)
*r = x
return nil return nil
} }

@ -12,19 +12,19 @@ import (
) )
func (t txdata) MarshalJSON() ([]byte, error) { func (t txdata) MarshalJSON() ([]byte, error) {
type txdataJSON struct { type txdata struct {
AccountNonce hexutil.Uint64 `json:"nonce"` AccountNonce hexutil.Uint64 `json:"nonce" gencodec:"required"`
Price *hexutil.Big `json:"gasPrice"` Price *hexutil.Big `json:"gasPrice" gencodec:"required"`
GasLimit *hexutil.Big `json:"gas"` GasLimit *hexutil.Big `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" optional:"yes" rlp:"nil"` Recipient *common.Address `json:"to" rlp:"nil"`
Amount *hexutil.Big `json:"value"` Amount *hexutil.Big `json:"value" gencodec:"required"`
Payload hexutil.Bytes `json:"input"` Payload hexutil.Bytes `json:"input" gencodec:"required"`
V *hexutil.Big `json:"v"` V *hexutil.Big `json:"v" gencodec:"required"`
R *hexutil.Big `json:"r"` R *hexutil.Big `json:"r" gencodec:"required"`
S *hexutil.Big `json:"s"` S *hexutil.Big `json:"s" gencodec:"required"`
Hash *common.Hash `json:"hash" optional:"yes" rlp:"-"` Hash *common.Hash `json:"hash" rlp:"-"`
} }
var enc txdataJSON var enc txdata
enc.AccountNonce = hexutil.Uint64(t.AccountNonce) enc.AccountNonce = hexutil.Uint64(t.AccountNonce)
enc.Price = (*hexutil.Big)(t.Price) enc.Price = (*hexutil.Big)(t.Price)
enc.GasLimit = (*hexutil.Big)(t.GasLimit) enc.GasLimit = (*hexutil.Big)(t.GasLimit)
@ -39,61 +39,59 @@ func (t txdata) MarshalJSON() ([]byte, error) {
} }
func (t *txdata) UnmarshalJSON(input []byte) error { func (t *txdata) UnmarshalJSON(input []byte) error {
type txdataJSON struct { type txdata struct {
AccountNonce *hexutil.Uint64 `json:"nonce"` AccountNonce *hexutil.Uint64 `json:"nonce" gencodec:"required"`
Price *hexutil.Big `json:"gasPrice"` Price *hexutil.Big `json:"gasPrice" gencodec:"required"`
GasLimit *hexutil.Big `json:"gas"` GasLimit *hexutil.Big `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" optional:"yes" rlp:"nil"` Recipient *common.Address `json:"to" rlp:"nil"`
Amount *hexutil.Big `json:"value"` Amount *hexutil.Big `json:"value" gencodec:"required"`
Payload hexutil.Bytes `json:"input"` Payload hexutil.Bytes `json:"input" gencodec:"required"`
V *hexutil.Big `json:"v"` V *hexutil.Big `json:"v" gencodec:"required"`
R *hexutil.Big `json:"r"` R *hexutil.Big `json:"r" gencodec:"required"`
S *hexutil.Big `json:"s"` S *hexutil.Big `json:"s" gencodec:"required"`
Hash *common.Hash `json:"hash" optional:"yes" rlp:"-"` Hash *common.Hash `json:"hash" rlp:"-"`
} }
var dec txdataJSON var dec txdata
if err := json.Unmarshal(input, &dec); err != nil { if err := json.Unmarshal(input, &dec); err != nil {
return err return err
} }
var x txdata
if dec.AccountNonce == nil { if dec.AccountNonce == nil {
return errors.New("missing required field 'nonce' for txdata") return errors.New("missing required field 'nonce' for txdata")
} }
x.AccountNonce = uint64(*dec.AccountNonce) t.AccountNonce = uint64(*dec.AccountNonce)
if dec.Price == nil { if dec.Price == nil {
return errors.New("missing required field 'gasPrice' for txdata") return errors.New("missing required field 'gasPrice' for txdata")
} }
x.Price = (*big.Int)(dec.Price) t.Price = (*big.Int)(dec.Price)
if dec.GasLimit == nil { if dec.GasLimit == nil {
return errors.New("missing required field 'gas' for txdata") return errors.New("missing required field 'gas' for txdata")
} }
x.GasLimit = (*big.Int)(dec.GasLimit) t.GasLimit = (*big.Int)(dec.GasLimit)
if dec.Recipient != nil { if dec.Recipient != nil {
x.Recipient = dec.Recipient t.Recipient = dec.Recipient
} }
if dec.Amount == nil { if dec.Amount == nil {
return errors.New("missing required field 'value' for txdata") return errors.New("missing required field 'value' for txdata")
} }
x.Amount = (*big.Int)(dec.Amount) t.Amount = (*big.Int)(dec.Amount)
if dec.Payload == nil { if dec.Payload == nil {
return errors.New("missing required field 'input' for txdata") return errors.New("missing required field 'input' for txdata")
} }
x.Payload = dec.Payload t.Payload = dec.Payload
if dec.V == nil { if dec.V == nil {
return errors.New("missing required field 'v' for txdata") return errors.New("missing required field 'v' for txdata")
} }
x.V = (*big.Int)(dec.V) t.V = (*big.Int)(dec.V)
if dec.R == nil { if dec.R == nil {
return errors.New("missing required field 'r' for txdata") return errors.New("missing required field 'r' for txdata")
} }
x.R = (*big.Int)(dec.R) t.R = (*big.Int)(dec.R)
if dec.S == nil { if dec.S == nil {
return errors.New("missing required field 's' for txdata") return errors.New("missing required field 's' for txdata")
} }
x.S = (*big.Int)(dec.S) t.S = (*big.Int)(dec.S)
if dec.Hash != nil { if dec.Hash != nil {
x.Hash = dec.Hash t.Hash = dec.Hash
} }
*t = x
return nil return nil
} }

@ -32,28 +32,28 @@ import (
type Log struct { type Log struct {
// Consensus fields: // Consensus fields:
// address of the contract that generated the event // address of the contract that generated the event
Address common.Address `json:"address"` Address common.Address `json:"address" gencodec:"required"`
// list of topics provided by the contract. // list of topics provided by the contract.
Topics []common.Hash `json:"topics"` Topics []common.Hash `json:"topics" gencodec:"required"`
// supplied by the contract, usually ABI-encoded // supplied by the contract, usually ABI-encoded
Data []byte `json:"data"` Data []byte `json:"data" gencodec:"required"`
// Derived fields. These fields are filled in by the node // Derived fields. These fields are filled in by the node
// but not secured by consensus. // but not secured by consensus.
// block in which the transaction was included // block in which the transaction was included
BlockNumber uint64 `json:"blockNumber" optional:"yes"` BlockNumber uint64 `json:"blockNumber"`
// hash of the transaction // hash of the transaction
TxHash common.Hash `json:"transactionHash"` TxHash common.Hash `json:"transactionHash" gencodec:"required"`
// index of the transaction in the block // index of the transaction in the block
TxIndex uint `json:"transactionIndex"` TxIndex uint `json:"transactionIndex" gencodec:"required"`
// hash of the block in which the transaction was included // hash of the block in which the transaction was included
BlockHash common.Hash `json:"blockHash" optional:"yes"` BlockHash common.Hash `json:"blockHash"`
// index of the log in the receipt // index of the log in the receipt
Index uint `json:"logIndex"` Index uint `json:"logIndex" gencodec:"required"`
// The Removed field is true if this log was reverted due to a chain reorganisation. // The Removed field is true if this log was reverted due to a chain reorganisation.
// You must pay attention to this field if you receive logs through a filter query. // You must pay attention to this field if you receive logs through a filter query.
Removed bool `json:"removed" optional:"yes"` Removed bool `json:"removed"`
} }
type logMarshaling struct { type logMarshaling struct {

@ -31,15 +31,15 @@ import (
// Receipt represents the results of a transaction. // Receipt represents the results of a transaction.
type Receipt struct { type Receipt struct {
// Consensus fields // Consensus fields
PostState []byte `json:"root"` PostState []byte `json:"root" gencodec:"required"`
CumulativeGasUsed *big.Int `json:"cumulativeGasUsed"` CumulativeGasUsed *big.Int `json:"cumulativeGasUsed" gencodec:"required"`
Bloom Bloom `json:"logsBloom"` Bloom Bloom `json:"logsBloom" gencodec:"required"`
Logs []*Log `json:"logs"` Logs []*Log `json:"logs" gencodec:"required"`
// Implementation fields (don't reorder!) // Implementation fields (don't reorder!)
TxHash common.Hash `json:"transactionHash"` TxHash common.Hash `json:"transactionHash" gencodec:"required"`
ContractAddress common.Address `json:"contractAddress" optional:"true"` ContractAddress common.Address `json:"contractAddress"`
GasUsed *big.Int `json:"gasUsed"` GasUsed *big.Int `json:"gasUsed" gencodec:"required"`
} }
type receiptMarshaling struct { type receiptMarshaling struct {

@ -55,20 +55,20 @@ type Transaction struct {
} }
type txdata struct { type txdata struct {
AccountNonce uint64 `json:"nonce"` AccountNonce uint64 `json:"nonce" gencodec:"required"`
Price *big.Int `json:"gasPrice"` Price *big.Int `json:"gasPrice" gencodec:"required"`
GasLimit *big.Int `json:"gas"` GasLimit *big.Int `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" optional:"yes" rlp:"nil"` // nil means contract creation Recipient *common.Address `json:"to" rlp:"nil"` // nil means contract creation
Amount *big.Int `json:"value"` Amount *big.Int `json:"value" gencodec:"required"`
Payload []byte `json:"input"` Payload []byte `json:"input" gencodec:"required"`
// Signature values // Signature values
V *big.Int `json:"v"` V *big.Int `json:"v" gencodec:"required"`
R *big.Int `json:"r"` R *big.Int `json:"r" gencodec:"required"`
S *big.Int `json:"s"` S *big.Int `json:"s" gencodec:"required"`
// This is only used when marshaling to JSON. // This is only used when marshaling to JSON.
Hash *common.Hash `json:"hash" optional:"yes" rlp:"-"` Hash *common.Hash `json:"hash" rlp:"-"`
} }
type txdataMarshaling struct { type txdataMarshaling struct {

Loading…
Cancel
Save