MCPcopy Create free account
hub / github.com/CPChain/chain / NewBlock

Function NewBlock

types/block.go:305–325  ·  view source on GitHub ↗

NewBlock creates a new block. The input data is copied, changes to header and to the field values will not affect the block. The values of TxsRoot, UncleHash, ReceiptsRoot and LogsBloom in header are ignored and set to values derived from the given txs, uncles and receipts.

(header *Header, txs []*Transaction, receipts []*Receipt)

Source from the content-addressed store, hash-verified

303// are ignored and set to values derived from the given txs, uncles
304// and receipts.
305func NewBlock(header *Header, txs []*Transaction, receipts []*Receipt) *Block {
306 b := &Block{header: CopyHeader(header), td: new(big.Int)}
307
308 // TODO: panic if len(txs) != len(receipts)
309 if len(txs) == 0 {
310 b.header.TxsRoot = EmptyRootHash
311 } else {
312 b.header.TxsRoot = DeriveSha(Transactions(txs))
313 b.transactions = make(Transactions, len(txs))
314 copy(b.transactions, txs)
315 }
316
317 if len(receipts) == 0 {
318 b.header.ReceiptsRoot = EmptyRootHash
319 } else {
320 b.header.ReceiptsRoot = DeriveSha(Receipts(receipts))
321 b.header.LogsBloom = CreateBloom(receipts)
322 }
323
324 return b
325}
326
327// NewBlockWithHeader creates a block with the given header data. The
328// header data is copied, changes to header and to the field values

Callers

nothing calls this directly

Calls 5

CopyHeaderFunction · 0.85
DeriveShaFunction · 0.85
TransactionsTypeAlias · 0.85
ReceiptsTypeAlias · 0.85
CreateBloomFunction · 0.85

Tested by

no test coverage detected