/
utils.go
40 lines (33 loc) · 987 Bytes
/
utils.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
package consensus
import (
"github.com/0xDaoChain/dao-chain/types"
"github.com/0xDaoChain/dao-chain/types/buildroot"
)
// BuildBlockParams are parameters passed into the BuildBlock helper method
type BuildBlockParams struct {
Header *types.Header
Txns []*types.Transaction
Receipts []*types.Receipt
}
// BuildBlock is a utility function that builds a block, based on the passed in header, transactions and receipts
func BuildBlock(params BuildBlockParams) *types.Block {
txs := params.Txns
header := params.Header
if len(txs) == 0 {
header.TxRoot = types.EmptyRootHash
} else {
header.TxRoot = buildroot.CalculateTransactionsRoot(txs)
}
if len(params.Receipts) == 0 {
header.ReceiptsRoot = types.EmptyRootHash
} else {
header.ReceiptsRoot = buildroot.CalculateReceiptsRoot(params.Receipts)
}
// TODO: Compute uncles
header.Sha3Uncles = types.EmptyUncleHash
header.ComputeHash()
return &types.Block{
Header: header,
Transactions: txs,
}
}