(acc *account.Account, txs []*types.Transaction)
| 417 | } |
| 418 | |
| 419 | func 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 | |
| 463 | func assertEq(a interface{}, b interface{}) { |
| 464 | if reflect.DeepEqual(a, b) == false { |
no test coverage detected