-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder_timelock.go
80 lines (66 loc) · 2.41 KB
/
builder_timelock.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
package mcms
import "github.com/smartcontractkit/mcms/types"
// TimelockProposalBuilder builder for timelock proposals types.
type TimelockProposalBuilder struct {
BaseProposalBuilder[*TimelockProposalBuilder]
proposal TimelockProposal
}
// NewTimelockProposalBuilder creates a new TimelockProposalBuilder.
func NewTimelockProposalBuilder() *TimelockProposalBuilder {
builder := &TimelockProposalBuilder{
proposal: TimelockProposal{
BaseProposal: BaseProposal{
Kind: types.KindTimelockProposal,
ChainMetadata: make(map[types.ChainSelector]types.ChainMetadata),
},
TimelockAddresses: make(map[types.ChainSelector]string),
Operations: []types.BatchOperation{},
},
}
builder.BaseProposalBuilder = BaseProposalBuilder[*TimelockProposalBuilder]{
baseProposal: &builder.proposal.BaseProposal,
builder: builder,
}
return builder
}
// SetAction sets the action of the timelock proposal.
func (b *TimelockProposalBuilder) SetAction(action types.TimelockAction) *TimelockProposalBuilder {
b.proposal.Action = action
return b
}
// SetDelay sets the delay of the timelock proposal.
func (b *TimelockProposalBuilder) SetDelay(delay types.Duration) *TimelockProposalBuilder {
b.proposal.Delay = delay
return b
}
// SetTimelockAddress adds a timelock address to the timelock proposal.
func (b *TimelockProposalBuilder) SetTimelockAddresses(
addrs map[types.ChainSelector]string,
) *TimelockProposalBuilder {
b.proposal.TimelockAddresses = addrs
return b
}
// AddTimelockAddress adds a timelock address for the given selector to the timelock proposal.
func (b *TimelockProposalBuilder) AddTimelockAddress(
selector types.ChainSelector, address string,
) *TimelockProposalBuilder {
b.proposal.TimelockAddresses[selector] = address
return b
}
// AddOperation adds an operation to the timelock proposal.
func (b *TimelockProposalBuilder) AddOperation(bop types.BatchOperation) *TimelockProposalBuilder {
b.proposal.Operations = append(b.proposal.Operations, bop)
return b
}
// SetOperations sets all the operations of the proposal
func (b *TimelockProposalBuilder) SetOperations(bops []types.BatchOperation) *TimelockProposalBuilder {
b.proposal.Operations = bops
return b
}
// Build validates and returns the constructed TimelockProposal.
func (b *TimelockProposalBuilder) Build() (*TimelockProposal, error) {
if err := b.proposal.Validate(); err != nil {
return nil, err
}
return &b.proposal, nil
}