-
Notifications
You must be signed in to change notification settings - Fork 52
/
proposal_handler.go
41 lines (36 loc) · 1.06 KB
/
proposal_handler.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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/shentufoundation/shentu/v2/x/cert/types"
)
// HandleCertifierUpdateProposal is a handler for executing a passed certifier update proposal
func HandleCertifierUpdateProposal(ctx sdk.Context, k Keeper, p *types.CertifierUpdateProposal) error {
certifierAddr, err := sdk.AccAddressFromBech32(p.Certifier)
if err != nil {
panic(err)
}
proposerAddr, err := sdk.AccAddressFromBech32(p.Proposer)
if err != nil {
panic(err)
}
switch p.AddOrRemove {
case types.Add:
if k.IsCertifier(ctx, certifierAddr) {
return types.ErrCertifierAlreadyExists
}
if p.Alias != "" && k.HasCertifierAlias(ctx, p.Alias) {
return types.ErrRepeatedAlias
}
certifier := types.NewCertifier(certifierAddr, p.Alias, proposerAddr, p.Description)
k.SetCertifier(ctx, certifier)
return nil
case types.Remove:
certifiers := k.GetAllCertifiers(ctx)
if len(certifiers) == 1 {
return types.ErrOnlyOneCertifier
}
return k.deleteCertifier(ctx, certifierAddr)
default:
return types.ErrAddOrRemove
}
}