From 703b47ab1eaa28b3becb330867e9864975aab95b Mon Sep 17 00:00:00 2001 From: Shoaib Ahmed Date: Tue, 7 May 2024 15:34:09 -0700 Subject: [PATCH] Reformat repo with nightly rustfmt (#25) --- bisenzone-cw-mvp/.github/workflows/Basic.yml | 24 ++++++---- .../contracts/cw-tee-mtcs/src/bin/schema.rs | 1 - .../contracts/cw-tee-mtcs/src/contract.rs | 47 ++++++++++--------- .../contracts/cw-tee-mtcs/src/msg.rs | 3 +- .../packages/quartz-cw/src/handler.rs | 17 ++++--- .../packages/quartz-cw/src/handler/execute.rs | 13 +++-- .../quartz-cw/src/handler/execute/attested.rs | 12 +++-- .../src/handler/execute/session_create.rs | 10 ++-- .../handler/execute/session_set_pub_key.rs | 8 ++-- .../quartz-cw/src/handler/instantiate.rs | 15 +++--- .../packages/quartz-cw/src/msg.rs | 3 +- .../packages/quartz-cw/src/msg/execute.rs | 13 +++-- .../quartz-cw/src/msg/execute/attested.rs | 6 ++- .../src/msg/execute/session_create.rs | 7 +-- .../src/msg/execute/session_set_pub_key.rs | 9 ++-- .../packages/quartz-cw/src/msg/instantiate.rs | 12 +++-- .../packages/quartz-cw/src/prelude.rs | 10 ++-- .../src/intel_sgx/epid/verifier.rs | 8 ++-- .../packages/quartz-tee-ra/src/lib.rs | 7 +-- 19 files changed, 131 insertions(+), 94 deletions(-) diff --git a/bisenzone-cw-mvp/.github/workflows/Basic.yml b/bisenzone-cw-mvp/.github/workflows/Basic.yml index 4b0121f..7b69ff3 100644 --- a/bisenzone-cw-mvp/.github/workflows/Basic.yml +++ b/bisenzone-cw-mvp/.github/workflows/Basic.yml @@ -1,6 +1,6 @@ # Based on https://github.com/actions-rs/example/blob/master/.github/workflows/quickstart.yml -on: [push, pull_request] +on: [ push, pull_request ] name: Basic @@ -48,16 +48,10 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.73.0 + toolchain: stable override: true components: rustfmt, clippy - - name: Run cargo fmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - name: Run cargo clippy uses: actions-rs/cargo@v1 with: @@ -79,3 +73,17 @@ jobs: - name: Schema Changes # fails if any changes not committed run: git diff --exit-code schema + + - name: Install nighly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: rustfmt + + - name: Run cargo nightly fmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check \ No newline at end of file diff --git a/bisenzone-cw-mvp/contracts/cw-tee-mtcs/src/bin/schema.rs b/bisenzone-cw-mvp/contracts/cw-tee-mtcs/src/bin/schema.rs index 353dd79..c80c69f 100644 --- a/bisenzone-cw-mvp/contracts/cw-tee-mtcs/src/bin/schema.rs +++ b/bisenzone-cw-mvp/contracts/cw-tee-mtcs/src/bin/schema.rs @@ -1,5 +1,4 @@ use cosmwasm_schema::write_api; - use cw_tee_mtcs::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; fn main() { diff --git a/bisenzone-cw-mvp/contracts/cw-tee-mtcs/src/contract.rs b/bisenzone-cw-mvp/contracts/cw-tee-mtcs/src/contract.rs index a6049f6..79d9dc2 100644 --- a/bisenzone-cw-mvp/contracts/cw-tee-mtcs/src/contract.rs +++ b/bisenzone-cw-mvp/contracts/cw-tee-mtcs/src/contract.rs @@ -3,17 +3,20 @@ use cosmwasm_std::{ Uint128, }; use cw2::set_contract_version; -use cw20_base::contract::execute_mint; -use cw20_base::contract::query_balance as cw20_query_balance; -use cw20_base::state::{MinterData, TokenInfo, TOKEN_INFO}; -use quartz_cw::handler::RawHandler; -use quartz_cw::state::EPOCH_COUNTER; +use cw20_base::{ + contract::{execute_mint, query_balance as cw20_query_balance}, + state::{MinterData, TokenInfo, TOKEN_INFO}, +}; +use quartz_cw::{handler::RawHandler, state::EPOCH_COUNTER}; -use crate::error::ContractError; -use crate::msg::execute::{SubmitObligationMsg, SubmitObligationsMsg, SubmitSetoffsMsg}; -use crate::msg::QueryMsg; -use crate::msg::{ExecuteMsg, InstantiateMsg}; -use crate::state::{current_epoch_key, ObligationsItem, State, OBLIGATIONS_KEY, STATE}; +use crate::{ + error::ContractError, + msg::{ + execute::{SubmitObligationMsg, SubmitObligationsMsg, SubmitSetoffsMsg}, + ExecuteMsg, InstantiateMsg, QueryMsg, + }, + state::{current_epoch_key, ObligationsItem, State, OBLIGATIONS_KEY, STATE}, +}; // version info for migration info const CONTRACT_NAME: &str = "crates.io:cw-tee-mtcs"; @@ -118,14 +121,15 @@ pub mod execute { use cosmwasm_std::{DepsMut, Env, HexBinary, MessageInfo, Response, StdResult}; use cw20_base::contract::{execute_burn, execute_mint}; - use quartz_cw::state::Hash; - use quartz_cw::state::EPOCH_COUNTER; + use quartz_cw::state::{Hash, EPOCH_COUNTER}; - use crate::state::{ - current_epoch_key, previous_epoch_key, ObligationsItem, RawHash, SetoffsItem, SettleOff, - OBLIGATIONS_KEY, SETOFFS_KEY, + use crate::{ + state::{ + current_epoch_key, previous_epoch_key, ObligationsItem, RawHash, SetoffsItem, + SettleOff, OBLIGATIONS_KEY, SETOFFS_KEY, + }, + ContractError, }; - use crate::ContractError; pub fn submit_obligation( deps: DepsMut, @@ -207,13 +211,12 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { } pub mod query { - use cosmwasm_std::Deps; - use cosmwasm_std::StdResult; + use cosmwasm_std::{Deps, StdResult}; - use crate::msg::GetAllSetoffsResponse; - use crate::state::previous_epoch_key; - use crate::state::SetoffsItem; - use crate::state::SETOFFS_KEY; + use crate::{ + msg::GetAllSetoffsResponse, + state::{previous_epoch_key, SetoffsItem, SETOFFS_KEY}, + }; pub fn get_all_setoffs(deps: Deps) -> StdResult { let setoffs = SetoffsItem::new(&previous_epoch_key(SETOFFS_KEY, deps.storage)?) diff --git a/bisenzone-cw-mvp/contracts/cw-tee-mtcs/src/msg.rs b/bisenzone-cw-mvp/contracts/cw-tee-mtcs/src/msg.rs index b2a356a..4592184 100644 --- a/bisenzone-cw-mvp/contracts/cw-tee-mtcs/src/msg.rs +++ b/bisenzone-cw-mvp/contracts/cw-tee-mtcs/src/msg.rs @@ -4,8 +4,7 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::HexBinary; use quartz_cw::prelude::*; -use crate::state::RawHash; -use crate::state::SettleOff; +use crate::state::{RawHash, SettleOff}; #[cw_serde] pub struct InstantiateMsg(pub QuartzInstantiateMsg); diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/handler.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/handler.rs index c7acbf8..386ba8b 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/handler.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/handler.rs @@ -3,8 +3,7 @@ pub mod instantiate; use cosmwasm_std::{DepsMut, Env, MessageInfo, Response}; -use crate::error::Error; -use crate::msg::HasDomainType; +use crate::{error::Error, msg::HasDomainType}; pub trait Handler { fn handle(self, deps: DepsMut<'_>, env: &Env, info: &MessageInfo) -> Result; @@ -37,13 +36,17 @@ where #[cfg(test)] mod tests { - use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; - use cosmwasm_std::DepsMut; + use cosmwasm_std::{ + testing::{mock_dependencies, mock_env, mock_info}, + DepsMut, + }; use serde::Deserialize; - use crate::handler::Handler; - use crate::msg::{HasDomainType, RawExecuteMsg, RawInstantiateMsg}; - use crate::state::SESSION; + use crate::{ + handler::Handler, + msg::{HasDomainType, RawExecuteMsg, RawInstantiateMsg}, + state::SESSION, + }; fn parse_msg<'a, R>(msg_str: &'a str) -> R::DomainType where diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute.rs index b0d4d99..c332ac9 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute.rs @@ -4,11 +4,14 @@ pub mod session_set_pub_key; use cosmwasm_std::{DepsMut, Env, MessageInfo, Response}; -use crate::error::Error; -use crate::handler::Handler; -use crate::msg::execute::attested::Attestation; -use crate::msg::execute::attested::HasUserData; -use crate::msg::execute::Execute; +use crate::{ + error::Error, + handler::Handler, + msg::execute::{ + attested::{Attestation, HasUserData}, + Execute, + }, +}; impl Handler for Execute where diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute/attested.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute/attested.rs index 3da23da..f49d1aa 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute/attested.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute/attested.rs @@ -1,12 +1,14 @@ use cosmwasm_std::{DepsMut, Env, MessageInfo, Response}; use quartz_tee_ra::{verify_epid_attestation, Error as RaVerificationError}; -use crate::error::Error; -use crate::handler::Handler; -use crate::msg::execute::attested::{ - Attestation, Attested, EpidAttestation, HasUserData, MockAttestation, +use crate::{ + error::Error, + handler::Handler, + msg::execute::attested::{ + Attestation, Attested, EpidAttestation, HasUserData, MockAttestation, + }, + state::CONFIG, }; -use crate::state::CONFIG; impl Handler for EpidAttestation { fn handle( diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute/session_create.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute/session_create.rs index 5144734..cd182a7 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute/session_create.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute/session_create.rs @@ -1,9 +1,11 @@ use cosmwasm_std::{DepsMut, Env, MessageInfo, Response}; -use crate::error::Error; -use crate::handler::Handler; -use crate::msg::execute::session_create::SessionCreate; -use crate::state::{Session, SESSION}; +use crate::{ + error::Error, + handler::Handler, + msg::execute::session_create::SessionCreate, + state::{Session, SESSION}, +}; impl Handler for SessionCreate { fn handle(self, deps: DepsMut<'_>, _env: &Env, _info: &MessageInfo) -> Result { diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute/session_set_pub_key.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute/session_set_pub_key.rs index 865dff0..ddebe9e 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute/session_set_pub_key.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/handler/execute/session_set_pub_key.rs @@ -1,9 +1,9 @@ use cosmwasm_std::{DepsMut, Env, HexBinary, MessageInfo, Response}; -use crate::error::Error; -use crate::handler::Handler; -use crate::msg::execute::session_set_pub_key::SessionSetPubKey; -use crate::state::SESSION; +use crate::{ + error::Error, handler::Handler, msg::execute::session_set_pub_key::SessionSetPubKey, + state::SESSION, +}; impl Handler for SessionSetPubKey { fn handle(self, deps: DepsMut<'_>, _env: &Env, _info: &MessageInfo) -> Result { diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/handler/instantiate.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/handler/instantiate.rs index e59419b..3804bc0 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/handler/instantiate.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/handler/instantiate.rs @@ -1,12 +1,15 @@ use cosmwasm_std::{DepsMut, Env, MessageInfo, Response}; use quartz_tee_ra::Error as RaVerificationError; -use crate::error::Error; -use crate::handler::Handler; -use crate::msg::execute::attested::{Attestation, EpidAttestation, MockAttestation}; -use crate::msg::instantiate::{CoreInstantiate, Instantiate}; -use crate::state::CONFIG; -use crate::state::{RawConfig, EPOCH_COUNTER}; +use crate::{ + error::Error, + handler::Handler, + msg::{ + execute::attested::{Attestation, EpidAttestation, MockAttestation}, + instantiate::{CoreInstantiate, Instantiate}, + }, + state::{RawConfig, CONFIG, EPOCH_COUNTER}, +}; impl Handler for Instantiate { fn handle(self, deps: DepsMut<'_>, env: &Env, info: &MessageInfo) -> Result { diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/msg.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/msg.rs index 8b8864b..4b440f8 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/msg.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/msg.rs @@ -2,11 +2,10 @@ pub mod execute; pub mod instantiate; pub mod query; +use cosmwasm_std::StdError; pub use execute::{Execute as ExecuteMsg, RawExecute as RawExecuteMsg}; pub use instantiate::{Instantiate as InstantiateMsg, RawInstantiate as RawInstantiateMsg}; -use cosmwasm_std::StdError; - pub trait HasDomainType: From { type DomainType: TryFrom; } diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute.rs index f6f1ed1..b95fc4e 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute.rs @@ -5,11 +5,14 @@ pub mod session_set_pub_key; use cosmwasm_schema::cw_serde; use cosmwasm_std::StdError; -use crate::msg::execute::attested::{Attested, EpidAttestation}; -use crate::msg::execute::attested::{RawAttested, RawEpidAttestation}; -use crate::msg::execute::session_create::{RawSessionCreate, SessionCreate}; -use crate::msg::execute::session_set_pub_key::{RawSessionSetPubKey, SessionSetPubKey}; -use crate::msg::HasDomainType; +use crate::msg::{ + execute::{ + attested::{Attested, EpidAttestation, RawAttested, RawEpidAttestation}, + session_create::{RawSessionCreate, SessionCreate}, + session_set_pub_key::{RawSessionSetPubKey, SessionSetPubKey}, + }, + HasDomainType, +}; #[derive(Clone, Debug, PartialEq)] pub enum Execute { diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute/attested.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute/attested.rs index 31de243..125abf6 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute/attested.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute/attested.rs @@ -2,8 +2,10 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::StdError; use quartz_tee_ra::IASReport; -use crate::msg::HasDomainType; -use crate::state::{MrEnclave, UserData}; +use crate::{ + msg::HasDomainType, + state::{MrEnclave, UserData}, +}; #[derive(Clone, Debug, PartialEq)] pub struct Attested { diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute/session_create.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute/session_create.rs index 7603555..99aa545 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute/session_create.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute/session_create.rs @@ -1,9 +1,10 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::{HexBinary, StdError}; -use crate::msg::execute::attested::HasUserData; -use crate::msg::HasDomainType; -use crate::state::{Nonce, UserData}; +use crate::{ + msg::{execute::attested::HasUserData, HasDomainType}, + state::{Nonce, UserData}, +}; #[derive(Clone, Debug, PartialEq)] pub struct SessionCreate { diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute/session_set_pub_key.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute/session_set_pub_key.rs index 47b3c34..9f857f2 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute/session_set_pub_key.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/msg/execute/session_set_pub_key.rs @@ -3,10 +3,11 @@ use cosmwasm_std::{HexBinary, StdError}; use k256::ecdsa::VerifyingKey; use sha2::{Digest, Sha256}; -use crate::error::Error; -use crate::msg::execute::attested::HasUserData; -use crate::msg::HasDomainType; -use crate::state::{Nonce, UserData}; +use crate::{ + error::Error, + msg::{execute::attested::HasUserData, HasDomainType}, + state::{Nonce, UserData}, +}; #[derive(Clone, Debug, PartialEq)] pub struct SessionSetPubKey { diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/msg/instantiate.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/msg/instantiate.rs index 6f2c2ef..6b47169 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/msg/instantiate.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/msg/instantiate.rs @@ -2,11 +2,15 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::StdError; use sha2::{Digest, Sha256}; -use crate::msg::execute::attested::{ - Attested, EpidAttestation, HasUserData, RawAttested, RawEpidAttestation, +use crate::{ + msg::{ + execute::attested::{ + Attested, EpidAttestation, HasUserData, RawAttested, RawEpidAttestation, + }, + HasDomainType, + }, + state::{Config, RawConfig, UserData}, }; -use crate::msg::HasDomainType; -use crate::state::{Config, RawConfig, UserData}; #[derive(Clone, Debug, PartialEq)] pub struct Instantiate(pub Attested); diff --git a/bisenzone-cw-mvp/packages/quartz-cw/src/prelude.rs b/bisenzone-cw-mvp/packages/quartz-cw/src/prelude.rs index b998726..d938635 100644 --- a/bisenzone-cw-mvp/packages/quartz-cw/src/prelude.rs +++ b/bisenzone-cw-mvp/packages/quartz-cw/src/prelude.rs @@ -1,3 +1,7 @@ -pub use crate::handler::RawHandler; -pub use crate::msg::execute::RawExecute as QuartzExecuteMsg; -pub use crate::msg::instantiate::RawInstantiate as QuartzInstantiateMsg; +pub use crate::{ + handler::RawHandler, + msg::{ + execute::RawExecute as QuartzExecuteMsg, + instantiate::RawInstantiate as QuartzInstantiateMsg, + }, +}; diff --git a/bisenzone-cw-mvp/packages/quartz-tee-ra/src/intel_sgx/epid/verifier.rs b/bisenzone-cw-mvp/packages/quartz-tee-ra/src/intel_sgx/epid/verifier.rs index 2d09248..7234836 100644 --- a/bisenzone-cw-mvp/packages/quartz-tee-ra/src/intel_sgx/epid/verifier.rs +++ b/bisenzone-cw-mvp/packages/quartz-tee-ra/src/intel_sgx/epid/verifier.rs @@ -2,10 +2,10 @@ use cosmwasm_std::ensure_eq; use num_bigint::BigUint; use sha2::{Digest, Sha256}; -use crate::intel_sgx::epid::types::IASReport; -use crate::intel_sgx::epid::Error as EpidError; -use crate::intel_sgx::epid::{INTEL_ROOT_EXPONENT, INTEL_ROOT_MODULUS}; -use crate::intel_sgx::Error; +use crate::intel_sgx::{ + epid::{types::IASReport, Error as EpidError, INTEL_ROOT_EXPONENT, INTEL_ROOT_MODULUS}, + Error, +}; /// Given an RSA signature and the signer's exponent + modulus we recover the digest that was signed by the signature. pub fn recover_signature_digest(signature: &[u8], exponent: &[u8], modulus: &[u8]) -> Vec { diff --git a/bisenzone-cw-mvp/packages/quartz-tee-ra/src/lib.rs b/bisenzone-cw-mvp/packages/quartz-tee-ra/src/lib.rs index 908a4cd..75fac91 100644 --- a/bisenzone-cw-mvp/packages/quartz-tee-ra/src/lib.rs +++ b/bisenzone-cw-mvp/packages/quartz-tee-ra/src/lib.rs @@ -17,6 +17,7 @@ pub mod intel_sgx; -pub use intel_sgx::epid::types::IASReport; -pub use intel_sgx::epid::verifier::verify as verify_epid_attestation; -pub use intel_sgx::Error; +pub use intel_sgx::{ + epid::{types::IASReport, verifier::verify as verify_epid_attestation}, + Error, +};