-
Notifications
You must be signed in to change notification settings - Fork 0
/
msgs.go
88 lines (74 loc) · 2.18 KB
/
msgs.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
80
81
82
83
84
85
86
87
88
package model
import (
"encoding/json"
"errors"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/percosis-labs/percosis/x/cosmwasmpool/types"
poolmanagertypes "github.com/percosis-labs/percosis/x/poolmanager/types"
)
// constants.
const (
TypeMsgCreateCosmWasmPool = "create_cosmwasm_pool"
)
var (
_ sdk.Msg = &MsgCreateCosmWasmPool{}
_ poolmanagertypes.CreatePoolMsg = &MsgCreateCosmWasmPool{}
)
func NewMsgCreateCosmWasmPool(
codeId uint64,
sender sdk.AccAddress,
instantiateMsg []byte,
) MsgCreateCosmWasmPool {
return MsgCreateCosmWasmPool{
CodeId: codeId,
Sender: sender.String(),
InstantiateMsg: instantiateMsg,
}
}
func (msg MsgCreateCosmWasmPool) Route() string { return types.RouterKey }
func (msg MsgCreateCosmWasmPool) Type() string { return TypeMsgCreateCosmWasmPool }
func (msg MsgCreateCosmWasmPool) ValidateBasic() error {
if msg.CodeId == 0 {
return errors.New("CodeId cannot be 0")
}
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return fmt.Errorf("Invalid sender address (%s)", err)
}
if !json.Valid(msg.InstantiateMsg) {
return fmt.Errorf("InstantiateMsg is not a valid json")
}
return nil
}
func (msg MsgCreateCosmWasmPool) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
func (msg MsgCreateCosmWasmPool) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}
// Implement the CreatePoolMsg interface
func (msg MsgCreateCosmWasmPool) PoolCreator() sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return sender
}
func (msg MsgCreateCosmWasmPool) Validate(ctx sdk.Context) error {
return msg.ValidateBasic()
}
func (msg MsgCreateCosmWasmPool) InitialLiquidity() sdk.Coins {
return sdk.Coins{}
}
func (msg MsgCreateCosmWasmPool) CreatePool(ctx sdk.Context, poolID uint64) (poolmanagertypes.PoolI, error) {
poolI := NewCosmWasmPool(poolID, msg.CodeId, msg.InstantiateMsg)
return poolI, nil
}
func (msg MsgCreateCosmWasmPool) GetPoolType() poolmanagertypes.PoolType {
return poolmanagertypes.CosmWasm
}