github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/block/abort_block.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package block 5 6 import ( 7 "time" 8 9 "github.com/MetalBlockchain/metalgo/ids" 10 "github.com/MetalBlockchain/metalgo/snow" 11 "github.com/MetalBlockchain/metalgo/vms/platformvm/txs" 12 ) 13 14 var ( 15 _ BanffBlock = (*BanffAbortBlock)(nil) 16 _ Block = (*ApricotAbortBlock)(nil) 17 ) 18 19 type BanffAbortBlock struct { 20 Time uint64 `serialize:"true" json:"time"` 21 ApricotAbortBlock `serialize:"true"` 22 } 23 24 func (b *BanffAbortBlock) Timestamp() time.Time { 25 return time.Unix(int64(b.Time), 0) 26 } 27 28 func (b *BanffAbortBlock) Visit(v Visitor) error { 29 return v.BanffAbortBlock(b) 30 } 31 32 func NewBanffAbortBlock( 33 timestamp time.Time, 34 parentID ids.ID, 35 height uint64, 36 ) (*BanffAbortBlock, error) { 37 blk := &BanffAbortBlock{ 38 Time: uint64(timestamp.Unix()), 39 ApricotAbortBlock: ApricotAbortBlock{ 40 CommonBlock: CommonBlock{ 41 PrntID: parentID, 42 Hght: height, 43 }, 44 }, 45 } 46 return blk, initialize(blk, &blk.CommonBlock) 47 } 48 49 type ApricotAbortBlock struct { 50 CommonBlock `serialize:"true"` 51 } 52 53 func (b *ApricotAbortBlock) initialize(bytes []byte) error { 54 b.CommonBlock.initialize(bytes) 55 return nil 56 } 57 58 func (*ApricotAbortBlock) InitCtx(*snow.Context) {} 59 60 func (*ApricotAbortBlock) Txs() []*txs.Tx { 61 return nil 62 } 63 64 func (b *ApricotAbortBlock) Visit(v Visitor) error { 65 return v.ApricotAbortBlock(b) 66 } 67 68 // NewApricotAbortBlock is kept for testing purposes only. 69 // Following Banff activation and subsequent code cleanup, Apricot Abort blocks 70 // should be only verified (upon bootstrap), never created anymore 71 func NewApricotAbortBlock( 72 parentID ids.ID, 73 height uint64, 74 ) (*ApricotAbortBlock, error) { 75 blk := &ApricotAbortBlock{ 76 CommonBlock: CommonBlock{ 77 PrntID: parentID, 78 Hght: height, 79 }, 80 } 81 return blk, initialize(blk, &blk.CommonBlock) 82 }