-
Notifications
You must be signed in to change notification settings - Fork 105
/
msg_refund.go
79 lines (65 loc) · 2.09 KB
/
msg_refund.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package types
import (
"fmt"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
axelarnet "github.com/axelarnetwork/axelar-core/x/axelarnet/exported"
)
// NewRefundMsgRequest creates a message of type RefundMsgRequest
func NewRefundMsgRequest(sender sdk.AccAddress, innerMessage sdk.Msg) *RefundMsgRequest {
messageAny, err := cdctypes.NewAnyWithValue(innerMessage)
if err != nil {
panic(err)
}
return &RefundMsgRequest{
Sender: sender,
InnerMessage: messageAny,
}
}
// Route returns the route for this message
func (m RefundMsgRequest) Route() string {
return RouterKey
}
// Type returns the type of the message
func (m RefundMsgRequest) Type() string {
return "RefundMsgRequest"
}
// ValidateBasic executes a stateless message validation
func (m RefundMsgRequest) ValidateBasic() error {
if err := sdk.VerifyAddressFormat(m.Sender); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, sdkerrors.Wrap(err, "sender").Error())
}
if m.InnerMessage == nil {
return fmt.Errorf("missing inner message")
}
innerMessage := m.GetInnerMessage()
if innerMessage == nil {
return fmt.Errorf("invalid inner message")
}
return innerMessage.ValidateBasic()
}
// GetSignBytes returns the message bytes that need to be signed
func (m RefundMsgRequest) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
// GetSigners returns the set of signers for this message
func (m RefundMsgRequest) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{m.Sender}
}
// UnpackInterfaces implements UnpackInterfacesMessage
func (m RefundMsgRequest) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error {
if m.InnerMessage != nil {
var refundableMsg axelarnet.Refundable
return unpacker.UnpackAny(m.InnerMessage, &refundableMsg)
}
return nil
}
// GetInnerMessage unwrap the inner message
func (m RefundMsgRequest) GetInnerMessage() axelarnet.Refundable {
innerMsg, ok := m.InnerMessage.GetCachedValue().(axelarnet.Refundable)
if !ok {
return nil
}
return innerMsg
}