-
Notifications
You must be signed in to change notification settings - Fork 100
/
msg.go
145 lines (125 loc) · 4.93 KB
/
msg.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package types
import (
"encoding/json"
)
//------- Results / Msgs -------------
// HandleResult is the raw response from the handle call.
// This is mirrors Rust's ContractResult<HandleResponse>.
type HandleResult struct {
Ok *HandleResponse `json:"ok,omitempty"`
Err string `json:"error,omitempty"`
}
// HandleResponse defines the return value on a successful handle
type HandleResponse struct {
// Messages comes directly from the contract and is it's request for action
Messages []CosmosMsg `json:"messages"`
// base64-encoded bytes to return as ABCI.Data field
Data []byte `json:"data"`
// attributes for a log event to return over abci interface
Attributes []EventAttribute `json:"attributes"`
}
// InitResult is the raw response from the handle call.
// This is mirrors Rust's ContractResult<InitResponse>.
type InitResult struct {
Ok *InitResponse `json:"ok,omitempty"`
Err string `json:"error,omitempty"`
}
// InitResponse defines the return value on a successful handle
type InitResponse struct {
// Messages comes directly from the contract and is it's request for action
Messages []CosmosMsg `json:"messages"`
// attributes for a log event to return over abci interface
Attributes []EventAttribute `json:"attributes"`
}
// MigrateResult is the raw response from the migrate call.
// This is mirrors Rust's ContractResult<MigrateResponse>.
type MigrateResult struct {
Ok *MigrateResponse `json:"ok,omitempty"`
Err string `json:"error,omitempty"`
}
// MigrateResponse defines the return value on a successful handle
type MigrateResponse struct {
// Messages comes directly from the contract and is it's request for action
Messages []CosmosMsg `json:"messages"`
// base64-encoded bytes to return as ABCI.Data field
Data []byte `json:"data"`
// attributes for a log event to return over abci interface
Attributes []EventAttribute `json:"attributes"`
}
// EventAttribute
type EventAttribute struct {
Key string `json:"key"`
Value string `json:"value"`
}
// CosmosMsg is an rust enum and only (exactly) one of the fields should be set
// Should we do a cleaner approach in Go? (type/data?)
type CosmosMsg struct {
Bank *BankMsg `json:"bank,omitempty"`
Custom json.RawMessage `json:"custom,omitempty"`
Staking *StakingMsg `json:"staking,omitempty"`
Wasm *WasmMsg `json:"wasm,omitempty"`
}
type BankMsg struct {
Send *SendMsg `json:"send,omitempty"`
}
// SendMsg contains instructions for a Cosmos-SDK/SendMsg
// It has a fixed interface here and should be converted into the proper SDK format before dispatching
type SendMsg struct {
FromAddress string `json:"from_address"`
ToAddress string `json:"to_address"`
Amount Coins `json:"amount"`
}
type StakingMsg struct {
Delegate *DelegateMsg `json:"delegate,omitempty"`
Undelegate *UndelegateMsg `json:"undelegate,omitempty"`
Redelegate *RedelegateMsg `json:"redelegate,omitempty"`
Withdraw *WithdrawMsg `json:"withdraw,omitempty"`
}
type DelegateMsg struct {
Validator string `json:"validator"`
Amount Coin `json:"amount"`
}
type UndelegateMsg struct {
Validator string `json:"validator"`
Amount Coin `json:"amount"`
}
type RedelegateMsg struct {
SrcValidator string `json:"src_validator"`
DstValidator string `json:"dst_validator"`
Amount Coin `json:"amount"`
}
type WithdrawMsg struct {
Validator string `json:"validator"`
// this is optional
Recipient string `json:"recipient,omitempty"`
}
type WasmMsg struct {
Execute *ExecuteMsg `json:"execute,omitempty"`
Instantiate *InstantiateMsg `json:"instantiate,omitempty"`
}
// ExecuteMsg is used to call another defined contract on this chain.
// The calling contract requires the callee to be defined beforehand,
// and the address should have been defined in initialization.
// And we assume the developer tested the ABIs and coded them together.
//
// Since a contract is immutable once it is deployed, we don't need to transform this.
// If it was properly coded and worked once, it will continue to work throughout upgrades.
type ExecuteMsg struct {
// ContractAddr is the sdk.AccAddress of the contract, which uniquely defines
// the contract ID and instance ID. The sdk module should maintain a reverse lookup table.
ContractAddr string `json:"contract_addr"`
// Msg is assumed to be a json-encoded message, which will be passed directly
// as `userMsg` when calling `Handle` on the above-defined contract
Msg []byte `json:"msg"`
// Send is an optional amount of coins this contract sends to the called contract
Send Coins `json:"send"`
}
type InstantiateMsg struct {
// CodeID is the reference to the wasm byte code as used by the Cosmos-SDK
CodeID uint64 `json:"code_id"`
// Msg is assumed to be a json-encoded message, which will be passed directly
// as `userMsg` when calling `Handle` on the above-defined contract
Msg []byte `json:"msg"`
// Send is an optional amount of coins this contract sends to the called contract
Send Coins `json:"send"`
}