-
Notifications
You must be signed in to change notification settings - Fork 531
/
reviewal.go
60 lines (48 loc) · 1.41 KB
/
reviewal.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
package spn
import (
"context"
"errors"
"github.com/cosmos/cosmos-sdk/types"
launchtypes "github.com/tendermint/spn/x/launch/types"
)
// reviewal keeps a proposal's reviewal.
type reviewal struct {
id int
isApproved bool
}
// Reviewal configures reviewal to create a review for a proposal.
type Reviewal func(*reviewal)
// ApproveProposal returns approval for a proposal with id.
func ApproveProposal(id int) Reviewal {
return func(r *reviewal) {
r.id = id
r.isApproved = true
}
}
// RejectProposal returns rejection for a proposals with id.
func RejectProposal(id int) Reviewal {
return func(r *reviewal) {
r.id = id
}
}
// SubmitReviewals submits reviewals for proposals in batch for chainID by using SPN accountName.
func (c *Client) SubmitReviewals(ctx context.Context, accountName, chainID string, reviewals ...Reviewal) (gas uint64, broadcast func() error, err error) {
if len(reviewals) == 0 {
return 0, nil, errors.New("at least one reviewal required")
}
addr, err := c.cosmos.Address(accountName)
if err != nil {
return 0, nil, err
}
var msgs []types.Msg
for _, r := range reviewals {
var rev reviewal
r(&rev)
if rev.isApproved {
msgs = append(msgs, launchtypes.NewMsgApprove(chainID, int32(rev.id), addr.String()))
} else {
msgs = append(msgs, launchtypes.NewMsgReject(chainID, int32(rev.id), addr.String()))
}
}
return c.broadcastProvision(ctx, accountName, msgs...)
}