-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.go
83 lines (68 loc) · 1.86 KB
/
builder.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2018 The VeChainThor developers
// Copyright (c) 2019 The PlayMaker developers
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>
package block
import (
"github.com/playmakerchain/powerplay/powerplay"
"github.com/playmakerchain/powerplay/tx"
)
// Builder to make it easy to build a block object.
type Builder struct {
headerBody headerBody
txs tx.Transactions
}
// ParentID set parent id.
func (b *Builder) ParentID(id powerplay.Bytes32) *Builder {
b.headerBody.ParentID = id
return b
}
// Timestamp set timestamp.
func (b *Builder) Timestamp(ts uint64) *Builder {
b.headerBody.Timestamp = ts
return b
}
// TotalScore set total score.
func (b *Builder) TotalScore(score uint64) *Builder {
b.headerBody.TotalScore = score
return b
}
// GasLimit set gas limit.
func (b *Builder) GasLimit(limit uint64) *Builder {
b.headerBody.GasLimit = limit
return b
}
// GasUsed set gas used.
func (b *Builder) GasUsed(used uint64) *Builder {
b.headerBody.GasUsed = used
return b
}
// Beneficiary set recipient of reward.
func (b *Builder) Beneficiary(addr powerplay.Address) *Builder {
b.headerBody.Beneficiary = addr
return b
}
// StateRoot set state root.
func (b *Builder) StateRoot(hash powerplay.Bytes32) *Builder {
b.headerBody.StateRoot = hash
return b
}
// ReceiptsRoot set receipts root.
func (b *Builder) ReceiptsRoot(hash powerplay.Bytes32) *Builder {
b.headerBody.ReceiptsRoot = hash
return b
}
// Transaction add a transaction.
func (b *Builder) Transaction(tx *tx.Transaction) *Builder {
b.txs = append(b.txs, tx)
return b
}
// Build build a block object.
func (b *Builder) Build() *Block {
header := Header{body: b.headerBody}
header.body.TxsRoot = b.txs.RootHash()
return &Block{
header: &header,
txs: b.txs,
}
}