-
Notifications
You must be signed in to change notification settings - Fork 17
/
message_claim_stray.go
60 lines (49 loc) · 1.54 KB
/
message_claim_stray.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 types
import (
fmt "fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const TypeMsgClaimStray = "claim_stray"
var _ sdk.Msg = &MsgClaimStray{}
func NewMsgClaimStray(creator string, cid string) *MsgClaimStray {
return &MsgClaimStray{
Creator: creator,
Cid: cid,
}
}
func (msg *MsgClaimStray) Route() string {
return RouterKey
}
func (msg *MsgClaimStray) Type() string {
return TypeMsgClaimStray
}
func (msg *MsgClaimStray) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
func (msg *MsgClaimStray) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgClaimStray) ValidateBasic() error {
prefix, _, err := bech32.DecodeAndConvert(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
if prefix != AddressPrefix {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator prefix (%s)", fmt.Errorf("%s is not a valid prefix here. Expected `jkl`", prefix))
}
prefix, _, err = bech32.DecodeAndConvert(msg.Cid)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid cid (%s)", err)
}
if prefix != CidPrefix {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid cid prefix (%s)", fmt.Errorf("%s is not a valid prefix here. Expected `jklc`", prefix))
}
return nil
}