-
Notifications
You must be signed in to change notification settings - Fork 130
/
block_ext.go
67 lines (56 loc) · 1.33 KB
/
block_ext.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
// (c) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package types
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
)
func (b *Block) WithExtData(version uint32, extdata *[]byte) *Block {
b.version = version
b.setExtDataHelper(extdata, false)
return b
}
func (b *Block) setExtDataHelper(data *[]byte, recalc bool) {
if data == nil {
b.setExtData(nil, recalc)
return
}
b.setExtData(*data, recalc)
}
func (b *Block) setExtData(data []byte, recalc bool) {
_data := make([]byte, len(data))
b.extdata = &_data
copy(*b.extdata, data)
if recalc {
b.header.ExtDataHash = CalcExtDataHash(*b.extdata)
}
}
func (b *Block) ExtData() []byte {
if b.extdata == nil {
return nil
}
return *b.extdata
}
func (b *Block) Version() uint32 {
return b.version
}
func (b *Block) ExtDataGasUsed() *big.Int {
if b.header.ExtDataGasUsed == nil {
return nil
}
return new(big.Int).Set(b.header.ExtDataGasUsed)
}
func CalcExtDataHash(extdata []byte) common.Hash {
if len(extdata) == 0 {
return EmptyExtDataHash
}
return rlpHash(extdata)
}
func NewBlockWithExtData(
header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt,
hasher TrieHasher, extdata []byte, recalc bool,
) *Block {
b := NewBlock(header, txs, uncles, receipts, hasher)
b.setExtData(extdata, recalc)
return b
}