-
Notifications
You must be signed in to change notification settings - Fork 2
/
bodyv0.go
121 lines (103 loc) · 3.54 KB
/
bodyv0.go
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package types
import (
"io"
"github.com/ethereum/go-ethereum/rlp"
"github.com/PositionExchange/posichain/block"
"github.com/PositionExchange/posichain/internal/utils"
staking "github.com/PositionExchange/posichain/staking/types"
)
// BodyV0 is the V0 block body
type BodyV0 struct {
f bodyFieldsV0
}
type bodyFieldsV0 struct {
Transactions []*Transaction
Uncles []*block.Header
}
// Transactions returns the list of transactions.
//
// The returned list is a deep copy; the caller may do anything with it without
// affecting the original.
func (b *BodyV0) Transactions() (txs []*Transaction) {
for _, tx := range b.f.Transactions {
txs = append(txs, tx.Copy())
}
return txs
}
// TransactionAt returns the transaction at the given index in this block.
// It returns nil if index is out of bounds.
func (b *BodyV0) TransactionAt(index int) *Transaction {
if index < 0 || index >= len(b.f.Transactions) {
return nil
}
return b.f.Transactions[index].Copy()
}
// StakingTransactionAt returns the staking transaction at the given index in this block.
// It returns nil if index is out of bounds. (not supported by Body V0)
func (b *BodyV0) StakingTransactionAt(index int) *staking.StakingTransaction {
// not supported
return nil
}
// CXReceiptAt returns the CXReceipt at given index in this block
// It returns nil if index is out of bounds
// V0 will just return nil because we don't support CXReceipt
func (b *BodyV0) CXReceiptAt(index int) *CXReceipt {
return nil
}
// SetTransactions sets the list of transactions with a deep copy of the given
// list.
func (b *BodyV0) SetTransactions(newTransactions []*Transaction) {
var txs []*Transaction
for _, tx := range newTransactions {
txs = append(txs, tx.Copy())
}
b.f.Transactions = txs
}
// SetStakingTransactions sets the list of staking transactions with a deep copy of the given
// list. (not supported by Body V0)
func (b *BodyV0) SetStakingTransactions(newTransactions []*staking.StakingTransaction) {
// not supported
}
// Uncles returns a deep copy of the list of uncle headers of this block.
func (b *BodyV0) Uncles() (uncles []*block.Header) {
for _, uncle := range b.f.Uncles {
uncles = append(uncles, CopyHeader(uncle))
}
return uncles
}
// SetUncles sets the list of uncle headers with a deep copy of the given list.
func (b *BodyV0) SetUncles(newUncle []*block.Header) {
var uncles []*block.Header
for _, uncle := range newUncle {
uncles = append(uncles, CopyHeader(uncle))
}
b.f.Uncles = uncles
}
// IncomingReceipts returns a deep copy of the list of incoming cross-shard
// transaction receipts of this block.
func (b *BodyV0) IncomingReceipts() (incomingReceipts CXReceiptsProofs) {
return nil
}
// StakingTransactions returns the list of staking transactions.
// The returned list is a deep copy; the caller may do anything with it without
// affecting the original.
func (b *BodyV0) StakingTransactions() (txs []*staking.StakingTransaction) {
return nil
}
// SetIncomingReceipts sets the list of incoming cross-shard transaction
// receipts of this block with a dep copy of the given list.
func (b *BodyV0) SetIncomingReceipts(newIncomingReceipts CXReceiptsProofs) {
if len(newIncomingReceipts) > 0 {
utils.Logger().Warn().
Msg("cannot store incoming CX receipts in v0 block body")
}
}
// EncodeRLP RLP-encodes the block body into the given writer.
func (b *BodyV0) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, &b.f)
}
// DecodeRLP RLP-decodes a block body from the given RLP stream into the
// receiver.
func (b *BodyV0) DecodeRLP(s *rlp.Stream) error {
return s.Decode(&b.f)
}