diff --git a/Cargo.lock b/Cargo.lock index a7b270d5..6aee4869 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,9 +69,9 @@ checksum = "128a44527fc0d6abf05f9eda748b9027536e12dff93f5acc8449f51583309350" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" @@ -91,6 +91,8 @@ version = "0.1.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", + "cw-utils", + "hex", "schemars", "serde", "thiserror", @@ -98,15 +100,15 @@ dependencies = [ [[package]] name = "const-oid" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "795bc6e66a8e340f075fcf6227e417a2dc976b92b91f3cdc778bb858778b6747" +checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" [[package]] name = "cosmwasm-crypto" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ca101fbf2f76723711a30ea3771ef312ec3ec254ad021b237871ed802f9f175" +checksum = "a6fb22494cf7d23d0c348740e06e5c742070b2991fd41db77bba0bcfbae1a723" dependencies = [ "digest 0.10.7", "ed25519-zebra", @@ -117,18 +119,18 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c73d2dd292f60e42849d2b07c03d809cf31e128a4299a805abd6d24553bcaaf5" +checksum = "6e199424486ea97d6b211db6387fd72e26b4a439d40cc23140b2d8305728055b" dependencies = [ "syn 1.0.109", ] [[package]] name = "cosmwasm-schema" -version = "1.3.1" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63c337e097a089e5b52b5d914a7ff6613332777f38ea6d9d36e1887cd0baa72e" +checksum = "fef683a9c1c4eabd6d31515719d0d2cc66952c4c87f7eb192bfc90384517dc34" dependencies = [ "cosmwasm-schema-derive", "schemars", @@ -139,9 +141,9 @@ dependencies = [ [[package]] name = "cosmwasm-schema-derive" -version = "1.3.1" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "766cc9e7c1762d8fc9c0265808910fcad755200cd0e624195a491dd885a61169" +checksum = "9567025acbb4c0c008178393eb53b3ac3c2e492c25949d3bf415b9cbe80772d8" dependencies = [ "proc-macro2", "quote", @@ -150,9 +152,9 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a44d3f9c25b2f864737c6605a98f2e4675d53fd8bbc7cf4d7c02475661a793d" +checksum = "7d89d680fb60439b7c5947b15f9c84b961b88d1f8a3b20c4bd178a3f87db8bae" dependencies = [ "base64", "bnum", @@ -164,15 +166,15 @@ dependencies = [ "schemars", "serde", "serde-json-wasm", - "sha2 0.10.7", + "sha2 0.10.8", "thiserror", ] [[package]] name = "cosmwasm-storage" -version = "1.3.1" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "800aaddd70ba915e19bf3d2d992aa3689d8767857727fdd3b414df4fd52d2aa1" +checksum = "54a1c574d30feffe4b8121e61e839c231a5ce21901221d2fb4d5c945968a4f00" dependencies = [ "cosmwasm-std", "serde", @@ -266,9 +268,9 @@ dependencies = [ [[package]] name = "cw-utils" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c80e93d1deccb8588db03945016a292c3c631e6325d349ebb35d2db6f4f946f7" +checksum = "1b9f351a4e4d81ef7c890e44d903f8c0bdcdc00f094fd3a181eaf70c0eec7a3a" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -281,9 +283,9 @@ dependencies = [ [[package]] name = "cw2" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29ac2dc7a55ad64173ca1e0a46697c31b7a5c51342f55a1e84a724da4eb99908" +checksum = "9431d14f64f49e41c6ef5561ed11a5391c417d0cb16455dea8cdcb9037a8d197" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -364,9 +366,9 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "304e6508efa593091e97a9abbc10f90aa7ca635b6d2784feff3c89d41dd12272" +checksum = "23d2f3407d9a573d666de4b5bdf10569d73ca9478087346697dcbae6244bfbcd" [[package]] name = "ecdsa" @@ -558,6 +560,7 @@ dependencies = [ "cosmwasm-std", "cw-multi-test", "cw-storage-plus", + "cw-utils", "cw2", "data-requests", "hex", @@ -594,7 +597,7 @@ dependencies = [ "cfg-if", "ecdsa 0.14.8", "elliptic-curve 0.12.3", - "sha2 0.10.7", + "sha2 0.10.8", ] [[package]] @@ -607,7 +610,7 @@ dependencies = [ "ecdsa 0.16.8", "elliptic-curve 0.13.6", "once_cell", - "sha2 0.10.7", + "sha2 0.10.8", "signature 2.1.0", ] @@ -622,9 +625,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.147" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "once_cell" @@ -660,9 +663,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -698,6 +701,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus", + "cw-utils", "cw2", "serde", "thiserror", @@ -705,9 +709,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.32" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -756,9 +760,9 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "schemars" -version = "0.8.12" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" +checksum = "1f7b0ce13155372a76ee2e1c5ffba1fe61ede73fbea5630d61eee6fac4929c0c" dependencies = [ "dyn-clone", "schemars_derive", @@ -768,9 +772,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.12" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" +checksum = "e85e2a16b12bdb763244c69ab79363d71db2b4b918a2def53f80b02e0574b13c" dependencies = [ "proc-macro2", "quote", @@ -808,15 +812,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0" [[package]] name = "serde" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] @@ -832,13 +836,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] @@ -878,9 +882,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", @@ -970,9 +974,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.28" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", @@ -981,35 +985,35 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.44" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.44" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.38", ] [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "version_check" diff --git a/Cargo.toml b/Cargo.toml index f06051c2..49dcf778 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ cosmwasm-std = { version = "1.4", features = ["staking"] } cosmwasm-storage = "1.1.3" cw-storage-plus = "1.1" cw2 = "1.1" +cw-utils = "1.0.1" hex = "0.4.3" proxy-contract = { path = "./packages/proxy" } schemars = "0.8.10" @@ -35,4 +36,3 @@ serde = { version = "1.0.145", default-features = false, features = ["derive"] } serde_json = "1.0.107" sha3 = "0.10.8" thiserror = { version = "1.0.31" } -wasm-bin-storage = { path = "./packages/wasm-bin-storage" } diff --git a/packages/common/Cargo.toml b/packages/common/Cargo.toml index f3627dea..1ad70eb2 100644 --- a/packages/common/Cargo.toml +++ b/packages/common/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" [dependencies] cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } +cw-utils = { workspace = true } schemars = { workspace = true } serde = { workspace = true } thiserror = { workspace = true } +hex = { workspace = true } diff --git a/packages/common/src/error.rs b/packages/common/src/error.rs index f2f26ca1..d391d3d9 100644 --- a/packages/common/src/error.rs +++ b/packages/common/src/error.rs @@ -1,6 +1,9 @@ use crate::types::Hash; use cosmwasm_std::StdError; +use cw_utils::ParseReplyError; +use hex::FromHexError; use thiserror::Error; + #[derive(Error, Debug, PartialEq)] pub enum ContractError { // staking contract errors @@ -40,4 +43,18 @@ pub enum ContractError { ContractAlreadySet, #[error("Caller must be the contract creator")] NotContractCreator, + #[error("Unknown reply ID: {0}")] + UnknownReplyId(String), + #[error("Unexpected error: {0}")] + UnexpectedError(String), + #[error(transparent)] + ParseReplyError(#[from] ParseReplyError), + #[error("Invalid hexadecimal input: {0}")] + FromHex(FromHexError), +} + +impl From for ContractError { + fn from(err: FromHexError) -> Self { + ContractError::FromHex(err) + } } diff --git a/packages/data-requests/src/data_request.rs b/packages/data-requests/src/data_request.rs index 1e389a8e..662ce54f 100644 --- a/packages/data-requests/src/data_request.rs +++ b/packages/data-requests/src/data_request.rs @@ -1,9 +1,8 @@ #[cfg(not(feature = "library"))] -use cosmwasm_std::{to_binary, Deps, DepsMut, MessageInfo, Order, Response, StdResult}; +use cosmwasm_std::{Deps, DepsMut, MessageInfo, Order, Response, StdResult}; use crate::state::{DATA_REQUESTS, DATA_REQUESTS_COUNT}; -use crate::msg::PostDataRequestResponse; use common::msg::{GetDataRequestResponse, GetDataRequestsFromPoolResponse}; use common::state::DataRequest; use common::types::Hash; @@ -110,9 +109,9 @@ pub mod data_requests { Ok(Response::new() .add_attribute("action", "post_data_request") - .set_data(to_binary(&PostDataRequestResponse { - dr_id: posted_dr.dr_id.clone(), - })?) + .set_data(cosmwasm_std::Binary::from(hex::decode( + posted_dr.dr_id[2..].to_string().clone(), + )?)) .add_event(Event::new("seda-data-request").add_attributes([ ("version", CONTRACT_VERSION), ("dr_id", &posted_dr.dr_id), diff --git a/packages/data-requests/src/lib.rs b/packages/data-requests/src/lib.rs index 2577ee07..188de1ae 100644 --- a/packages/data-requests/src/lib.rs +++ b/packages/data-requests/src/lib.rs @@ -1,7 +1,6 @@ pub mod contract; pub mod data_request; pub mod data_request_result; -pub mod msg; pub mod state; pub mod types; pub mod utils; diff --git a/packages/data-requests/src/msg.rs b/packages/data-requests/src/msg.rs deleted file mode 100644 index 85cc4603..00000000 --- a/packages/data-requests/src/msg.rs +++ /dev/null @@ -1,7 +0,0 @@ -use common::types::Hash; -use cosmwasm_schema::cw_serde; - -#[cw_serde] -pub struct PostDataRequestResponse { - pub dr_id: Hash, -} diff --git a/packages/integration-tests/Cargo.toml b/packages/integration-tests/Cargo.toml index 1be2b6ea..36cab9b8 100644 --- a/packages/integration-tests/Cargo.toml +++ b/packages/integration-tests/Cargo.toml @@ -33,6 +33,7 @@ cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } cw2 = { workspace = true } +cw-utils = { workspace = true } hex = { workspace = true } proxy-contract = { workspace = true } schemars = { workspace = true } diff --git a/packages/integration-tests/src/utils.rs b/packages/integration-tests/src/utils.rs index 29a2fb61..85402bb2 100644 --- a/packages/integration-tests/src/utils.rs +++ b/packages/integration-tests/src/utils.rs @@ -4,6 +4,7 @@ use common::types::Bytes; use common::types::Hash; use cosmwasm_std::{to_binary, Addr, BankMsg, Coin, CosmosMsg, Empty, StdResult, Uint128, WasmMsg}; use cw_multi_test::{App, AppBuilder, AppResponse, Contract, ContractWrapper, Executor}; +use cw_utils::parse_execute_response_data; use data_requests::state::DataRequestInputs; use data_requests::utils::hash_data_request; use proxy_contract::msg::ProxyExecuteMsg; @@ -89,7 +90,8 @@ pub fn proxy_contract_template() -> Box> { proxy_contract::contract::instantiate, proxy_contract::contract::query, ) - .with_sudo(proxy_contract::contract::sudo); + .with_sudo(proxy_contract::contract::sudo) + .with_reply(proxy_contract::contract::reply); Box::new(contract) } @@ -210,10 +212,12 @@ pub fn proper_instantiate() -> (App, CwTemplateContract) { } pub fn get_dr_id(res: AppResponse) -> String { - // TODO: this is an ugly way to get the dr_id. - // although PostDataRequest on the DataRequest contract returns it in `data`, the Proxy contract does not yet. - // https://github.com/sedaprotocol/seda-chain-contracts/issues/68 - res.events.last().unwrap().attributes[2].value.clone() + let binary = parse_execute_response_data(&res.data.unwrap().0) + .unwrap() + .data + .unwrap(); + + format!("0x{}", hex::encode(binary)) } pub fn calculate_commitment(reveal: &str, salt: &str) -> String { diff --git a/packages/proxy/Cargo.toml b/packages/proxy/Cargo.toml index 7eef08b4..358c8104 100644 --- a/packages/proxy/Cargo.toml +++ b/packages/proxy/Cargo.toml @@ -31,5 +31,6 @@ cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } cw2 = { workspace = true } +cw-utils = { workspace = true } serde = { workspace = true } thiserror = { workspace = true } diff --git a/packages/proxy/src/contract.rs b/packages/proxy/src/contract.rs index f0f46115..723690a4 100644 --- a/packages/proxy/src/contract.rs +++ b/packages/proxy/src/contract.rs @@ -14,10 +14,11 @@ use common::{ }, }; use cosmwasm_std::{ - to_binary, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, QueryRequest, Response, - StdResult, WasmMsg, WasmQuery, + to_binary, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, QueryRequest, Reply, + Response, StdResult, SubMsg, WasmMsg, WasmQuery, }; use cw2::set_contract_version; +use cw_utils::parse_reply_execute_data; use crate::{ msg::{InstantiateMsg, ProxyExecuteMsg, ProxyQueryMsg, ProxySudoMsg}, @@ -28,6 +29,8 @@ use crate::{ const CONTRACT_NAME: &str = "proxy-contract"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); +const POST_DATA_REQUEST_REPLY_ID: u64 = 1; + #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( deps: DepsMut, @@ -86,13 +89,21 @@ pub fn execute( // Delegated calls to contracts // DataRequests - ProxyExecuteMsg::PostDataRequest { posted_dr } => Ok(Response::new() - .add_message(CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: DATA_REQUESTS.load(deps.storage)?.to_string(), - msg: to_binary(&DataRequestsExecuteMsg::PostDataRequest { posted_dr })?, - funds: vec![], - })) - .add_attribute("action", "post_data_request")), + ProxyExecuteMsg::PostDataRequest { posted_dr } => { + // we create a submessage here rather than a fire-and-forget + // message to the DataRequest contract in order to return the dr_id + // in the data field of this call on the Proxy contract. + Ok(Response::new() + .add_submessage(SubMsg::reply_on_success( + CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: DATA_REQUESTS.load(deps.storage)?.to_string(), + msg: to_binary(&DataRequestsExecuteMsg::PostDataRequest { posted_dr })?, + funds: vec![], + }), + POST_DATA_REQUEST_REPLY_ID, + )) + .add_attribute("action", "post_data_request")) + } ProxyExecuteMsg::CommitDataResult { dr_id, commitment } => Ok(Response::new() .add_message(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: DATA_REQUESTS.load(deps.storage)?.to_string(), @@ -318,6 +329,19 @@ pub fn sudo(deps: DepsMut, _env: Env, msg: ProxySudoMsg) -> Result Result { + match msg.id { + POST_DATA_REQUEST_REPLY_ID => { + let data = parse_reply_execute_data(msg)? + .data + .ok_or_else(|| ContractError::UnexpectedError("Data is None".to_string()))?; + Ok(Response::new().set_data(data)) + } + id => Err(ContractError::UnknownReplyId(id.to_string())), + } +} + #[cfg(test)] mod init_tests { use super::*;