2024-08-13 13:31:10 +00:00
|
|
|
use cosmwasm_std::{
|
|
|
|
to_json_binary, Addr, CosmosMsg, CustomQuery, Querier, QuerierWrapper, StdResult, WasmMsg,
|
|
|
|
WasmQuery,
|
|
|
|
};
|
2024-10-01 14:27:57 +00:00
|
|
|
use quartz_tcbinfo_msgs::{ExecuteMsg, GetTcbInfoResponse, QueryMsg};
|
2024-08-13 13:31:10 +00:00
|
|
|
use schemars::JsonSchema;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
const FMSPC: &str = "00606a000000";
|
|
|
|
|
|
|
|
/// CwTemplateContract is a wrapper around Addr that provides a lot of helpers
|
|
|
|
/// for working with this.
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
|
|
|
|
pub struct CwTemplateContract(pub Addr);
|
|
|
|
|
|
|
|
impl CwTemplateContract {
|
|
|
|
pub fn addr(&self) -> Addr {
|
|
|
|
self.0.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn call<T: Into<ExecuteMsg>>(&self, msg: T) -> StdResult<CosmosMsg> {
|
|
|
|
let msg = to_json_binary(&msg.into())?;
|
|
|
|
Ok(WasmMsg::Execute {
|
|
|
|
contract_addr: self.addr().into(),
|
|
|
|
msg,
|
|
|
|
funds: vec![],
|
|
|
|
}
|
|
|
|
.into())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get Count
|
|
|
|
pub fn get_tcbinfo<Q, T, CQ>(&self, querier: &Q) -> StdResult<GetTcbInfoResponse>
|
|
|
|
where
|
|
|
|
Q: Querier,
|
|
|
|
T: Into<String>,
|
|
|
|
CQ: CustomQuery,
|
|
|
|
{
|
|
|
|
let msg = QueryMsg::GetTcbInfo {
|
|
|
|
fmspc: FMSPC.to_string(),
|
|
|
|
};
|
|
|
|
let query = WasmQuery::Smart {
|
|
|
|
contract_addr: self.addr().into(),
|
|
|
|
msg: to_json_binary(&msg)?,
|
|
|
|
}
|
|
|
|
.into();
|
|
|
|
let res: GetTcbInfoResponse = QuerierWrapper::<CQ>::new(querier).query(&query)?;
|
|
|
|
Ok(res)
|
|
|
|
}
|
|
|
|
}
|