/
block.go
49 lines (41 loc) · 1.37 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
48
49
// Package block implements the roothash block and header.
package block
import "github.com/oasisprotocol/oasis-core/go/common"
// Block is an Oasis block.
//
// Keep this in sync with /runtime/src/common/roothash.rs.
type Block struct {
// Header is the block header.
Header Header `json:"header"`
}
// NewGenesisBlock creates a new empty genesis block given a runtime
// id and POSIX timestamp.
func NewGenesisBlock(id common.Namespace, timestamp uint64) *Block {
var blk Block
blk.Header.Version = 0
blk.Header.Timestamp = Timestamp(timestamp)
blk.Header.HeaderType = Normal
blk.Header.Namespace = id
blk.Header.PreviousHash.Empty()
blk.Header.IORoot.Empty()
blk.Header.StateRoot.Empty()
blk.Header.MessagesHash.Empty()
blk.Header.InMessagesHash.Empty()
return &blk
}
// NewEmptyBlock creates a new empty block with a specific type.
func NewEmptyBlock(child *Block, timestamp uint64, htype HeaderType) *Block {
var blk Block
blk.Header.Version = child.Header.Version
blk.Header.Namespace = child.Header.Namespace
blk.Header.Round = child.Header.Round + 1
blk.Header.Timestamp = Timestamp(timestamp)
blk.Header.HeaderType = htype
blk.Header.PreviousHash = child.Header.EncodedHash()
blk.Header.IORoot.Empty()
// State root is unchanged.
blk.Header.StateRoot = child.Header.StateRoot
blk.Header.MessagesHash.Empty()
blk.Header.InMessagesHash.Empty()
return &blk
}