forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 10
/
content.go
38 lines (30 loc) · 1.08 KB
/
content.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
package v1
import (
"fmt"
"github.com/cosmos/gogoproto/proto"
codectypes "github.com/shapeshift/cosmos-sdk/codec/types"
sdkerrors "github.com/shapeshift/cosmos-sdk/types/errors"
"github.com/shapeshift/cosmos-sdk/x/gov/types/v1beta1"
)
// NewLegacyContent creates a new MsgExecLegacyContent from a legacy Content
// interface.
func NewLegacyContent(content v1beta1.Content, authority string) (*MsgExecLegacyContent, error) {
msg, ok := content.(proto.Message)
if !ok {
return nil, fmt.Errorf("%T does not implement proto.Message", content)
}
any, err := codectypes.NewAnyWithValue(msg)
if err != nil {
return nil, err
}
return NewMsgExecLegacyContent(any, authority), nil
}
// LegacyContentFromMessage extracts the legacy Content interface from a
// MsgExecLegacyContent.
func LegacyContentFromMessage(msg *MsgExecLegacyContent) (v1beta1.Content, error) {
content, ok := msg.Content.GetCachedValue().(v1beta1.Content)
if !ok {
return nil, sdkerrors.ErrInvalidType.Wrapf("expected %T, got %T", (*v1beta1.Content)(nil), msg.Content.GetCachedValue())
}
return content, nil
}