Skip to content

Commit

Permalink
refactor(common): Clippy was very angry
Browse files Browse the repository at this point in the history
  • Loading branch information
gluax committed Oct 8, 2024
1 parent c60d3da commit f36bfc2
Show file tree
Hide file tree
Showing 38 changed files with 183 additions and 170 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
13 changes: 9 additions & 4 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
8 changes: 4 additions & 4 deletions crates/common/src/msgs/data_requests/execute/commit_result.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions crates/common/src/msgs/data_requests/execute/mod.rs
Original file line number Diff line number Diff line change
@@ -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),
Expand All @@ -14,7 +14,7 @@ pub enum ExecuteMsg {
SetTimeoutConfig(TimeoutConfig),
}

impl From<ExecuteMsg> for super::ExecuteMsg {
impl From<ExecuteMsg> for crate::msgs::ExecuteMsg {
fn from(value: ExecuteMsg) -> Self {
Self::DataRequest(Box::new(value))
}
Expand Down
6 changes: 3 additions & 3 deletions crates/common/src/msgs/data_requests/execute/post_request.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 4 additions & 4 deletions crates/common/src/msgs/data_requests/execute/reveal_result.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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(),
Expand Down
14 changes: 8 additions & 6 deletions crates/common/src/msgs/data_requests/execute_tests.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 0 additions & 4 deletions crates/common/src/msgs/data_requests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use std::collections::HashMap;

use super::*;

pub mod execute;
pub mod query;
pub mod sudo;
Expand Down
13 changes: 8 additions & 5 deletions crates/common/src/msgs/data_requests/query.rs
Original file line number Diff line number Diff line change
@@ -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<DataRequest>))]
Expand All @@ -25,7 +28,7 @@ pub enum QueryMsg {
},
}

impl From<QueryMsg> for super::QueryMsg {
impl From<QueryMsg> for crate::msgs::QueryMsg {
fn from(value: QueryMsg) -> Self {
Self::DataRequest(value)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/msgs/data_requests/query_tests.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
8 changes: 4 additions & 4 deletions crates/common/src/msgs/data_requests/sudo/mod.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -18,7 +18,7 @@ impl From<PostResult> 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 {
Expand All @@ -27,7 +27,7 @@ pub enum SudoMsg {
ExpireDataRequests(expire_data_requests::Sudo),
}

impl From<SudoMsg> for super::SudoMsg {
impl From<SudoMsg> for crate::msgs::SudoMsg {
fn from(value: SudoMsg) -> Self {
Self::DataRequest(value)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/msgs/data_requests/sudo/post_results.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions crates/common/src/msgs/data_requests/sudo_tests.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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,
Expand All @@ -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")]
Expand Down
18 changes: 11 additions & 7 deletions crates/common/src/msgs/data_requests/types.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions crates/common/src/msgs/data_requests/types_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit f36bfc2

Please sign in to comment.