-
Notifications
You must be signed in to change notification settings - Fork 205
/
message_set_iprpc_data.go
56 lines (43 loc) · 1.34 KB
/
message_set_iprpc_data.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
package types
import (
"fmt"
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const TypeMsgSetIprpcData = "set_iprpc_data"
var _ sdk.Msg = &MsgSetIprpcData{}
func NewMsgSetIprpcData(authority string, cost sdk.Coin, subs []string) *MsgSetIprpcData {
return &MsgSetIprpcData{
Authority: authority,
MinIprpcCost: cost,
IprpcSubscriptions: subs,
}
}
func (msg *MsgSetIprpcData) Route() string {
return RouterKey
}
func (msg *MsgSetIprpcData) Type() string {
return TypeMsgSetIprpcData
}
func (msg *MsgSetIprpcData) GetSigners() []sdk.AccAddress {
authority, _ := sdk.AccAddressFromBech32(msg.Authority)
return []sdk.AccAddress{authority}
}
func (msg *MsgSetIprpcData) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgSetIprpcData) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
return sdkerrors.Wrap(err, "invalid authority address")
}
if !msg.MinIprpcCost.IsValid() {
return sdkerrors.Wrap(fmt.Errorf("invalid min iprpc cost; invalid denom or negative amount. coin: %s", msg.MinIprpcCost.String()), "")
}
for _, sub := range msg.IprpcSubscriptions {
if _, err := sdk.AccAddressFromBech32(sub); err != nil {
return sdkerrors.Wrap(err, "invalid subscription address")
}
}
return nil
}