use crate::abstract_ica::StdAck;
use cosmwasm_std::{from_slice, Binary, Coin, CosmosMsg, StdResult, Timestamp};
use abstract_ica::IbcResponseMsg;
use crate::ibc_host::HostAction;
use self::state::AccountData;
pub mod state {
use super::LatestQueryResponse;
use crate::{
objects::{ans_host::AnsHost, common_namespace::ADMIN_NAMESPACE},
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, u32), AccountData> = Map::new("accounts");
pub const LATEST_QUERIES: Map<(&str, u32), 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]
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]
pub enum QueryMsg {
Admin {},
ListAccounts {},
Account { chain: String, os_id: u32 },
LatestQueryResult { chain: String, os_id: u32 },
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: u32,
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: u32, 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,
}
}
}