MCPcopy Create free account
hub / github.com/chain/txvm / NewInitialBlock

Function NewInitialBlock

protocol/block.go:139–169  ·  view source on GitHub ↗

NewInitialBlock produces the first block for a new blockchain, using the given pubkeys and quorum for its NextPredicate.

(pubkeys []ed25519.PublicKey, quorum int, timestamp time.Time)

Source from the content-addressed store, hash-verified

137// NewInitialBlock produces the first block for a new blockchain,
138// using the given pubkeys and quorum for its NextPredicate.
139func NewInitialBlock(pubkeys []ed25519.PublicKey, quorum int, timestamp time.Time) (*bc.Block, error) {
140 // TODO(kr): move this into a lower-level package (e.g. chain/protocol/bc)
141 // so that other packages (e.g. chain/protocol/validation) unit tests can
142 // call this function.
143 root := bc.TxMerkleRoot(nil) // calculate the zero value of the tx merkle root
144 patRoot := bc.NewHash(new(patricia.Tree).RootHash())
145
146 var pkBytes [][]byte
147 for _, pk := range pubkeys {
148 pkBytes = append(pkBytes, pk)
149 }
150
151 b := &bc.Block{
152 UnsignedBlock: &bc.UnsignedBlock{
153 BlockHeader: &bc.BlockHeader{
154 Version: 3,
155 Height: 1,
156 TimestampMs: bc.Millis(timestamp),
157 TransactionsRoot: &root,
158 ContractsRoot: &patRoot,
159 NoncesRoot: &patRoot,
160 NextPredicate: &bc.Predicate{
161 Version: 1,
162 Quorum: int32(quorum),
163 Pubkeys: pkBytes,
164 },
165 },
166 },
167 }
168 return b, nil
169}

Callers 5

NewChainFunction · 0.92
newBlockFunction · 0.92
newTestChainFunction · 0.85

Calls 4

TxMerkleRootFunction · 0.92
NewHashFunction · 0.92
MillisFunction · 0.92
RootHashMethod · 0.80

Tested by 3

newTestChainFunction · 0.68