-
Notifications
You must be signed in to change notification settings - Fork 14
/
submessages.go
87 lines (72 loc) · 1.84 KB
/
submessages.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
package types
import (
"encoding/json"
"fmt"
)
type replyOn int
const (
ReplyAlways replyOn = iota
ReplySuccess
ReplyError
ReplyNever
)
var fromReplyOn = map[replyOn]string{
ReplyAlways: "always",
ReplySuccess: "success",
ReplyError: "error",
ReplyNever: "never",
}
var toReplyOn = map[string]replyOn{
"always": ReplyAlways,
"success": ReplySuccess,
"error": ReplyError,
"never": ReplyNever,
}
func (r replyOn) String() string {
return fromReplyOn[r]
}
func (s replyOn) MarshalJSON() ([]byte, error) {
return json.Marshal(s.String())
}
func (s *replyOn) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
voteOption, ok := toReplyOn[j]
if !ok {
return fmt.Errorf("invalid reply_on value '%v'", j)
}
*s = voteOption
return nil
}
// SubMsg wraps a CosmosMsg with some metadata for handling replies (ID) and optionally
// limiting the gas usage (GasLimit)
type SubMsg struct {
ID uint64 `json:"id"`
Msg CosmosMsg `json:"msg"`
GasLimit *uint64 `json:"gas_limit,omitempty"`
ReplyOn replyOn `json:"reply_on"`
}
type Reply struct {
ID uint64 `json:"id"`
Result SubMsgResult `json:"result"`
}
// SubMsgResult is the raw response we return from wasmd after executing a SubMsg.
// This mirrors Rust's SubMsgResult.
type SubMsgResult struct {
Ok *SubMsgResponse `json:"ok,omitempty"`
Err string `json:"error,omitempty"`
}
// SubMsgResponse contains information we get back from a successful sub message execution,
// with full Cosmos SDK events.
// This mirrors Rust's SubMsgResponse.
type SubMsgResponse struct {
Events Events `json:"events"`
Data []byte `json:"data,omitempty"`
}
// Deprecated: Renamed to SubMsgResult
type SubcallResult = SubMsgResult
// Deprecated: Renamed to SubMsgResponse
type SubcallResponse = SubMsgResponse