|
|
|
@ -5,6 +5,7 @@ package types |
|
|
|
|
import ( |
|
|
|
|
"encoding/json" |
|
|
|
|
"errors" |
|
|
|
|
"math/big" |
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil" |
|
|
|
@ -23,6 +24,9 @@ func (r Receipt) MarshalJSON() ([]byte, error) { |
|
|
|
|
TxHash common.Hash `json:"transactionHash" gencodec:"required"` |
|
|
|
|
ContractAddress common.Address `json:"contractAddress"` |
|
|
|
|
GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"` |
|
|
|
|
BlockHash common.Hash `json:"blockHash,omitempty"` |
|
|
|
|
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"` |
|
|
|
|
TransactionIndex hexutil.Uint `json:"transactionIndex"` |
|
|
|
|
} |
|
|
|
|
var enc Receipt |
|
|
|
|
enc.PostState = r.PostState |
|
|
|
@ -33,6 +37,9 @@ func (r Receipt) MarshalJSON() ([]byte, error) { |
|
|
|
|
enc.TxHash = r.TxHash |
|
|
|
|
enc.ContractAddress = r.ContractAddress |
|
|
|
|
enc.GasUsed = hexutil.Uint64(r.GasUsed) |
|
|
|
|
enc.BlockHash = r.BlockHash |
|
|
|
|
enc.BlockNumber = (*hexutil.Big)(r.BlockNumber) |
|
|
|
|
enc.TransactionIndex = hexutil.Uint(r.TransactionIndex) |
|
|
|
|
return json.Marshal(&enc) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -47,6 +54,9 @@ func (r *Receipt) UnmarshalJSON(input []byte) error { |
|
|
|
|
TxHash *common.Hash `json:"transactionHash" gencodec:"required"` |
|
|
|
|
ContractAddress *common.Address `json:"contractAddress"` |
|
|
|
|
GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"` |
|
|
|
|
BlockHash *common.Hash `json:"blockHash,omitempty"` |
|
|
|
|
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"` |
|
|
|
|
TransactionIndex *hexutil.Uint `json:"transactionIndex"` |
|
|
|
|
} |
|
|
|
|
var dec Receipt |
|
|
|
|
if err := json.Unmarshal(input, &dec); err != nil { |
|
|
|
@ -81,5 +91,14 @@ func (r *Receipt) UnmarshalJSON(input []byte) error { |
|
|
|
|
return errors.New("missing required field 'gasUsed' for Receipt") |
|
|
|
|
} |
|
|
|
|
r.GasUsed = uint64(*dec.GasUsed) |
|
|
|
|
if dec.BlockHash != nil { |
|
|
|
|
r.BlockHash = *dec.BlockHash |
|
|
|
|
} |
|
|
|
|
if dec.BlockNumber != nil { |
|
|
|
|
r.BlockNumber = (*big.Int)(dec.BlockNumber) |
|
|
|
|
} |
|
|
|
|
if dec.TransactionIndex != nil { |
|
|
|
|
r.TransactionIndex = uint(*dec.TransactionIndex) |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|