This commit is contained in:
Diep Pham 2018-06-11 07:41:35 +00:00 committed by GitHub
commit 1788a611ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -20,6 +20,7 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
CumulativeGasUsed hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"` CumulativeGasUsed hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"`
Bloom Bloom `json:"logsBloom" gencodec:"required"` Bloom Bloom `json:"logsBloom" gencodec:"required"`
Logs []*Log `json:"logs" gencodec:"required"` Logs []*Log `json:"logs" gencodec:"required"`
BlockNumber hexutil.Uint64 `json:"blockNumber" gencodec:"required"`
TxHash common.Hash `json:"transactionHash" gencodec:"required"` TxHash common.Hash `json:"transactionHash" gencodec:"required"`
ContractAddress common.Address `json:"contractAddress"` ContractAddress common.Address `json:"contractAddress"`
GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"` GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
@ -30,6 +31,7 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
enc.CumulativeGasUsed = hexutil.Uint64(r.CumulativeGasUsed) enc.CumulativeGasUsed = hexutil.Uint64(r.CumulativeGasUsed)
enc.Bloom = r.Bloom enc.Bloom = r.Bloom
enc.Logs = r.Logs enc.Logs = r.Logs
enc.BlockNumber = hexutil.Uint64(r.BlockNumber)
enc.TxHash = r.TxHash enc.TxHash = r.TxHash
enc.ContractAddress = r.ContractAddress enc.ContractAddress = r.ContractAddress
enc.GasUsed = hexutil.Uint64(r.GasUsed) enc.GasUsed = hexutil.Uint64(r.GasUsed)
@ -44,6 +46,7 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
CumulativeGasUsed *hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"` CumulativeGasUsed *hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"`
Bloom *Bloom `json:"logsBloom" gencodec:"required"` Bloom *Bloom `json:"logsBloom" gencodec:"required"`
Logs []*Log `json:"logs" gencodec:"required"` Logs []*Log `json:"logs" gencodec:"required"`
BlockNumber *hexutil.Uint64 `json:"blockNumber" gencodec:"required"`
TxHash *common.Hash `json:"transactionHash" gencodec:"required"` TxHash *common.Hash `json:"transactionHash" gencodec:"required"`
ContractAddress *common.Address `json:"contractAddress"` ContractAddress *common.Address `json:"contractAddress"`
GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"` GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
@ -70,6 +73,10 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
return errors.New("missing required field 'logs' for Receipt") return errors.New("missing required field 'logs' for Receipt")
} }
r.Logs = dec.Logs r.Logs = dec.Logs
if dec.BlockNumber == nil {
return errors.New("missing required field 'blockNumber' for Receipt")
}
r.BlockNumber = uint64(*dec.BlockNumber)
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")
} }

View file

@ -50,6 +50,7 @@ type Receipt struct {
CumulativeGasUsed uint64 `json:"cumulativeGasUsed" gencodec:"required"` CumulativeGasUsed uint64 `json:"cumulativeGasUsed" gencodec:"required"`
Bloom Bloom `json:"logsBloom" gencodec:"required"` Bloom Bloom `json:"logsBloom" gencodec:"required"`
Logs []*Log `json:"logs" gencodec:"required"` Logs []*Log `json:"logs" gencodec:"required"`
BlockNumber uint64 `json:"blockNumber" gencodec:"required"`
// Implementation fields (don't reorder!) // Implementation fields (don't reorder!)
TxHash common.Hash `json:"transactionHash" gencodec:"required"` TxHash common.Hash `json:"transactionHash" gencodec:"required"`
@ -61,6 +62,7 @@ type receiptMarshaling struct {
PostState hexutil.Bytes PostState hexutil.Bytes
Status hexutil.Uint64 Status hexutil.Uint64
CumulativeGasUsed hexutil.Uint64 CumulativeGasUsed hexutil.Uint64
BlockNumber hexutil.Uint64
GasUsed hexutil.Uint64 GasUsed hexutil.Uint64
} }
@ -70,6 +72,7 @@ type receiptRLP struct {
CumulativeGasUsed uint64 CumulativeGasUsed uint64
Bloom Bloom Bloom Bloom
Logs []*Log Logs []*Log
BlockNumber uint64
} }
type receiptStorageRLP struct { type receiptStorageRLP struct {
@ -79,6 +82,7 @@ type receiptStorageRLP struct {
TxHash common.Hash TxHash common.Hash
ContractAddress common.Address ContractAddress common.Address
Logs []*LogForStorage Logs []*LogForStorage
BlockNumber uint64
GasUsed uint64 GasUsed uint64
} }
@ -96,7 +100,7 @@ func NewReceipt(root []byte, failed bool, cumulativeGasUsed uint64) *Receipt {
// EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt // EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt
// into an RLP stream. If no post state is present, byzantium fork is assumed. // into an RLP stream. If no post state is present, byzantium fork is assumed.
func (r *Receipt) EncodeRLP(w io.Writer) error { func (r *Receipt) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs}) return rlp.Encode(w, &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs, r.BlockNumber})
} }
// DecodeRLP implements rlp.Decoder, and loads the consensus fields of a receipt // DecodeRLP implements rlp.Decoder, and loads the consensus fields of a receipt