-
Notifications
You must be signed in to change notification settings - Fork 83
/
msg_delay_message.go
44 lines (37 loc) · 1.34 KB
/
msg_delay_message.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
package types
import (
"fmt"
codec "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// MsgDelayMessage implements the UnpackInterfaces method for unpacking Msg, which is encoded as an Any type.
// Implementing this interface is necessary to decode the Msg, see https://docs.cosmos.network/v0.45/core/encoding.html
var _ codec.UnpackInterfacesMessage = &MsgDelayMessage{}
func (msg *MsgDelayMessage) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Authority)
return []sdk.AccAddress{addr}
}
// ValidateBasic performs basic validation on the message.
func (msg *MsgDelayMessage) ValidateBasic() error {
// Perform basic checks that the encoded message was set.
if msg.Msg == nil {
return ErrMsgIsNil
}
return nil
}
func (msg *MsgDelayMessage) UnpackInterfaces(unpacker codec.AnyUnpacker) error {
var sdkMsg sdk.Msg
// Unpack the Any into the sdk.Msg type. This should hydrate the cached value.
return unpacker.UnpackAny(msg.Msg, &sdkMsg)
}
func (msg *MsgDelayMessage) GetMessage() (sdk.Msg, error) {
cached := msg.Msg.GetCachedValue()
if cached == nil {
return nil, fmt.Errorf("any cached value is nil, delayed messages must be correctly packed any values")
}
casted, ok := cached.(sdk.Msg)
if !ok {
return nil, fmt.Errorf("cached value is not a sdk.Msg")
}
return casted, nil
}