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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
use self::state::AccountData;
use crate::{abstract_ica::StdAck, ibc_host::HostAction, objects::core::OsId};
use abstract_ica::IbcResponseMsg;
use cosmwasm_schema::QueryResponses;
use cosmwasm_std::{from_slice, Binary, Coin, CosmosMsg, StdResult, Timestamp};
pub mod state {
use super::LatestQueryResponse;
use crate::{
objects::{ans_host::AnsHost, common_namespace::ADMIN_NAMESPACE, core::OsId},
ANS_HOST as ANS_HOST_KEY,
};
use cosmwasm_std::{Addr, Coin, Timestamp};
use cw_controllers::Admin;
use cw_storage_plus::{Item, Map};
#[cosmwasm_schema::cw_serde]
pub struct Config {
pub version_control_address: Addr,
pub chain: String,
}
#[cosmwasm_schema::cw_serde]
#[derive(Default)]
pub struct AccountData {
pub last_update_time: Timestamp,
pub remote_addr: Option<String>,
pub remote_balance: Vec<Coin>,
}
pub const ADMIN: Admin = Admin::new(ADMIN_NAMESPACE);
pub const CHANNELS: Map<&str, String> = Map::new("channels");
pub const CONFIG: Item<Config> = Item::new("config");
pub const ACCOUNTS: Map<(&str, OsId), AccountData> = Map::new("accounts");
pub const LATEST_QUERIES: Map<(&str, OsId), LatestQueryResponse> = Map::new("queries");
pub const ANS_HOST: Item<AnsHost> = Item::new(ANS_HOST_KEY);
}
#[cosmwasm_schema::cw_serde]
pub struct InstantiateMsg {
pub ans_host_address: String,
pub version_control_address: String,
pub chain: String,
}
#[cosmwasm_schema::cw_serde]
pub struct MigrateMsg {}
#[cosmwasm_schema::cw_serde]
pub struct CallbackInfo {
pub id: String,
pub receiver: String,
}
impl CallbackInfo {
pub fn to_callback_msg(self, ack_data: &Binary) -> StdResult<CosmosMsg> {
let msg: StdAck = from_slice(ack_data)?;
IbcResponseMsg { id: self.id, msg }.into_cosmos_msg(self.receiver)
}
}
#[cosmwasm_schema::cw_serde]
#[cfg_attr(feature = "boot", derive(boot_core::ExecuteFns))]
pub enum ExecuteMsg {
UpdateAdmin {
admin: String,
},
UpdateConfig {
ans_host: Option<String>,
version_control: Option<String>,
},
SendFunds {
host_chain: String,
funds: Vec<Coin>,
},
Register {
host_chain: String,
},
SendPacket {
host_chain: String,
action: HostAction,
callback_info: Option<CallbackInfo>,
retries: u8,
},
RemoveHost {
host_chain: String,
},
}
#[cosmwasm_schema::cw_serde]
#[cfg_attr(feature = "boot", derive(boot_core::QueryFns))]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(ConfigResponse)]
Config {},
#[returns(ListAccountsResponse)]
ListAccounts {},
#[returns(AccountResponse)]
Account { chain: String, os_id: OsId },
#[returns(LatestQueryResponse)]
LatestQueryResult { chain: String, os_id: OsId },
#[returns(ListChannelsResponse)]
ListChannels {},
}
#[cosmwasm_schema::cw_serde]
pub struct ConfigResponse {
pub admin: String,
pub version_control_address: String,
pub chain: String,
}
#[cosmwasm_schema::cw_serde]
pub struct ListAccountsResponse {
pub accounts: Vec<AccountInfo>,
}
#[cosmwasm_schema::cw_serde]
pub struct ListChannelsResponse {
pub channels: Vec<(String, String)>,
}
#[cosmwasm_schema::cw_serde]
pub struct LatestQueryResponse {
pub last_update_time: Timestamp,
pub response: StdAck,
}
#[cosmwasm_schema::cw_serde]
pub struct RemoteProxyResponse {
pub channel_id: String,
pub proxy_address: String,
}
#[cosmwasm_schema::cw_serde]
pub struct AccountInfo {
pub channel_id: String,
pub os_id: OsId,
pub last_update_time: Timestamp,
pub remote_addr: Option<String>,
pub remote_balance: Vec<Coin>,
}
impl AccountInfo {
pub fn convert(channel_id: String, os_id: OsId, input: AccountData) -> Self {
AccountInfo {
channel_id,
os_id,
last_update_time: input.last_update_time,
remote_addr: input.remote_addr,
remote_balance: input.remote_balance,
}
}
}
#[cosmwasm_schema::cw_serde]
pub struct AccountResponse {
pub last_update_time: Timestamp,
pub remote_addr: Option<String>,
pub remote_balance: Vec<Coin>,
}
impl From<AccountData> for AccountResponse {
fn from(input: AccountData) -> Self {
AccountResponse {
last_update_time: input.last_update_time,
remote_addr: input.remote_addr,
remote_balance: input.remote_balance,
}
}
}