github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/block/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 "fmt" 8 "time" 9 10 "github.com/MetalBlockchain/metalgo/ids" 11 "github.com/MetalBlockchain/metalgo/snow" 12 "github.com/MetalBlockchain/metalgo/vms/platformvm/txs" 13 ) 14 15 // Block defines the common stateless interface for all blocks 16 type Block interface { 17 snow.ContextInitializable 18 ID() ids.ID 19 Parent() ids.ID 20 Bytes() []byte 21 Height() uint64 22 23 // Txs returns list of transactions contained in the block 24 Txs() []*txs.Tx 25 26 // Visit calls [visitor] with this block's concrete type 27 Visit(visitor Visitor) error 28 29 // note: initialize does not assume that block transactions 30 // are initialized, and initializes them itself if they aren't. 31 initialize(bytes []byte) error 32 } 33 34 type BanffBlock interface { 35 Block 36 Timestamp() time.Time 37 } 38 39 func initialize(blk Block, commonBlk *CommonBlock) error { 40 // We serialize this block as a pointer so that it can be deserialized into 41 // a Block 42 bytes, err := Codec.Marshal(CodecVersion, &blk) 43 if err != nil { 44 return fmt.Errorf("couldn't marshal block: %w", err) 45 } 46 47 commonBlk.initialize(bytes) 48 return nil 49 }