diff --git a/Cargo.toml b/Cargo.toml index 3ad816f..2238a09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,8 @@ members = ["crates/common", "crates/proto-common"] [workspace.dependencies] base64 = { version = "0.22.1" } -cosmwasm-schema = { version = "1.5.7" } -cosmwasm-std = { version = "1.5.7" } +cosmwasm-schema = { version = "1.5" } +cosmwasm-std = { version = "1.5" } cw-storage-plus = "1.2.0" hex = "0.4.3" k256 = { version = "0.13" } diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index e403e29..04821e0 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -4,8 +4,13 @@ version = "0.1.0" edition = "2021" [features] -default = ["serde", "base64"] -cosmwasm = ["cosmwasm-schema", "cosmwasm-std", "cw-storage-plus"] +default = ["dep:serde", "dep:base64"] +cosmwasm = [ + "dep:cosmwasm-schema", + "dep:cosmwasm-std", + "dep:cw-storage-plus", + "dep:schemars", +] test-utils = [] [dependencies] @@ -15,13 +20,13 @@ cosmwasm-std = { workspace = true, optional = true } cw-storage-plus = { workspace = true, optional = true } hex.workspace = true lazy_static.workspace = true +schemars = { workspace = true, features = ["semver"], optional = true } sha3.workspace = true semver = { workspace = true, features = ["serde"] } -serde = { workspace = true, optional = true } +serde = { workspace = true, features = ["derive"], optional = true } thiserror.workspace = true vrf-rs.workspace = true [dev-dependencies] -schemars = { workspace = true, features = ["semver"] } serde_json.workspace = true k256.workspace = true diff --git a/crates/common/src/msgs/data_requests/execute/commit_result.rs b/crates/common/src/msgs/data_requests/execute/commit_result.rs index d6f1205..7aa5f99 100644 --- a/crates/common/src/msgs/data_requests/execute/commit_result.rs +++ b/crates/common/src/msgs/data_requests/execute/commit_result.rs @@ -1,7 +1,7 @@ -use super::*; +use crate::{error::Result, types::*}; -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Execute { pub dr_id: String, @@ -12,7 +12,7 @@ pub struct Execute { impl Execute { fn generate_hash(dr_id: &str, commitment: &str, chain_id: &str, contract_addr: &str, dr_height: u64) -> Hash { - hash([ + crate::crypto::hash([ "commit_data_result".as_bytes(), dr_id.as_bytes(), &dr_height.to_be_bytes(), diff --git a/crates/common/src/msgs/data_requests/execute/mod.rs b/crates/common/src/msgs/data_requests/execute/mod.rs index 8fe6eb8..8b48a12 100644 --- a/crates/common/src/msgs/data_requests/execute/mod.rs +++ b/crates/common/src/msgs/data_requests/execute/mod.rs @@ -1,11 +1,11 @@ -use super::*; +use super::TimeoutConfig; pub mod commit_result; pub mod post_request; pub mod reveal_result; -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub enum ExecuteMsg { CommitDataResult(commit_result::Execute), @@ -14,7 +14,7 @@ pub enum ExecuteMsg { SetTimeoutConfig(TimeoutConfig), } -impl From for super::ExecuteMsg { +impl From for crate::msgs::ExecuteMsg { fn from(value: ExecuteMsg) -> Self { Self::DataRequest(Box::new(value)) } diff --git a/crates/common/src/msgs/data_requests/execute/post_request.rs b/crates/common/src/msgs/data_requests/execute/post_request.rs index 2dd0352..2b7e03c 100644 --- a/crates/common/src/msgs/data_requests/execute/post_request.rs +++ b/crates/common/src/msgs/data_requests/execute/post_request.rs @@ -1,7 +1,7 @@ -use super::*; +use crate::{msgs::data_requests::PostDataRequestArgs, types::Bytes}; -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Execute { pub posted_dr: PostDataRequestArgs, diff --git a/crates/common/src/msgs/data_requests/execute/reveal_result.rs b/crates/common/src/msgs/data_requests/execute/reveal_result.rs index f2ad5fc..ab20272 100644 --- a/crates/common/src/msgs/data_requests/execute/reveal_result.rs +++ b/crates/common/src/msgs/data_requests/execute/reveal_result.rs @@ -1,7 +1,7 @@ -use super::*; +use crate::{error::Result, msgs::data_requests::RevealBody, types::*}; -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Execute { pub dr_id: String, @@ -14,7 +14,7 @@ pub struct Execute { impl Execute { fn generate_hash(dr_id: &str, chain_id: &str, contract_addr: &str, dr_height: u64, reveal_body_hash: Hash) -> Hash { - hash([ + crate::crypto::hash([ "reveal_data_result".as_bytes(), dr_id.as_bytes(), &dr_height.to_be_bytes(), diff --git a/crates/common/src/msgs/data_requests/execute_tests.rs b/crates/common/src/msgs/data_requests/execute_tests.rs index 76573d3..2dd6d18 100644 --- a/crates/common/src/msgs/data_requests/execute_tests.rs +++ b/crates/common/src/msgs/data_requests/execute_tests.rs @@ -1,10 +1,12 @@ use semver::Version; use serde_json::json; +use super::{execute::*, PostDataRequestArgs, RevealBody}; +use crate::msgs; +#[cfg(not(feature = "cosmwasm"))] +use crate::msgs::assert_json_ser; #[cfg(feature = "cosmwasm")] -use super::Bytes; -use super::{execute::*, ExecuteMsg, PostDataRequestArgs, RevealBody}; -use crate::msgs::*; +use crate::{msgs::assert_json_deser, types::Bytes}; #[test] fn json_commit_result() { @@ -16,7 +18,7 @@ fn json_commit_result() { "proof": "proof" } }); - let msg: ExecuteMsg = commit_result::Execute { + let msg: msgs::ExecuteMsg = commit_result::Execute { dr_id: "dr_id".to_string(), commitment: "commitment".to_string(), public_key: "public_key".to_string(), @@ -95,7 +97,7 @@ fn json_post_request() { "payback_address": payback_address, } }); - let msg: ExecuteMsg = post_request::Execute { + let msg: msgs::ExecuteMsg = post_request::Execute { posted_dr: args, seda_payload, payback_address, @@ -141,7 +143,7 @@ fn json_reveal_result() { "stdout": vec!["some-output".to_string()], } }); - let msg: ExecuteMsg = reveal_result::Execute { + let msg: msgs::ExecuteMsg = reveal_result::Execute { dr_id: "dr_id".to_string(), reveal_body, public_key: "public_key".to_string(), diff --git a/crates/common/src/msgs/data_requests/mod.rs b/crates/common/src/msgs/data_requests/mod.rs index 41f4883..f3f788e 100644 --- a/crates/common/src/msgs/data_requests/mod.rs +++ b/crates/common/src/msgs/data_requests/mod.rs @@ -1,7 +1,3 @@ -use std::collections::HashMap; - -use super::*; - pub mod execute; pub mod query; pub mod sudo; diff --git a/crates/common/src/msgs/data_requests/query.rs b/crates/common/src/msgs/data_requests/query.rs index 2d78e87..24ba87a 100644 --- a/crates/common/src/msgs/data_requests/query.rs +++ b/crates/common/src/msgs/data_requests/query.rs @@ -1,8 +1,11 @@ -use super::*; +#[cfg(feature = "cosmwasm")] +use std::collections::HashMap; -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(feature = "cosmwasm", derive(QueryResponses))] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +use super::types::*; + +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(feature = "cosmwasm", derive(cosmwasm_schema::QueryResponses))] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub enum QueryMsg { #[cfg_attr(feature = "cosmwasm", returns(Option))] @@ -25,7 +28,7 @@ pub enum QueryMsg { }, } -impl From for super::QueryMsg { +impl From for crate::msgs::QueryMsg { fn from(value: QueryMsg) -> Self { Self::DataRequest(value) } diff --git a/crates/common/src/msgs/data_requests/query_tests.rs b/crates/common/src/msgs/data_requests/query_tests.rs index 82ef6c3..4256d2d 100644 --- a/crates/common/src/msgs/data_requests/query_tests.rs +++ b/crates/common/src/msgs/data_requests/query_tests.rs @@ -1,6 +1,6 @@ use serde_json::json; -use super::{data_requests::DataRequestStatus, query::QueryMsg as DrQueryMsg, QueryMsg}; +use super::{query::QueryMsg as DrQueryMsg, DataRequestStatus}; use crate::msgs::*; #[test] diff --git a/crates/common/src/msgs/data_requests/sudo/mod.rs b/crates/common/src/msgs/data_requests/sudo/mod.rs index d0de3a2..2d7b75a 100644 --- a/crates/common/src/msgs/data_requests/sudo/mod.rs +++ b/crates/common/src/msgs/data_requests/sudo/mod.rs @@ -1,9 +1,9 @@ -use super::*; +use super::DataResult; pub mod expire_data_requests; pub mod post_results; -#[cfg_attr(feature = "cosmwasm", cw_serde)] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] #[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct PostResult { @@ -18,7 +18,7 @@ impl From for crate::msgs::SudoMsg { } } -#[cfg_attr(feature = "cosmwasm", cw_serde)] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] #[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub enum SudoMsg { @@ -27,7 +27,7 @@ pub enum SudoMsg { ExpireDataRequests(expire_data_requests::Sudo), } -impl From for super::SudoMsg { +impl From for crate::msgs::SudoMsg { fn from(value: SudoMsg) -> Self { Self::DataRequest(value) } diff --git a/crates/common/src/msgs/data_requests/sudo/post_results.rs b/crates/common/src/msgs/data_requests/sudo/post_results.rs index 281d779..b0ce2bc 100644 --- a/crates/common/src/msgs/data_requests/sudo/post_results.rs +++ b/crates/common/src/msgs/data_requests/sudo/post_results.rs @@ -1,6 +1,6 @@ -use super::*; +use super::PostResult; -#[cfg_attr(feature = "cosmwasm", cw_serde)] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] #[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Sudo { diff --git a/crates/common/src/msgs/data_requests/sudo_tests.rs b/crates/common/src/msgs/data_requests/sudo_tests.rs index 4e0417e..53144cc 100644 --- a/crates/common/src/msgs/data_requests/sudo_tests.rs +++ b/crates/common/src/msgs/data_requests/sudo_tests.rs @@ -1,10 +1,12 @@ use semver::Version; use serde_json::json; +use super::{sudo::*, DataResult}; +use crate::msgs; +#[cfg(not(feature = "cosmwasm"))] +use crate::msgs::assert_json_ser; #[cfg(feature = "cosmwasm")] -use super::Bytes; -use super::{sudo::*, DataResult, SudoMsg}; -use crate::msgs::*; +use crate::{msgs::assert_json_deser, types::Bytes}; #[test] fn json_post_result() { @@ -52,7 +54,7 @@ fn json_post_result() { "exit_code": 0, } }); - let msg: SudoMsg = PostResult { + let msg: msgs::SudoMsg = PostResult { dr_id: "dr_id".to_string(), result, exit_code: 0, @@ -67,7 +69,7 @@ fn json_post_result() { #[test] fn json_remove_timed_out_data_requests() { let expected_json = json!({"expire_data_requests": {}}); - let msg: SudoMsg = expire_data_requests::Sudo {}.into(); + let msg: msgs::SudoMsg = expire_data_requests::Sudo {}.into(); #[cfg(not(feature = "cosmwasm"))] assert_json_ser(msg, expected_json); #[cfg(feature = "cosmwasm")] diff --git a/crates/common/src/msgs/data_requests/types.rs b/crates/common/src/msgs/data_requests/types.rs index 13eb9b2..1d54a42 100644 --- a/crates/common/src/msgs/data_requests/types.rs +++ b/crates/common/src/msgs/data_requests/types.rs @@ -1,13 +1,17 @@ +use std::collections::HashMap; + #[cfg(not(feature = "cosmwasm"))] use base64::{prelude::BASE64_STANDARD, Engine}; #[cfg(feature = "cosmwasm")] use cw_storage_plus::{Key, Prefixer, PrimaryKey}; use semver::Version; +#[cfg(not(feature = "cosmwasm"))] +use serde::{Deserialize, Serialize}; use sha3::{Digest, Keccak256}; -use super::*; +use crate::{error::Result, types::*}; -#[cfg_attr(feature = "cosmwasm", cw_serde)] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] #[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub enum DataRequestStatus { @@ -40,7 +44,7 @@ impl<'a> Prefixer<'a> for DataRequestStatus { } /// Represents a data request at creation time -#[cfg_attr(feature = "cosmwasm", cw_serde)] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] #[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Deserialize, Clone, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct DataRequest { @@ -110,7 +114,7 @@ impl DataRequest { } /// Represents a resolved data result -#[cfg_attr(feature = "cosmwasm", cw_serde)] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] #[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Deserialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct DataResult { @@ -190,7 +194,7 @@ impl TryHashSelf for DataResult { } /// A revealed data request result that is hashed and signed by the executor -#[cfg_attr(feature = "cosmwasm", cw_serde)] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] #[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Deserialize, Clone, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct RevealBody { @@ -227,7 +231,7 @@ impl TryHashSelf for RevealBody { } } -#[cfg_attr(feature = "cosmwasm", cw_serde)] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] #[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct PostDataRequestArgs { @@ -299,7 +303,7 @@ impl TryHashSelf for PostDataRequestArgs { } /// Governance-controlled timeout configuration parameters -#[cfg_attr(feature = "cosmwasm", cw_serde)] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] #[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Deserialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct TimeoutConfig { diff --git a/crates/common/src/msgs/data_requests/types_tests.rs b/crates/common/src/msgs/data_requests/types_tests.rs index 540d36e..86ae97e 100644 --- a/crates/common/src/msgs/data_requests/types_tests.rs +++ b/crates/common/src/msgs/data_requests/types_tests.rs @@ -2,10 +2,10 @@ use std::collections::HashMap; use serde_json::json; +use super::{DataRequest, DataResult, PostDataRequestArgs, RevealBody, TimeoutConfig}; #[cfg(feature = "cosmwasm")] -use super::Bytes; -use super::{DataRequest, DataResult, HashSelf, PostDataRequestArgs, RevealBody, TimeoutConfig, U128}; -use crate::msgs::*; +use crate::msgs::assert_json_deser; +use crate::{msgs::assert_json_ser, types::*}; #[test] fn json_data_request() { diff --git a/crates/common/src/msgs/mod.rs b/crates/common/src/msgs/mod.rs index a9f732d..fb31702 100644 --- a/crates/common/src/msgs/mod.rs +++ b/crates/common/src/msgs/mod.rs @@ -1,9 +1,5 @@ -#[cfg(feature = "cosmwasm")] -use cosmwasm_schema::{cw_serde, QueryResponses}; #[cfg(not(feature = "cosmwasm"))] -use serde::{Deserialize, Serialize}; - -use crate::{crypto::hash, error::*, types::*}; +use serde::Serialize; pub mod data_requests; pub mod owner; @@ -14,7 +10,7 @@ mod assert_json; #[cfg(test)] pub use assert_json::*; -#[cfg_attr(feature = "cosmwasm", cw_serde)] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] #[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] #[serde(untagged)] @@ -25,10 +21,10 @@ pub enum ExecuteMsg { } // https://github.com/CosmWasm/cosmwasm/issues/2030 -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(feature = "cosmwasm", derive(QueryResponses))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(feature = "cosmwasm", derive(cosmwasm_schema::QueryResponses))] #[cfg_attr(feature = "cosmwasm", query_responses(nested))] -#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] +#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] #[serde(untagged)] pub enum QueryMsg { @@ -37,15 +33,15 @@ pub enum QueryMsg { Owner(owner::query::QueryMsg), } -#[cfg_attr(feature = "cosmwasm", cw_serde)] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] pub struct InstantiateMsg { pub token: String, pub owner: String, pub chain_id: String, } -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] #[serde(untagged)] pub enum SudoMsg { diff --git a/crates/common/src/msgs/owner/execute/accept_ownership.rs b/crates/common/src/msgs/owner/execute/accept_ownership.rs index 6e2676f..9eb2e21 100644 --- a/crates/common/src/msgs/owner/execute/accept_ownership.rs +++ b/crates/common/src/msgs/owner/execute/accept_ownership.rs @@ -1,7 +1,5 @@ -use super::*; - -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Execute {} diff --git a/crates/common/src/msgs/owner/execute/add_to_allowlist.rs b/crates/common/src/msgs/owner/execute/add_to_allowlist.rs index 42c1d68..32c490e 100644 --- a/crates/common/src/msgs/owner/execute/add_to_allowlist.rs +++ b/crates/common/src/msgs/owner/execute/add_to_allowlist.rs @@ -1,7 +1,5 @@ -use super::*; - -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Execute { /// The public key of the person. diff --git a/crates/common/src/msgs/owner/execute/mod.rs b/crates/common/src/msgs/owner/execute/mod.rs index 959c1a5..2a2ea95 100644 --- a/crates/common/src/msgs/owner/execute/mod.rs +++ b/crates/common/src/msgs/owner/execute/mod.rs @@ -1,12 +1,10 @@ -use super::*; - pub mod accept_ownership; pub mod add_to_allowlist; pub mod remove_from_allowlist; pub mod transfer_ownership; -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub enum ExecuteMsg { TransferOwnership(transfer_ownership::Execute), @@ -17,7 +15,7 @@ pub enum ExecuteMsg { RemoveFromAllowlist(remove_from_allowlist::Execute), } -impl From for super::ExecuteMsg { +impl From for crate::msgs::ExecuteMsg { fn from(value: ExecuteMsg) -> Self { Self::Owner(value) } diff --git a/crates/common/src/msgs/owner/execute/remove_from_allowlist.rs b/crates/common/src/msgs/owner/execute/remove_from_allowlist.rs index eecd3b3..4c096dd 100644 --- a/crates/common/src/msgs/owner/execute/remove_from_allowlist.rs +++ b/crates/common/src/msgs/owner/execute/remove_from_allowlist.rs @@ -1,7 +1,5 @@ -use super::*; - -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Execute { /// The public key of the person. diff --git a/crates/common/src/msgs/owner/execute/transfer_ownership.rs b/crates/common/src/msgs/owner/execute/transfer_ownership.rs index 7758c43..66cc065 100644 --- a/crates/common/src/msgs/owner/execute/transfer_ownership.rs +++ b/crates/common/src/msgs/owner/execute/transfer_ownership.rs @@ -1,7 +1,5 @@ -use super::*; - -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Execute { pub new_owner: String, diff --git a/crates/common/src/msgs/owner/execute_tests.rs b/crates/common/src/msgs/owner/execute_tests.rs index efb54f1..6167315 100644 --- a/crates/common/src/msgs/owner/execute_tests.rs +++ b/crates/common/src/msgs/owner/execute_tests.rs @@ -1,7 +1,11 @@ use serde_json::json; -use super::{execute::*, ExecuteMsg}; -use crate::msgs::*; +use super::execute::*; +use crate::msgs; +#[cfg(feature = "cosmwasm")] +use crate::msgs::assert_json_deser; +#[cfg(not(feature = "cosmwasm"))] +use crate::msgs::assert_json_ser; #[test] fn json_accept_ownership() { @@ -9,7 +13,7 @@ fn json_accept_ownership() { { "accept_ownership": {} }); - let msg: ExecuteMsg = accept_ownership::Execute {}.into(); + let msg: msgs::ExecuteMsg = accept_ownership::Execute {}.into(); #[cfg(not(feature = "cosmwasm"))] assert_json_ser(msg, expected_json); #[cfg(feature = "cosmwasm")] @@ -23,7 +27,7 @@ fn json_add_to_allowlist() { "public_key": "public_key" } }); - let msg: ExecuteMsg = add_to_allowlist::Execute { + let msg: msgs::ExecuteMsg = add_to_allowlist::Execute { public_key: "public_key".to_string(), } .into(); @@ -40,7 +44,7 @@ fn json_remove_from_allowlist() { "public_key": "public_key" } }); - let msg: ExecuteMsg = remove_from_allowlist::Execute { + let msg: msgs::ExecuteMsg = remove_from_allowlist::Execute { public_key: "public_key".to_string(), } .into(); @@ -57,7 +61,7 @@ fn json_transfer_ownership() { "new_owner": "new_owner" } }); - let msg: ExecuteMsg = transfer_ownership::Execute { + let msg: msgs::ExecuteMsg = transfer_ownership::Execute { new_owner: "new_owner".to_string(), } .into(); diff --git a/crates/common/src/msgs/owner/mod.rs b/crates/common/src/msgs/owner/mod.rs index bfe97a4..d0d7867 100644 --- a/crates/common/src/msgs/owner/mod.rs +++ b/crates/common/src/msgs/owner/mod.rs @@ -1,8 +1,6 @@ pub mod execute; pub mod query; -use super::*; - #[path = ""] #[cfg(test)] mod test { diff --git a/crates/common/src/msgs/owner/query.rs b/crates/common/src/msgs/owner/query.rs index 7fb62aa..3717775 100644 --- a/crates/common/src/msgs/owner/query.rs +++ b/crates/common/src/msgs/owner/query.rs @@ -1,8 +1,6 @@ -use super::*; - -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(feature = "cosmwasm", derive(QueryResponses))] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(feature = "cosmwasm", derive(cosmwasm_schema::QueryResponses))] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub enum QueryMsg { #[cfg_attr(feature = "cosmwasm", returns(cosmwasm_std::Addr))] @@ -11,7 +9,7 @@ pub enum QueryMsg { GetPendingOwner {}, } -impl From for super::QueryMsg { +impl From for crate::msgs::QueryMsg { fn from(value: QueryMsg) -> Self { Self::Owner(value) } diff --git a/crates/common/src/msgs/owner/query_tests.rs b/crates/common/src/msgs/owner/query_tests.rs index 4cf94ae..0f431fd 100644 --- a/crates/common/src/msgs/owner/query_tests.rs +++ b/crates/common/src/msgs/owner/query_tests.rs @@ -1,15 +1,18 @@ use serde_json::json; -use super::{query::QueryMsg as OwnerQueryMsg, QueryMsg}; -use crate::msgs::*; - +use super::query::QueryMsg as OwnerQueryMsg; +use crate::msgs; +#[cfg(feature = "cosmwasm")] +use crate::msgs::assert_json_deser; +#[cfg(not(feature = "cosmwasm"))] +use crate::msgs::assert_json_ser; #[test] fn json_get_owner() { let expected_json = json!( { "get_owner": {} }); - let msg: QueryMsg = OwnerQueryMsg::GetOwner {}.into(); + let msg: msgs::QueryMsg = OwnerQueryMsg::GetOwner {}.into(); #[cfg(not(feature = "cosmwasm"))] assert_json_ser(msg, expected_json); #[cfg(feature = "cosmwasm")] @@ -22,7 +25,7 @@ fn json_get_pending_owner() { { "get_pending_owner": {} }); - let msg: QueryMsg = OwnerQueryMsg::GetPendingOwner {}.into(); + let msg: msgs::QueryMsg = OwnerQueryMsg::GetPendingOwner {}.into(); #[cfg(not(feature = "cosmwasm"))] assert_json_ser(msg, expected_json); #[cfg(feature = "cosmwasm")] diff --git a/crates/common/src/msgs/staking/execute/mod.rs b/crates/common/src/msgs/staking/execute/mod.rs index 8040d85..6902cf4 100644 --- a/crates/common/src/msgs/staking/execute/mod.rs +++ b/crates/common/src/msgs/staking/execute/mod.rs @@ -1,11 +1,11 @@ -use super::*; +use super::StakingConfig; pub mod stake; pub mod unstake; pub mod withdraw; -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub enum ExecuteMsg { Stake(stake::Execute), @@ -14,7 +14,7 @@ pub enum ExecuteMsg { SetStakingConfig(StakingConfig), } -impl From for super::ExecuteMsg { +impl From for crate::msgs::ExecuteMsg { fn from(value: ExecuteMsg) -> Self { Self::Staking(value) } diff --git a/crates/common/src/msgs/staking/execute/stake.rs b/crates/common/src/msgs/staking/execute/stake.rs index 0eb169d..f739d61 100644 --- a/crates/common/src/msgs/staking/execute/stake.rs +++ b/crates/common/src/msgs/staking/execute/stake.rs @@ -1,7 +1,7 @@ -use super::*; +use crate::{error::Result, types::*}; -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Execute { pub public_key: String, @@ -11,7 +11,7 @@ pub struct Execute { impl Execute { fn generate_hash(memo: Option<&Bytes>, chain_id: &str, contract_addr: &str, sequence: U128) -> Hash { - hash([ + crate::crypto::hash([ "stake".as_bytes(), &memo.hash(), chain_id.as_bytes(), diff --git a/crates/common/src/msgs/staking/execute/unstake.rs b/crates/common/src/msgs/staking/execute/unstake.rs index b535b56..cef565a 100644 --- a/crates/common/src/msgs/staking/execute/unstake.rs +++ b/crates/common/src/msgs/staking/execute/unstake.rs @@ -1,7 +1,7 @@ -use super::*; +use crate::{error::Result, types::*}; -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Execute { pub public_key: String, @@ -11,7 +11,7 @@ pub struct Execute { impl Execute { fn generate_hash(amount: U128, chain_id: &str, contract_addr: &str, sequence: U128) -> Hash { - hash([ + crate::crypto::hash([ "unstake".as_bytes(), &amount.to_be_bytes(), chain_id.as_bytes(), diff --git a/crates/common/src/msgs/staking/execute/withdraw.rs b/crates/common/src/msgs/staking/execute/withdraw.rs index fdd4cf3..d655718 100644 --- a/crates/common/src/msgs/staking/execute/withdraw.rs +++ b/crates/common/src/msgs/staking/execute/withdraw.rs @@ -1,7 +1,7 @@ -use super::*; +use crate::{crypto::hash, error::Result, types::*}; -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, PartialEq, Debug))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, PartialEq, Debug))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Execute { pub public_key: String, diff --git a/crates/common/src/msgs/staking/execute_tests.rs b/crates/common/src/msgs/staking/execute_tests.rs index 7ab2435..493019d 100644 --- a/crates/common/src/msgs/staking/execute_tests.rs +++ b/crates/common/src/msgs/staking/execute_tests.rs @@ -1,7 +1,11 @@ use serde_json::json; -use super::{execute::*, ExecuteMsg, U128}; -use crate::msgs::*; +use super::execute::*; +#[cfg(feature = "cosmwasm")] +use crate::msgs::assert_json_deser; +#[cfg(not(feature = "cosmwasm"))] +use crate::msgs::assert_json_ser; +use crate::{msgs, types::U128}; #[test] fn json_stake() { @@ -12,7 +16,7 @@ fn json_stake() { "public_key": "public", } }); - let msg_no_memo: ExecuteMsg = stake::Execute { + let msg_no_memo: msgs::ExecuteMsg = stake::Execute { public_key: "public".to_string(), proof: "proof".to_string(), memo: None, @@ -35,7 +39,7 @@ fn json_stake() { "memo": memo, } }); - let msg_with_memo: ExecuteMsg = stake::Execute { + let msg_with_memo: msgs::ExecuteMsg = stake::Execute { public_key: "public".to_string(), proof: "proof".to_string(), memo: Some(memo), @@ -57,7 +61,7 @@ fn json_unstake() { "amount": amount.to_string(), } }); - let msg: ExecuteMsg = unstake::Execute { + let msg: msgs::ExecuteMsg = unstake::Execute { public_key: "public".to_string(), proof: "proof".to_string(), amount, @@ -79,7 +83,7 @@ fn json_withdraw() { "amount": amount.to_string(), } }); - let msg: ExecuteMsg = withdraw::Execute { + let msg: msgs::ExecuteMsg = withdraw::Execute { public_key: "public".to_string(), proof: "proof".to_string(), amount, diff --git a/crates/common/src/msgs/staking/mod.rs b/crates/common/src/msgs/staking/mod.rs index 9487403..93cebc4 100644 --- a/crates/common/src/msgs/staking/mod.rs +++ b/crates/common/src/msgs/staking/mod.rs @@ -4,8 +4,6 @@ pub mod query; mod types; pub use types::*; -use super::*; - #[path = ""] #[cfg(test)] mod test { diff --git a/crates/common/src/msgs/staking/query/is_executor_eligible.rs b/crates/common/src/msgs/staking/query/is_executor_eligible.rs index 330804a..a6abd4b 100644 --- a/crates/common/src/msgs/staking/query/is_executor_eligible.rs +++ b/crates/common/src/msgs/staking/query/is_executor_eligible.rs @@ -1,9 +1,9 @@ use core::str; -use super::*; +use crate::{error::Result, types::*}; -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Query { pub data: Bytes, @@ -11,7 +11,7 @@ pub struct Query { impl Query { fn generate_hash(dr_id: &str, chain_id: &str, contract_addr: &str) -> Hash { - hash([ + crate::crypto::hash([ "is_executor_eligible".as_bytes(), dr_id.as_bytes(), chain_id.as_bytes(), diff --git a/crates/common/src/msgs/staking/query/mod.rs b/crates/common/src/msgs/staking/query/mod.rs index 725cfad..afafc91 100644 --- a/crates/common/src/msgs/staking/query/mod.rs +++ b/crates/common/src/msgs/staking/query/mod.rs @@ -1,10 +1,12 @@ -use super::*; - pub mod is_executor_eligible; +#[cfg(feature = "cosmwasm")] +use super::types::*; +#[cfg(feature = "cosmwasm")] +use crate::types::U128; -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(feature = "cosmwasm", derive(QueryResponses))] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr(feature = "cosmwasm", derive(cosmwasm_schema::QueryResponses))] +#[cfg_attr(not(feature = "cosmwasm"), derive(serde::Serialize, Debug, PartialEq))] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub enum QueryMsg { #[cfg_attr(feature = "cosmwasm", returns(Option))] @@ -21,7 +23,7 @@ pub enum QueryMsg { GetStakingConfig {}, } -impl From for super::QueryMsg { +impl From for crate::msgs::QueryMsg { fn from(value: QueryMsg) -> Self { Self::Staking(value) } diff --git a/crates/common/src/msgs/staking/query_tests.rs b/crates/common/src/msgs/staking/query_tests.rs index 69bef2e..94549a2 100644 --- a/crates/common/src/msgs/staking/query_tests.rs +++ b/crates/common/src/msgs/staking/query_tests.rs @@ -4,14 +4,15 @@ use k256::{ }; use serde_json::json; -use super::{ - query::{ - is_executor_eligible::{self, Query, QueryFactory}, - QueryMsg as StakingQueryMsg, - }, - QueryMsg, +use super::query::{ + is_executor_eligible::{self, Query, QueryFactory}, + QueryMsg as StakingQueryMsg, }; -use crate::{crypto::VRF, msgs::*}; +#[cfg(feature = "cosmwasm")] +use crate::msgs::assert_json_deser; +#[cfg(not(feature = "cosmwasm"))] +use crate::msgs::assert_json_ser; +use crate::{crypto::VRF, msgs, types::*}; #[test] fn json_get_staker() { @@ -20,7 +21,7 @@ fn json_get_staker() { "public_key": "public_key" } }); - let msg: QueryMsg = StakingQueryMsg::GetStaker { + let msg: msgs::QueryMsg = StakingQueryMsg::GetStaker { public_key: "public_key".to_string(), } .into(); @@ -37,7 +38,7 @@ fn json_get_account_seq() { "public_key": "public_key" } }); - let msg: QueryMsg = StakingQueryMsg::GetAccountSeq { + let msg: msgs::QueryMsg = StakingQueryMsg::GetAccountSeq { public_key: "public_key".to_string(), } .into(); @@ -54,7 +55,7 @@ fn json_get_staker_and_seq() { "public_key": "public_key" } }); - let msg: QueryMsg = StakingQueryMsg::GetStakerAndSeq { + let msg: msgs::QueryMsg = StakingQueryMsg::GetStakerAndSeq { public_key: "public_key".to_string(), } .into(); @@ -71,7 +72,7 @@ fn json_is_staker_executor() { "public_key": "public_key", } }); - let msg: QueryMsg = StakingQueryMsg::IsStakerExecutor { + let msg: msgs::QueryMsg = StakingQueryMsg::IsStakerExecutor { public_key: "public_key".to_string(), } .into(); @@ -93,7 +94,7 @@ fn json_is_executor_eligible() { "data": data, } }); - let msg: QueryMsg = is_executor_eligible::Query { data }.into(); + let msg: msgs::QueryMsg = is_executor_eligible::Query { data }.into(); #[cfg(not(feature = "cosmwasm"))] assert_json_ser(msg, expected_json); #[cfg(feature = "cosmwasm")] @@ -105,7 +106,7 @@ fn json_get_staking_config() { let expected_json = json!({ "get_staking_config": {} }); - let msg: QueryMsg = StakingQueryMsg::GetStakingConfig {}.into(); + let msg: msgs::QueryMsg = StakingQueryMsg::GetStakingConfig {}.into(); #[cfg(not(feature = "cosmwasm"))] assert_json_ser(msg, expected_json); #[cfg(feature = "cosmwasm")] diff --git a/crates/common/src/msgs/staking/types.rs b/crates/common/src/msgs/staking/types.rs index e87e14c..1d56c4a 100644 --- a/crates/common/src/msgs/staking/types.rs +++ b/crates/common/src/msgs/staking/types.rs @@ -1,8 +1,11 @@ -use super::*; +use crate::types::{Bytes, U128}; /// A data request executor with staking info and optional p2p multi address -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Deserialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr( + not(feature = "cosmwasm"), + derive(serde::Serialize, serde::Deserialize, Debug, PartialEq) +)] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct Staker { pub memo: Option, @@ -11,8 +14,11 @@ pub struct Staker { } /// Governance-controlled staking configuration parameters -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Deserialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr( + not(feature = "cosmwasm"), + derive(serde::Serialize, serde::Deserialize, Debug, PartialEq) +)] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct StakingConfig { /// Minimum amount of SEDA tokens required to register as a data request executor @@ -29,8 +35,11 @@ impl From for crate::msgs::ExecuteMsg { } } -#[cfg_attr(feature = "cosmwasm", cw_serde)] -#[cfg_attr(not(feature = "cosmwasm"), derive(Serialize, Deserialize, Debug, PartialEq))] +#[cfg_attr(feature = "cosmwasm", cosmwasm_schema::cw_serde)] +#[cfg_attr( + not(feature = "cosmwasm"), + derive(serde::Serialize, serde::Deserialize, Debug, PartialEq) +)] #[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))] pub struct StakerAndSeq { pub staker: Option, diff --git a/crates/common/src/types/hash_self.rs b/crates/common/src/types/hash_self.rs index a24f2d6..74cbbd0 100644 --- a/crates/common/src/types/hash_self.rs +++ b/crates/common/src/types/hash_self.rs @@ -1,5 +1,7 @@ -use super::*; -use crate::error::Result; +use semver::Version; +use sha3::{Digest, Keccak256}; + +use crate::{error::Result, types::Hash}; pub trait TryHashSelf { fn try_hash(&self) -> Result; diff --git a/crates/common/src/types/mod.rs b/crates/common/src/types/mod.rs index f8f1827..d8b5429 100644 --- a/crates/common/src/types/mod.rs +++ b/crates/common/src/types/mod.rs @@ -1,6 +1,3 @@ -use semver::Version; -use sha3::{Digest, Keccak256}; - mod to_hex; pub use to_hex::ToHexStr; diff --git a/crates/common/src/types/verify_self.rs b/crates/common/src/types/verify_self.rs index 783a33f..acffa10 100644 --- a/crates/common/src/types/verify_self.rs +++ b/crates/common/src/types/verify_self.rs @@ -1,5 +1,4 @@ -use super::*; -use crate::{crypto::verify_proof, error::Result}; +use crate::{crypto::verify_proof, error::Result, types::Hash}; pub(crate) trait VerifySelf { type Extra;