-
Notifications
You must be signed in to change notification settings - Fork 113
/
msg_update_governance_key.go
64 lines (52 loc) · 2.06 KB
/
msg_update_governance_key.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
package types
import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// NewUpdateGovernanceKeyRequest is the constructor for UpdateGovernanceKeyRequest
func NewUpdateGovernanceKeyRequest(sender sdk.AccAddress, threshold int, pubKeys ...cryptotypes.PubKey) *UpdateGovernanceKeyRequest {
govKey := multisig.NewLegacyAminoPubKey(threshold, pubKeys)
return &UpdateGovernanceKeyRequest{
Sender: sender,
GovernanceKey: *govKey,
}
}
// Route returns the route for this message
func (m UpdateGovernanceKeyRequest) Route() string {
return RouterKey
}
// Type returns the type of the message
func (m UpdateGovernanceKeyRequest) Type() string {
return "UpdateGovernanceKey"
}
// ValidateBasic executes a stateless message validation
func (m UpdateGovernanceKeyRequest) ValidateBasic() error {
if err := sdk.VerifyAddressFormat(m.Sender); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, sdkerrors.Wrap(err, "sender").Error())
}
if m.GovernanceKey.Threshold <= 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "threshold k of n multisignature: k <= 0")
}
if uint32(len(m.GovernanceKey.GetPubKeys())) < m.GovernanceKey.Threshold {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "threshold k of n multisignature: len(pubKeys) < k")
}
return nil
}
// GetSignBytes returns the message bytes that need to be signed
func (m UpdateGovernanceKeyRequest) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
// GetSigners returns the set of signers for this message
func (m UpdateGovernanceKeyRequest) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{m.Sender}
}
// UnpackInterfaces implements UnpackInterfacesMessage
func (m UpdateGovernanceKeyRequest) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
if err := m.GovernanceKey.UnpackInterfaces(unpacker); err != nil {
return err
}
return nil
}