github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/block/commit_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 = (*BanffCommitBlock)(nil) 16 _ Block = (*ApricotCommitBlock)(nil) 17 ) 18 19 type BanffCommitBlock struct { 20 Time uint64 `serialize:"true" json:"time"` 21 ApricotCommitBlock `serialize:"true"` 22 } 23 24 func (b *BanffCommitBlock) Timestamp() time.Time { 25 return time.Unix(int64(b.Time), 0) 26 } 27 28 func (b *BanffCommitBlock) Visit(v Visitor) error { 29 return v.BanffCommitBlock(b) 30 } 31 32 func NewBanffCommitBlock( 33 timestamp time.Time, 34 parentID ids.ID, 35 height uint64, 36 ) (*BanffCommitBlock, error) { 37 blk := &BanffCommitBlock{ 38 Time: uint64(timestamp.Unix()), 39 ApricotCommitBlock: ApricotCommitBlock{ 40 CommonBlock: CommonBlock{ 41 PrntID: parentID, 42 Hght: height, 43 }, 44 }, 45 } 46 return blk, initialize(blk, &blk.CommonBlock) 47 } 48 49 type ApricotCommitBlock struct { 50 CommonBlock `serialize:"true"` 51 } 52 53 func (b *ApricotCommitBlock) initialize(bytes []byte) error { 54 b.CommonBlock.initialize(bytes) 55 return nil 56 } 57 58 func (*ApricotCommitBlock) InitCtx(*snow.Context) {} 59 60 func (*ApricotCommitBlock) Txs() []*txs.Tx { 61 return nil 62 } 63 64 func (b *ApricotCommitBlock) Visit(v Visitor) error { 65 return v.ApricotCommitBlock(b) 66 } 67 68 func NewApricotCommitBlock( 69 parentID ids.ID, 70 height uint64, 71 ) (*ApricotCommitBlock, error) { 72 blk := &ApricotCommitBlock{ 73 CommonBlock: CommonBlock{ 74 PrntID: parentID, 75 Hght: height, 76 }, 77 } 78 return blk, initialize(blk, &blk.CommonBlock) 79 }