|
|
@ -30,15 +30,23 @@ import ( |
|
|
|
//go:generate gencodec -type Receipt -field-override receiptMarshaling -out gen_receipt_json.go
|
|
|
|
//go:generate gencodec -type Receipt -field-override receiptMarshaling -out gen_receipt_json.go
|
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
receiptStatusFailed = []byte{} |
|
|
|
receiptStatusFailedRLP = []byte{} |
|
|
|
receiptStatusSuccessful = []byte{0x01} |
|
|
|
receiptStatusSuccessfulRLP = []byte{0x01} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
|
|
// ReceiptStatusFailed is the status code of a transaction if execution failed.
|
|
|
|
|
|
|
|
ReceiptStatusFailed = uint(0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ReceiptStatusSuccessful is the status code of a transaction if execution succeeded.
|
|
|
|
|
|
|
|
ReceiptStatusSuccessful = uint(1) |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// 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"` |
|
|
|
Failed bool `json:"failed"` |
|
|
|
Status uint `json:"status"` |
|
|
|
CumulativeGasUsed *big.Int `json:"cumulativeGasUsed" gencodec:"required"` |
|
|
|
CumulativeGasUsed *big.Int `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"` |
|
|
@ -51,6 +59,7 @@ type Receipt struct { |
|
|
|
|
|
|
|
|
|
|
|
type receiptMarshaling struct { |
|
|
|
type receiptMarshaling struct { |
|
|
|
PostState hexutil.Bytes |
|
|
|
PostState hexutil.Bytes |
|
|
|
|
|
|
|
Status hexutil.Uint |
|
|
|
CumulativeGasUsed *hexutil.Big |
|
|
|
CumulativeGasUsed *hexutil.Big |
|
|
|
GasUsed *hexutil.Big |
|
|
|
GasUsed *hexutil.Big |
|
|
|
} |
|
|
|
} |
|
|
@ -75,7 +84,13 @@ type receiptStorageRLP struct { |
|
|
|
|
|
|
|
|
|
|
|
// NewReceipt creates a barebone transaction receipt, copying the init fields.
|
|
|
|
// NewReceipt creates a barebone transaction receipt, copying the init fields.
|
|
|
|
func NewReceipt(root []byte, failed bool, cumulativeGasUsed *big.Int) *Receipt { |
|
|
|
func NewReceipt(root []byte, failed bool, cumulativeGasUsed *big.Int) *Receipt { |
|
|
|
return &Receipt{PostState: common.CopyBytes(root), Failed: failed, CumulativeGasUsed: new(big.Int).Set(cumulativeGasUsed)} |
|
|
|
r := &Receipt{PostState: common.CopyBytes(root), CumulativeGasUsed: new(big.Int).Set(cumulativeGasUsed)} |
|
|
|
|
|
|
|
if failed { |
|
|
|
|
|
|
|
r.Status = ReceiptStatusFailed |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
r.Status = ReceiptStatusSuccessful |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return r |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt
|
|
|
|
// EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt
|
|
|
@ -100,10 +115,10 @@ func (r *Receipt) DecodeRLP(s *rlp.Stream) error { |
|
|
|
|
|
|
|
|
|
|
|
func (r *Receipt) setStatus(postStateOrStatus []byte) error { |
|
|
|
func (r *Receipt) setStatus(postStateOrStatus []byte) error { |
|
|
|
switch { |
|
|
|
switch { |
|
|
|
case bytes.Equal(postStateOrStatus, receiptStatusSuccessful): |
|
|
|
case bytes.Equal(postStateOrStatus, receiptStatusSuccessfulRLP): |
|
|
|
r.Failed = false |
|
|
|
r.Status = ReceiptStatusSuccessful |
|
|
|
case bytes.Equal(postStateOrStatus, receiptStatusFailed): |
|
|
|
case bytes.Equal(postStateOrStatus, receiptStatusFailedRLP): |
|
|
|
r.Failed = true |
|
|
|
r.Status = ReceiptStatusFailed |
|
|
|
case len(postStateOrStatus) == len(common.Hash{}): |
|
|
|
case len(postStateOrStatus) == len(common.Hash{}): |
|
|
|
r.PostState = postStateOrStatus |
|
|
|
r.PostState = postStateOrStatus |
|
|
|
default: |
|
|
|
default: |
|
|
@ -114,19 +129,18 @@ func (r *Receipt) setStatus(postStateOrStatus []byte) error { |
|
|
|
|
|
|
|
|
|
|
|
func (r *Receipt) statusEncoding() []byte { |
|
|
|
func (r *Receipt) statusEncoding() []byte { |
|
|
|
if len(r.PostState) == 0 { |
|
|
|
if len(r.PostState) == 0 { |
|
|
|
if r.Failed { |
|
|
|
if r.Status == ReceiptStatusFailed { |
|
|
|
return receiptStatusFailed |
|
|
|
return receiptStatusFailedRLP |
|
|
|
} else { |
|
|
|
|
|
|
|
return receiptStatusSuccessful |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return receiptStatusSuccessfulRLP |
|
|
|
} |
|
|
|
} |
|
|
|
return r.PostState |
|
|
|
return r.PostState |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// String implements the Stringer interface.
|
|
|
|
// String implements the Stringer interface.
|
|
|
|
func (r *Receipt) String() string { |
|
|
|
func (r *Receipt) String() string { |
|
|
|
if r.PostState == nil { |
|
|
|
if len(r.PostState) == 0 { |
|
|
|
return fmt.Sprintf("receipt{failed=%t cgas=%v bloom=%x logs=%v}", r.Failed, r.CumulativeGasUsed, r.Bloom, r.Logs) |
|
|
|
return fmt.Sprintf("receipt{status=%d cgas=%v bloom=%x logs=%v}", r.Status, r.CumulativeGasUsed, r.Bloom, r.Logs) |
|
|
|
} |
|
|
|
} |
|
|
|
return fmt.Sprintf("receipt{med=%x cgas=%v bloom=%x logs=%v}", r.PostState, r.CumulativeGasUsed, r.Bloom, r.Logs) |
|
|
|
return fmt.Sprintf("receipt{med=%x cgas=%v bloom=%x logs=%v}", r.PostState, r.CumulativeGasUsed, r.Bloom, r.Logs) |
|
|
|
} |
|
|
|
} |
|
|
|