-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
define req and resp types for dex stargate queries and refactor respe…
…ctive helpers
- Loading branch information
1 parent
eb0b075
commit 4d3e10e
Showing
7 changed files
with
110 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,28 @@ | ||
use cosmwasm_std::{ | ||
Binary, ContractResult, CosmosMsg, Deps, Empty, QueryRequest, StdError, StdResult, | ||
SystemResult, Timestamp, | ||
}; | ||
use prost::bytes::Bytes; | ||
use cosmwasm_std::{Binary, CosmosMsg, Deps, QueryRequest, StdResult}; | ||
use prost_types::Timestamp as TimestampGen; | ||
use serde_json_wasm::to_vec; | ||
use serde::de::DeserializeOwned; | ||
|
||
pub(crate) fn make_stargate_query<Req, Res>(deps: Deps, req: Req, path: &str) -> StdResult<Res> | ||
where | ||
Req: prost::Message, | ||
Res: prost::Message + Default, | ||
Res: DeserializeOwned, | ||
{ | ||
let raw = to_vec::<QueryRequest<Empty>>(&QueryRequest::Stargate { | ||
deps.querier.query(&QueryRequest::Stargate { | ||
path: path.to_string(), | ||
data: req.encode_to_vec().into(), | ||
}) | ||
.map_err(|serialize_err| { | ||
StdError::generic_err(format!("Serializing QueryRequest: {}", serialize_err)) | ||
})?; | ||
|
||
match deps.querier.raw_query(&raw) { | ||
SystemResult::Err(system_err) => Err(StdError::generic_err(format!( | ||
"Querier system error: {}", | ||
system_err | ||
))), | ||
SystemResult::Ok(ContractResult::Err(contract_err)) => Err(StdError::generic_err(format!( | ||
"Querier contract error: {}", | ||
contract_err | ||
))), | ||
SystemResult::Ok(ContractResult::Ok(value)) => { | ||
deps.api.debug( | ||
format!( | ||
"WASMDEBUG: stargate query raw resp: {:?}", | ||
value.to_string() | ||
) | ||
.as_str(), | ||
); | ||
deps.api.debug( | ||
format!( | ||
"WASMDEBUG: stargate query to_base_64 resp: {:?}", | ||
value.to_base64() | ||
) | ||
.as_str(), | ||
); | ||
|
||
Res::decode(Bytes::copy_from_slice(&value)) | ||
.map_err(|e| StdError::generic_err(e.to_string())) | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn create_stargate_msg<Req>(req: Req, path: &str) -> CosmosMsg | ||
where | ||
Req: prost::Message, | ||
{ | ||
pub(crate) fn create_stargate_msg<Req: prost::Message>(req: Req, path: &str) -> CosmosMsg { | ||
cosmwasm_std::CosmosMsg::Stargate { | ||
type_url: path.to_string(), | ||
value: Binary::from(req.encode_to_vec()), | ||
} | ||
} | ||
|
||
pub(crate) fn convert_timestamp(timestamp: Timestamp) -> TimestampGen { | ||
pub(crate) fn convert_timestamp(timestamp: u64) -> TimestampGen { | ||
TimestampGen { | ||
seconds: i64::try_from(timestamp.seconds()).unwrap(), | ||
nanos: i32::try_from(timestamp.subsec_nanos()).unwrap(), | ||
seconds: timestamp as i64, | ||
nanos: 0, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.