-
Notifications
You must be signed in to change notification settings - Fork 8
/
subcall.go
75 lines (64 loc) · 1.67 KB
/
subcall.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
package types
// TODO: look at using this strong type from wasmvm:subcall.go
// for now, it adda a bunch of custom json parsing and need to be careful.
type replyOn int
const (
ReplyAlways = "always"
ReplySuccess = "success"
ReplyError = "error"
ReplyNever = "never"
)
// 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 string `json:"reply_on"`
}
type Reply struct {
ID uint64 `json:"id"`
Result SubcallResult `json:"result"`
}
// SubcallResult is the raw response we return from the sdk -> reply after executing a SubMsg.
// This is mirrors Rust's ContractResult<SubcallResponse>.
type SubcallResult struct {
Ok *SubcallResponse `json:"ok,omitempty"`
Err string `json:"error,omitempty"`
}
type SubcallResponse struct {
Events []Event `json:"events,emptyslice"`
Data []byte `json:"data,omitempty"`
}
type Event struct {
Type string `json:"type"`
Attributes []EventAttribute `json:"attributes,emptyslice"`
}
func NewSubMsg(msg ToMsg) SubMsg {
return SubMsg{
ID: 0,
Msg: msg.ToMsg(),
ReplyOn: ReplyNever,
}
}
func ReplyOnError(msg ToMsg, id uint64) SubMsg {
return SubMsg{
ID: id,
Msg: msg.ToMsg(),
ReplyOn: ReplyError,
}
}
func ReplyOnSuccess(msg ToMsg, id uint64) SubMsg {
return SubMsg{
ID: id,
Msg: msg.ToMsg(),
ReplyOn: ReplySuccess,
}
}
func AlwaysReply(msg ToMsg, id uint64) SubMsg {
return SubMsg{
ID: id,
Msg: msg.ToMsg(),
ReplyOn: ReplyAlways,
}
}