forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
abort_block.go
82 lines (68 loc) · 1.77 KB
/
abort_block.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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package blocks
import (
"time"
"github.com/MetalBlockchain/metalgo/ids"
"github.com/MetalBlockchain/metalgo/snow"
"github.com/MetalBlockchain/metalgo/vms/platformvm/txs"
)
var (
_ BanffBlock = (*BanffAbortBlock)(nil)
_ Block = (*ApricotAbortBlock)(nil)
)
type BanffAbortBlock struct {
Time uint64 `serialize:"true" json:"time"`
ApricotAbortBlock `serialize:"true"`
}
func (b *BanffAbortBlock) Timestamp() time.Time {
return time.Unix(int64(b.Time), 0)
}
func (b *BanffAbortBlock) Visit(v Visitor) error {
return v.BanffAbortBlock(b)
}
func NewBanffAbortBlock(
timestamp time.Time,
parentID ids.ID,
height uint64,
) (*BanffAbortBlock, error) {
blk := &BanffAbortBlock{
Time: uint64(timestamp.Unix()),
ApricotAbortBlock: ApricotAbortBlock{
CommonBlock: CommonBlock{
PrntID: parentID,
Hght: height,
},
},
}
return blk, initialize(blk)
}
type ApricotAbortBlock struct {
CommonBlock `serialize:"true"`
}
func (b *ApricotAbortBlock) initialize(bytes []byte) error {
b.CommonBlock.initialize(bytes)
return nil
}
func (*ApricotAbortBlock) InitCtx(*snow.Context) {}
func (*ApricotAbortBlock) Txs() []*txs.Tx {
return nil
}
func (b *ApricotAbortBlock) Visit(v Visitor) error {
return v.ApricotAbortBlock(b)
}
// NewApricotAbortBlock is kept for testing purposes only.
// Following Banff activation and subsequent code cleanup, Apricot Abort blocks
// should be only verified (upon bootstrap), never created anymore
func NewApricotAbortBlock(
parentID ids.ID,
height uint64,
) (*ApricotAbortBlock, error) {
blk := &ApricotAbortBlock{
CommonBlock: CommonBlock{
PrntID: parentID,
Hght: height,
},
}
return blk, initialize(blk)
}