@@ -30,15 +30,23 @@ import (
30
30
//go:generate gencodec -type Receipt -field-override receiptMarshaling -out gen_receipt_json.go
31
31
32
32
var (
33
- receiptStatusFailed = []byte {}
34
- receiptStatusSuccessful = []byte {0x01 }
33
+ receiptStatusFailedRLP = []byte {}
34
+ receiptStatusSuccessfulRLP = []byte {0x01 }
35
+ )
36
+
37
+ const (
38
+ // ReceiptStatusFailed is the status code of a transaction if execution failed.
39
+ ReceiptStatusFailed = uint (0 )
40
+
41
+ // ReceiptStatusSuccessful is the status code of a transaction if execution succeeded.
42
+ ReceiptStatusSuccessful = uint (1 )
35
43
)
36
44
37
45
// Receipt represents the results of a transaction.
38
46
type Receipt struct {
39
47
// Consensus fields
40
48
PostState []byte `json:"root"`
41
- Failed bool `json:"failed "`
49
+ Status uint `json:"status "`
42
50
CumulativeGasUsed * big.Int `json:"cumulativeGasUsed" gencodec:"required"`
43
51
Bloom Bloom `json:"logsBloom" gencodec:"required"`
44
52
Logs []* Log `json:"logs" gencodec:"required"`
@@ -51,6 +59,7 @@ type Receipt struct {
51
59
52
60
type receiptMarshaling struct {
53
61
PostState hexutil.Bytes
62
+ Status hexutil.Uint
54
63
CumulativeGasUsed * hexutil.Big
55
64
GasUsed * hexutil.Big
56
65
}
@@ -75,7 +84,13 @@ type receiptStorageRLP struct {
75
84
76
85
// NewReceipt creates a barebone transaction receipt, copying the init fields.
77
86
func NewReceipt (root []byte , failed bool , cumulativeGasUsed * big.Int ) * Receipt {
78
- return & Receipt {PostState : common .CopyBytes (root ), Failed : failed , CumulativeGasUsed : new (big.Int ).Set (cumulativeGasUsed )}
87
+ r := & Receipt {PostState : common .CopyBytes (root ), CumulativeGasUsed : new (big.Int ).Set (cumulativeGasUsed )}
88
+ if failed {
89
+ r .Status = ReceiptStatusFailed
90
+ } else {
91
+ r .Status = ReceiptStatusSuccessful
92
+ }
93
+ return r
79
94
}
80
95
81
96
// EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt
@@ -100,10 +115,10 @@ func (r *Receipt) DecodeRLP(s *rlp.Stream) error {
100
115
101
116
func (r * Receipt ) setStatus (postStateOrStatus []byte ) error {
102
117
switch {
103
- case bytes .Equal (postStateOrStatus , receiptStatusSuccessful ):
104
- r .Failed = false
105
- case bytes .Equal (postStateOrStatus , receiptStatusFailed ):
106
- r .Failed = true
118
+ case bytes .Equal (postStateOrStatus , receiptStatusSuccessfulRLP ):
119
+ r .Status = ReceiptStatusSuccessful
120
+ case bytes .Equal (postStateOrStatus , receiptStatusFailedRLP ):
121
+ r .Status = ReceiptStatusFailed
107
122
case len (postStateOrStatus ) == len (common.Hash {}):
108
123
r .PostState = postStateOrStatus
109
124
default :
@@ -114,19 +129,18 @@ func (r *Receipt) setStatus(postStateOrStatus []byte) error {
114
129
115
130
func (r * Receipt ) statusEncoding () []byte {
116
131
if len (r .PostState ) == 0 {
117
- if r .Failed {
118
- return receiptStatusFailed
119
- } else {
120
- return receiptStatusSuccessful
132
+ if r .Status == ReceiptStatusFailed {
133
+ return receiptStatusFailedRLP
121
134
}
135
+ return receiptStatusSuccessfulRLP
122
136
}
123
137
return r .PostState
124
138
}
125
139
126
140
// String implements the Stringer interface.
127
141
func (r * Receipt ) String () string {
128
- if r .PostState == nil {
129
- return fmt .Sprintf ("receipt{failed=%t cgas=%v bloom=%x logs=%v}" , r .Failed , r .CumulativeGasUsed , r .Bloom , r .Logs )
142
+ if len ( r .PostState ) == 0 {
143
+ return fmt .Sprintf ("receipt{status=%d cgas=%v bloom=%x logs=%v}" , r .Status , r .CumulativeGasUsed , r .Bloom , r .Logs )
130
144
}
131
145
return fmt .Sprintf ("receipt{med=%x cgas=%v bloom=%x logs=%v}" , r .PostState , r .CumulativeGasUsed , r .Bloom , r .Logs )
132
146
}
0 commit comments