Skip to content

Commit

Permalink
replace data field with msg_responses
Browse files Browse the repository at this point in the history
  • Loading branch information
joldie777 committed Jun 12, 2024
1 parent 31e2282 commit 87d0b65
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 15 deletions.
20 changes: 13 additions & 7 deletions contracts/ibc_transfer/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use cosmwasm_std::{
coin, entry_point, from_json, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Reply,
Response, StdError, StdResult, SubMsg,
coin, entry_point, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Reply, Response,
StdError, StdResult, SubMsg,
};
use cw2::set_contract_version;
use neutron_sdk::interchain_txs::helpers::decode_message_response;
use neutron_sdk::proto_types::neutron::transfer::MsgTransferResponse;
use neutron_sdk::{
bindings::{
msg::{IbcFee, MsgIbcTransferResponse, NeutronMsg},
msg::{IbcFee, NeutronMsg},
query::NeutronQuery,
},
query::min_ibc_fee::query_min_ibc_fee,
Expand Down Expand Up @@ -112,14 +114,18 @@ fn msg_with_sudo_callback<C: Into<CosmosMsg<T>>, T>(
// and process this payload when an acknowledgement for the SubmitTx message is received in Sudo handler
fn prepare_sudo_payload(mut deps: DepsMut, _env: Env, msg: Reply) -> StdResult<Response> {
let payload = read_reply_payload(deps.storage, msg.id)?;
let resp: MsgIbcTransferResponse = from_json(
msg.result
let resp: MsgTransferResponse = decode_message_response(
&msg.result
.into_result()
.map_err(StdError::generic_err)?
.data
.ok_or_else(|| StdError::generic_err("no result"))?,
.msg_responses[0]
.clone()
.value
.to_vec(),
)
.map_err(|e| StdError::generic_err(format!("failed to parse response: {:?}", e)))?;
deps.api
.debug(format!("WASMDEBUG: reply msg: {:?}", resp).as_str());
let seq_id = resp.sequence_id;
let channel_id = resp.channel;
save_sudo_payload(deps.branch().storage, channel_id, seq_id, payload)?;
Expand Down
14 changes: 8 additions & 6 deletions contracts/neutron_interchain_txs/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ use serde::{Deserialize, Serialize};

use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use neutron_sdk::bindings::msg::IbcFee;
use neutron_sdk::proto_types::neutron::interchaintxs::v1::MsgSubmitTxResponse;
use neutron_sdk::{
bindings::{
msg::{MsgSubmitTxResponse, NeutronMsg},
msg::NeutronMsg,
query::{NeutronQuery, QueryInterchainAccountAddressResponse},
types::ProtobufAny,
},
Expand Down Expand Up @@ -615,13 +616,14 @@ fn sudo_error(deps: DepsMut, request: RequestPacket, details: String) -> StdResu
// and process this payload when an acknowledgement for the SubmitTx message is received in Sudo handler
fn prepare_sudo_payload(mut deps: DepsMut, _env: Env, msg: Reply) -> StdResult<Response> {
let payload = read_reply_payload(deps.storage)?;
let resp: MsgSubmitTxResponse = serde_json_wasm::from_slice(
msg.result
let resp: MsgSubmitTxResponse = decode_message_response(
&msg.result
.into_result()
.map_err(StdError::generic_err)?
.data
.ok_or_else(|| StdError::generic_err("no result"))?
.as_slice(),
.msg_responses[0]
.clone()
.value
.to_vec(),
)
.map_err(|e| StdError::generic_err(format!("failed to parse response: {:?}", e)))?;
deps.api
Expand Down
8 changes: 6 additions & 2 deletions packages/neutron-sdk/schema/neutron_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,8 @@
"additionalProperties": false
},
{
"description": "Proposal to upgrade IBC client",
"description": "Depreacteed Proposal to upgrade IBC client",
"deprecated": true,
"type": "object",
"required": [
"upgrade_proposal"
Expand All @@ -642,7 +643,8 @@
"additionalProperties": false
},
{
"description": "Proposal to update IBC client",
"description": "Deprecated. Proposal to update IBC client",
"deprecated": true,
"type": "object",
"required": [
"client_update_proposal"
Expand Down Expand Up @@ -816,6 +818,7 @@
},
"ClientUpdateProposal": {
"description": "ClientUpdateProposal defines the struct for client update proposal.",
"deprecated": true,
"type": "object",
"required": [
"description",
Expand Down Expand Up @@ -1628,6 +1631,7 @@
},
"UpgradeProposal": {
"description": "UpgradeProposal defines the struct for IBC upgrade proposal.",
"deprecated": true,
"type": "object",
"required": [
"description",
Expand Down
159 changes: 159 additions & 0 deletions packages/neutron-sdk/schema/neutron_query.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,52 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"market_map"
],
"properties": {
"market_map": {
"$ref": "#/definitions/MarketMapQuery"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"oracle"
],
"properties": {
"oracle": {
"$ref": "#/definitions/OracleQuery"
}
},
"additionalProperties": false
}
],
"definitions": {
"Binary": {
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>. See also <https://github.com/CosmWasm/cosmwasm/blob/main/docs/MESSAGE_TYPES.md>.",
"type": "string"
},
"CurrencyPair": {
"type": "object",
"required": [
"Base",
"Quote"
],
"properties": {
"Base": {
"type": "string"
},
"Quote": {
"type": "string"
}
}
},
"DexQuery": {
"oneOf": [
{
Expand Down Expand Up @@ -872,6 +911,67 @@
}
]
},
"MarketMapQuery": {
"oneOf": [
{
"description": "Parameters queries the parameters of the module.",
"type": "object",
"required": [
"params"
],
"properties": {
"params": {
"type": "object"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"last_updated"
],
"properties": {
"last_updated": {
"type": "object"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"market_map"
],
"properties": {
"market_map": {
"type": "object"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"market"
],
"properties": {
"market": {
"type": "object",
"required": [
"currency_pair"
],
"properties": {
"currency_pair": {
"$ref": "#/definitions/CurrencyPair"
}
}
}
},
"additionalProperties": false
}
]
},
"MultiHopRoute": {
"type": "object",
"required": [
Expand All @@ -886,6 +986,65 @@
}
}
},
"OracleQuery": {
"oneOf": [
{
"type": "object",
"required": [
"get_all_currency_pairs"
],
"properties": {
"get_all_currency_pairs": {
"type": "object"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"get_price"
],
"properties": {
"get_price": {
"type": "object",
"required": [
"currency_pair"
],
"properties": {
"currency_pair": {
"$ref": "#/definitions/CurrencyPair"
}
}
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"get_prices"
],
"properties": {
"get_prices": {
"type": "object",
"required": [
"currency_pair_ids"
],
"properties": {
"currency_pair_ids": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
},
"additionalProperties": false
}
]
},
"PageRequest": {
"type": "object",
"required": [
Expand Down
2 changes: 2 additions & 0 deletions packages/neutron-sdk/src/stargate/aux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ where
Req: prost::Message,
Res: DeserializeOwned,
{
#[allow(deprecated)]
deps.querier.query(&QueryRequest::Stargate {
path: path.to_string(),
data: req.encode_to_vec().into(),
Expand All @@ -28,6 +29,7 @@ where
/// * **path** is an RPC request path. See Msg service definitions in neutron modules' proto files
/// for additional info.
pub fn create_stargate_msg<Req: prost::Message, T>(path: &str, req: Req) -> CosmosMsg<T> {
#[allow(deprecated)]
CosmosMsg::Stargate::<T> {
type_url: path.to_string(),
value: Binary::from(req.encode_to_vec()),
Expand Down

0 comments on commit 87d0b65

Please sign in to comment.