core/types: add a reverted field in receipt

This commit is contained in:
rjl493456442 2017-06-15 21:46:57 +08:00
parent fade09a7ff
commit d14dceb396
3 changed files with 19 additions and 2 deletions

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View file

@ -20,6 +20,7 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
ContractAddress common.Address `json:"contractAddress"`
GasUsed *hexutil.Big `json:"gasUsed" gencodec:"required"`
Reverted bool `json:"reverted" gencode:"required"`
}
var enc Receipt
enc.PostState = r.PostState
@ -29,6 +30,7 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
enc.TxHash = r.TxHash
enc.ContractAddress = r.ContractAddress
enc.GasUsed = (*hexutil.Big)(r.GasUsed)
enc.Reverted = r.Reverted
return json.Marshal(&enc)
}
@ -41,6 +43,7 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
TxHash *common.Hash `json:"transactionHash" gencodec:"required"`
ContractAddress *common.Address `json:"contractAddress"`
GasUsed *hexutil.Big `json:"gasUsed" gencodec:"required"`
Reverted *bool `json:"reverted" gencode:"required"`
}
var dec Receipt
if err := json.Unmarshal(input, &dec); err != nil {
@ -73,5 +76,8 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
return errors.New("missing required field 'gasUsed' for Receipt")
}
r.GasUsed = (*big.Int)(dec.GasUsed)
if dec.Reverted != nil {
r.Reverted = *dec.Reverted
}
return nil
}

View file

@ -40,6 +40,10 @@ type Receipt struct {
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
ContractAddress common.Address `json:"contractAddress"`
GasUsed *big.Int `json:"gasUsed" gencodec:"required"`
// The Reverted field is true if transaction is reverted during state transition,
// As the transaction revert will cause all the remaining gas to be consumed,
// This field could help to gas estimation.
Reverted bool `json:"reverted" gencode:"required"`
}
type receiptMarshaling struct {
@ -91,7 +95,7 @@ func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error {
for i, log := range r.Logs {
logs[i] = (*LogForStorage)(log)
}
return rlp.Encode(w, []interface{}{r.PostState, r.CumulativeGasUsed, r.Bloom, r.TxHash, r.ContractAddress, logs, r.GasUsed})
return rlp.Encode(w, []interface{}{r.PostState, r.CumulativeGasUsed, r.Bloom, r.TxHash, r.ContractAddress, logs, r.GasUsed, r.Reverted})
}
// DecodeRLP implements rlp.Decoder, and loads both consensus and implementation
@ -105,6 +109,7 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error {
ContractAddress common.Address
Logs []*LogForStorage
GasUsed *big.Int
Reverted bool
}
if err := s.Decode(&receipt); err != nil {
return err
@ -116,7 +121,7 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error {
r.Logs[i] = (*Log)(log)
}
// Assign the implementation fields
r.TxHash, r.ContractAddress, r.GasUsed = receipt.TxHash, receipt.ContractAddress, receipt.GasUsed
r.TxHash, r.ContractAddress, r.GasUsed, r.Reverted = receipt.TxHash, receipt.ContractAddress, receipt.GasUsed, receipt.Reverted
return nil
}