MCPcopy Create free account
hub / github.com/DNAProject/DNA / makeBlock

Function makeBlock

wasmtest/wasm-test.go:419–461  ·  view source on GitHub ↗
(acc *account.Account, txs []*types.Transaction)

Source from the content-addressed store, hash-verified

417}
418
419func makeBlock(acc *account.Account, txs []*types.Transaction) (*types.Block, error) {
420 nextBookkeeper, err := types.AddressFromBookkeepers([]keypair.PublicKey{acc.PublicKey})
421 if err != nil {
422 return nil, fmt.Errorf("GetBookkeeperAddress error:%s", err)
423 }
424 prevHash := ledger.DefLedger.GetCurrentBlockHash()
425 height := ledger.DefLedger.GetCurrentBlockHeight()
426
427 nonce := uint64(height)
428 var txHash []common.Uint256
429 for _, t := range txs {
430 txHash = append(txHash, t.Hash())
431 }
432
433 txRoot := common.ComputeMerkleRoot(txHash)
434
435 blockRoot := ledger.DefLedger.GetBlockRootWithNewTxRoots(height+1, []common.Uint256{txRoot})
436 header := &types.Header{
437 Version: 0,
438 PrevBlockHash: prevHash,
439 TransactionsRoot: txRoot,
440 BlockRoot: blockRoot,
441 Timestamp: constants.GENESIS_BLOCK_TIMESTAMP + height + 1,
442 Height: height + 1,
443 ConsensusData: nonce,
444 NextBookkeeper: nextBookkeeper,
445 }
446 block := &types.Block{
447 Header: header,
448 Transactions: txs,
449 }
450
451 blockHash := block.Hash()
452
453 sig, err := signature.Sign(acc, blockHash[:])
454 if err != nil {
455 return nil, fmt.Errorf("signature, Sign error:%s", err)
456 }
457
458 block.Header.Bookkeepers = []keypair.PublicKey{acc.PublicKey}
459 block.Header.SigData = [][]byte{sig}
460 return block, nil
461}
462
463func assertEq(a interface{}, b interface{}) {
464 if reflect.DeepEqual(a, b) == false {

Callers 2

execTxCheckResFunction · 0.85
mainFunction · 0.85

Calls 7

HashMethod · 0.95
SignFunction · 0.92
ErrorfMethod · 0.80
GetCurrentBlockHashMethod · 0.65
GetCurrentBlockHeightMethod · 0.65
HashMethod · 0.65

Tested by

no test coverage detected