forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
block.go
47 lines (38 loc) · 1.11 KB
/
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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package blocks
import (
"fmt"
"time"
"github.com/MetalBlockchain/metalgo/ids"
"github.com/MetalBlockchain/metalgo/snow"
"github.com/MetalBlockchain/metalgo/vms/platformvm/txs"
)
// Block defines the common stateless interface for all blocks
type Block interface {
snow.ContextInitializable
ID() ids.ID
Parent() ids.ID
Bytes() []byte
Height() uint64
// Txs returns list of transactions contained in the block
Txs() []*txs.Tx
// Visit calls [visitor] with this block's concrete type
Visit(visitor Visitor) error
// note: initialize does not assume that block transactions
// are initialized, and initializes them itself if they aren't.
initialize(bytes []byte) error
}
type BanffBlock interface {
Block
Timestamp() time.Time
}
func initialize(blk Block) error {
// We serialize this block as a pointer so that it can be deserialized into
// a Block
bytes, err := Codec.Marshal(Version, &blk)
if err != nil {
return fmt.Errorf("couldn't marshal block: %w", err)
}
return blk.initialize(bytes)
}