Skip to content

Commit

Permalink
terra/terra-cosmwasm: fix custom query serialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Csongor Kiss committed Jun 27, 2023
1 parent 54df7e5 commit 88ab475
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 156 deletions.
6 changes: 1 addition & 5 deletions terra/packages/terra-cosmwasm-2.2.0/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
mod msg;
mod querier;
mod query;
mod route;

pub use msg::{create_swap_msg, create_swap_send_msg, TerraMsg, TerraMsgWrapper};
pub use querier::TerraQuerier;
pub use query::{
ContractInfoResponse, ExchangeRateItem, ExchangeRatesResponse, SwapResponse, TaxCapResponse,
TaxRateResponse, TerraQuery, TerraQueryWrapper,
TaxRateResponse, TerraQuery,
};
pub use route::TerraRoute;

// This export is added to all contracts that import this package, signifying that they require
// "terra" support on the chain they run on.
Expand Down
63 changes: 0 additions & 63 deletions terra/packages/terra-cosmwasm-2.2.0/src/msg.rs

This file was deleted.

70 changes: 5 additions & 65 deletions terra/packages/terra-cosmwasm-2.2.0/src/querier.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use cosmwasm_std::{Coin, QuerierWrapper, StdResult};
use cosmwasm_std::{QuerierWrapper, StdResult};

use crate::query::{
ContractInfoResponse, ExchangeRatesResponse, SwapResponse, TaxCapResponse, TaxRateResponse,
TerraQuery, TerraQueryWrapper,
};
use crate::route::TerraRoute;
use crate::query::{TaxCapResponse, TaxRateResponse, TerraQuery};

/// This is a helper wrapper to easily use our custom queries
pub struct TerraQuerier<'a> {
Expand All @@ -16,73 +12,17 @@ impl<'a> TerraQuerier<'a> {
TerraQuerier { querier }
}

pub fn query_swap<T: Into<String>>(
&self,
offer_coin: Coin,
ask_denom: T,
) -> StdResult<SwapResponse> {
let request = TerraQueryWrapper {
route: TerraRoute::Market,
query_data: TerraQuery::Swap {
offer_coin,
ask_denom: ask_denom.into(),
},
}
.into();

self.querier.custom_query(&request)
}

pub fn query_tax_cap<T: Into<String>>(&self, denom: T) -> StdResult<TaxCapResponse> {
let request = TerraQueryWrapper {
route: TerraRoute::Treasury,
query_data: TerraQuery::TaxCap {
denom: denom.into(),
},
let request = TerraQuery::TaxCap {
denom: denom.into(),
}
.into();

self.querier.custom_query(&request)
}

pub fn query_tax_rate(&self) -> StdResult<TaxRateResponse> {
let request = TerraQueryWrapper {
route: TerraRoute::Treasury,
query_data: TerraQuery::TaxRate {},
}
.into();

self.querier.custom_query(&request)
}

pub fn query_exchange_rates<T: Into<String>>(
&self,
base_denom: T,
quote_denoms: Vec<T>,
) -> StdResult<ExchangeRatesResponse> {
let request = TerraQueryWrapper {
route: TerraRoute::Oracle,
query_data: TerraQuery::ExchangeRates {
base_denom: base_denom.into(),
quote_denoms: quote_denoms.into_iter().map(|x| x.into()).collect(),
},
}
.into();

self.querier.custom_query(&request)
}

pub fn query_contract_info<T: Into<String>>(
&self,
contract_address: T,
) -> StdResult<ContractInfoResponse> {
let request = TerraQueryWrapper {
route: TerraRoute::Wasm,
query_data: TerraQuery::ContractInfo {
contract_address: contract_address.into(),
},
}
.into();
let request = TerraQuery::TaxRate {}.into();

self.querier.custom_query(&request)
}
Expand Down
12 changes: 1 addition & 11 deletions terra/packages/terra-cosmwasm-2.2.0/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::route::TerraRoute;
use cosmwasm_std::{Coin, CustomQuery, Decimal, Uint128};

/// TerraQueryWrapper is an override of QueryRequest::Custom to access Terra-specific modules
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct TerraQueryWrapper {
pub route: TerraRoute,
pub query_data: TerraQuery,
}

// implement custom query
impl CustomQuery for TerraQueryWrapper {}
impl CustomQuery for TerraQuery {}

/// TerraQuery is defines available query datas
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
Expand Down
12 changes: 0 additions & 12 deletions terra/packages/terra-cosmwasm-2.2.0/src/route.rs

This file was deleted.

0 comments on commit 88ab475

Please sign in to comment.