diff --git a/packages/cw0/src/lib.rs b/packages/cw0/src/lib.rs index d84e61a3f..332437a37 100644 --- a/packages/cw0/src/lib.rs +++ b/packages/cw0/src/lib.rs @@ -8,7 +8,10 @@ mod payment; pub use pagination::{ calc_range_end, calc_range_start, calc_range_start_string, maybe_addr, maybe_canonical, }; -pub use parse_reply::{parse_reply_execute_data, parse_reply_instantiate_data}; +pub use parse_reply::{ + parse_execute_response_data, parse_instantiate_response_data, parse_reply_execute_data, + parse_reply_instantiate_data, +}; pub use payment::{may_pay, must_pay, nonpayable, one_coin, PaymentError}; pub use crate::balance::NativeBalance; diff --git a/packages/cw0/src/parse_reply.rs b/packages/cw0/src/parse_reply.rs index 2778a4a68..2035fa095 100644 --- a/packages/cw0/src/parse_reply.rs +++ b/packages/cw0/src/parse_reply.rs @@ -1,3 +1,5 @@ +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; use thiserror::Error; use cosmwasm_std::{Binary, Reply}; @@ -7,13 +9,13 @@ const WIRE_TYPE_LENGTH_DELIMITED: u8 = 2; // Up to 9 bytes of varints as a practical limit (https://github.com/multiformats/unsigned-varint#practical-maximum-of-9-bytes-for-security) const VARINT_MAX_BYTES: usize = 9; -#[derive(Clone, Debug, PartialEq)] +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] pub struct MsgInstantiateContractResponse { pub contract_address: String, pub data: Option, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] pub struct MsgExecuteContractResponse { pub data: Option, } @@ -112,8 +114,24 @@ pub fn parse_reply_instantiate_data( .map_err(ParseReplyError::SubMsgFailure)? .data .ok_or_else(|| ParseReplyError::ParseFailure("Missing reply data".to_owned()))?; + parse_instantiate_response_data(&data.0) +} + +pub fn parse_reply_execute_data(msg: Reply) -> Result { + let data = msg + .result + .into_result() + .map_err(ParseReplyError::SubMsgFailure)? + .data + .ok_or_else(|| ParseReplyError::ParseFailure("Missing reply data".to_owned()))?; + parse_execute_response_data(&data.0) +} + +pub fn parse_instantiate_response_data( + data: &[u8], +) -> Result { // Manual protobuf decoding - let mut data = data.0; + let mut data = data.to_vec(); // Parse contract addr let contract_addr = parse_protobuf_string(&mut data, 1)?; @@ -126,19 +144,14 @@ pub fn parse_reply_instantiate_data( }) } -pub fn parse_reply_execute_data(msg: Reply) -> Result { - let data = msg - .result - .into_result() - .map_err(ParseReplyError::SubMsgFailure)? - .data - .ok_or_else(|| ParseReplyError::ParseFailure("Missing reply data".to_owned()))?; +pub fn parse_execute_response_data( + data: &[u8], +) -> Result { // Manual protobuf decoding - let mut data = data.0; - // Parse (optional) data - let data = parse_protobuf_bytes(&mut data, 1)?; + let mut data = data.to_vec(); + let inner_data = parse_protobuf_bytes(&mut data, 1)?; - Ok(MsgExecuteContractResponse { data }) + Ok(MsgExecuteContractResponse { data: inner_data }) } #[derive(Error, Debug, PartialEq)] diff --git a/packages/multi-test/src/wasm.rs b/packages/multi-test/src/wasm.rs index abaaab7b6..93ef37628 100644 --- a/packages/multi-test/src/wasm.rs +++ b/packages/multi-test/src/wasm.rs @@ -24,6 +24,7 @@ use crate::transactions::transactional; use cosmwasm_std::testing::mock_wasmd_attr; use anyhow::{anyhow, bail, Result as AnyResult}; +use cw0::parse_instantiate_response_data; // Contract state is kept in Storage, separate from the contracts themselves const CONTRACTS: Map<&Addr, ContractData> = Map::new("contracts"); @@ -856,11 +857,11 @@ pub fn parse_contract_addr(data: &Option) -> AnyResult { .ok_or_else(|| anyhow!("No data response"))? .to_vec(); // parse the protobuf struct - let init_data = InstantiateData::decode(bin.as_slice())?; - if init_data.address.is_empty() { + let init_data = parse_instantiate_response_data(bin.as_slice())?; + if init_data.contract_address.is_empty() { bail!("no contract address provided"); } - Ok(Addr::unchecked(init_data.address)) + Ok(Addr::unchecked(init_data.contract_address)) } #[cfg(test)]