-
Notifications
You must be signed in to change notification settings - Fork 198
/
message_fund_iprpc.go
63 lines (51 loc) · 1.48 KB
/
message_fund_iprpc.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
package types
import (
fmt "fmt"
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
legacyerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const TypeMsgFundIprpc = "fund_iprpc"
var _ sdk.Msg = &MsgFundIprpc{}
func NewMsgFundIprpc(creator string, spec string, duration uint64, amounts sdk.Coins) *MsgFundIprpc {
return &MsgFundIprpc{
Creator: creator,
Spec: spec,
Duration: duration,
Amounts: amounts,
}
}
func (msg *MsgFundIprpc) Route() string {
return RouterKey
}
func (msg *MsgFundIprpc) Type() string {
return TypeMsgFundIprpc
}
func (msg *MsgFundIprpc) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
func (msg *MsgFundIprpc) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgFundIprpc) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(legacyerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
unique := map[string]struct{}{}
for _, amount := range msg.Amounts {
if !amount.IsValid() {
return sdkerrors.Wrap(fmt.Errorf("invalid amount; invalid denom or negative amount. coin: %s", amount.String()), "")
}
if _, ok := unique[amount.Denom]; ok {
return sdkerrors.Wrap(fmt.Errorf("invalid coins, duplicated denom: %s", amount.Denom), "")
}
unique[amount.Denom] = struct{}{}
}
return nil
}