-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathreceipt.go
More file actions
95 lines (88 loc) · 3.28 KB
/
Copy pathreceipt.go
File metadata and controls
95 lines (88 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package models
import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
)
// Receipt struct copies the geth.Receipt type found here:
// https://github.com/ethereum/go-ethereum/blob/9bbb9df18549d6f81c3d1f4fc6c65f71bc92490d/core/types/receipt.go#L52
//
// the reason is if we use geth.Receipt some values will be skipped when RLP encoding which is because
// geth node has the data locally, but we don't in evm gateway, so we can not reproduce those values
// and we need to store them
type Receipt struct {
Type uint8 `json:"type,omitempty"`
PostState []byte `json:"root"`
Status uint64 `json:"status"`
CumulativeGasUsed uint64 `json:"cumulativeGasUsed"`
Bloom gethTypes.Bloom `json:"logsBloom"`
Logs []*gethTypes.Log `json:"logs"`
TxHash common.Hash `json:"transactionHash"`
ContractAddress common.Address `json:"contractAddress"`
GasUsed uint64 `json:"gasUsed"`
EffectiveGasPrice *big.Int `json:"effectiveGasPrice"`
BlobGasUsed uint64 `json:"blobGasUsed,omitempty"`
BlobGasPrice *big.Int `json:"blobGasPrice,omitempty"`
BlockHash common.Hash `json:"blockHash,omitempty"`
BlockNumber *big.Int `json:"blockNumber,omitempty"`
TransactionIndex uint `json:"transactionIndex"`
RevertReason []byte `json:"revertReason"`
PrecompiledCalls []byte
}
func (r *Receipt) ToGethReceipt() *gethTypes.Receipt {
return &gethTypes.Receipt{
Type: r.Type,
PostState: r.PostState,
Status: r.Status,
CumulativeGasUsed: r.CumulativeGasUsed,
Bloom: r.Bloom,
Logs: r.Logs,
TxHash: r.TxHash,
ContractAddress: r.ContractAddress,
GasUsed: r.GasUsed,
EffectiveGasPrice: r.EffectiveGasPrice,
BlobGasUsed: r.BlobGasUsed,
BlobGasPrice: r.BlobGasPrice,
BlockHash: r.BlockHash,
BlockNumber: r.BlockNumber,
TransactionIndex: r.TransactionIndex,
}
}
func NewReceipt(
receipt *gethTypes.Receipt,
revertReason []byte,
precompiledCalls []byte,
) *Receipt {
return &Receipt{
Type: receipt.Type,
PostState: receipt.PostState,
Status: receipt.Status,
CumulativeGasUsed: receipt.CumulativeGasUsed,
Bloom: receipt.Bloom,
Logs: receipt.Logs,
TxHash: receipt.TxHash,
ContractAddress: receipt.ContractAddress,
GasUsed: receipt.GasUsed,
EffectiveGasPrice: receipt.EffectiveGasPrice,
BlobGasUsed: receipt.BlobGasUsed,
BlobGasPrice: receipt.BlobGasPrice,
BlockHash: receipt.BlockHash,
BlockNumber: receipt.BlockNumber,
TransactionIndex: receipt.TransactionIndex,
RevertReason: revertReason,
PrecompiledCalls: precompiledCalls,
}
}
func ReceiptsFromBytes(data []byte) ([]*Receipt, error) {
var receipts []*Receipt
if err := rlp.DecodeBytes(data, &receipts); err != nil {
return nil, fmt.Errorf("failed to RLP-decode block receipts [%x] %w", data, err)
}
return receipts, nil
}
type BloomsHeight struct {
Blooms []*gethTypes.Bloom
Height uint64
}