add query helper functions (#587)

This commit is contained in:
Dev Kalra 2023-02-13 22:50:38 +05:30 committed by GitHub
parent ca1a03b507
commit c59c00333a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 0 deletions

View File

@ -12,8 +12,14 @@ use {
QueryResponses,
},
cosmwasm_std::{
to_binary,
Addr,
Binary,
Coin,
QuerierWrapper,
QueryRequest,
StdResult,
WasmQuery,
},
std::time::Duration,
};
@ -40,3 +46,39 @@ pub enum QueryMsg {
pub struct PriceFeedResponse {
pub price_feed: PriceFeed,
}
/// Queries the price on-chain
pub fn query_price_feed(
querier: &QuerierWrapper,
contract_addr: Addr,
id: PriceIdentifier,
) -> StdResult<PriceFeedResponse> {
let price_feed_response = querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: contract_addr.into_string(),
msg: to_binary(&QueryMsg::PriceFeed { id })?,
}))?;
Ok(price_feed_response)
}
/// Get the fee required in order to update the on-chain state with the provided
/// `price_update_vaas`.
pub fn get_update_fee(
querier: &QuerierWrapper,
contract_addr: Addr,
price_update_vaas: &[Binary],
) -> StdResult<Coin> {
querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: contract_addr.into_string(),
msg: to_binary(&QueryMsg::GetUpdateFee {
vaas: price_update_vaas.to_vec(),
})?,
}))
}
/// Get the default length of time for which a price update remains valid.
pub fn get_valid_time_period(querier: &QuerierWrapper, contract_addr: Addr) -> StdResult<Duration> {
querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: contract_addr.into_string(),
msg: to_binary(&QueryMsg::GetValidTimePeriod)?,
}))
}