From e09b2ab7d62670a87200c839c5075dfa2c354b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Wed, 22 Feb 2023 15:19:52 +0000 Subject: [PATCH] reversed the dependency between 'nym-contracts-common' and 'dkg' (#3089) --- Cargo.lock | 2 +- .../contracts-common/Cargo.toml | 1 - .../contracts-common/src/dealings.rs | 16 ---------------- common/dkg/Cargo.toml | 7 ++++++- common/dkg/src/dealing.rs | 18 ++++++++++++++++++ nym-api/Cargo.toml | 4 ++-- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7235f28297..a5ae3d2f08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1601,6 +1601,7 @@ dependencies = [ "ff 0.11.1", "group 0.11.0", "lazy_static", + "nym-contracts-common", "nym-pemstore", "rand 0.8.5", "rand_chacha 0.3.1", @@ -3519,7 +3520,6 @@ version = "0.1.0" dependencies = [ "bs58", "cosmwasm-std", - "dkg", "schemars", "serde", "serde_json", diff --git a/common/cosmwasm-smart-contracts/contracts-common/Cargo.toml b/common/cosmwasm-smart-contracts/contracts-common/Cargo.toml index 946f0cce90..59042f9a48 100644 --- a/common/cosmwasm-smart-contracts/contracts-common/Cargo.toml +++ b/common/cosmwasm-smart-contracts/contracts-common/Cargo.toml @@ -9,7 +9,6 @@ edition = "2021" [dependencies] bs58 = "0.4.0" cosmwasm-std = "1.0.0" -dkg = { path = "../../../common/dkg", optional = true } schemars = "0.8" serde = { version = "1.0", features = ["derive"] } thiserror = "1" diff --git a/common/cosmwasm-smart-contracts/contracts-common/src/dealings.rs b/common/cosmwasm-smart-contracts/contracts-common/src/dealings.rs index f28ca85ba2..cfc22e8727 100644 --- a/common/cosmwasm-smart-contracts/contracts-common/src/dealings.rs +++ b/common/cosmwasm-smart-contracts/contracts-common/src/dealings.rs @@ -69,19 +69,3 @@ impl<'de> Deserialize<'de> for ContractSafeBytes { Ok(ContractSafeBytes(bytes)) } } - -#[cfg(feature = "dkg")] -impl<'a> From<&'a Dealing> for ContractSafeBytes { - fn from(dealing: &'a Dealing) -> Self { - ContractSafeBytes(dealing.to_bytes()) - } -} - -#[cfg(feature = "dkg")] -impl<'a> TryFrom<&'a ContractSafeBytes> for Dealing { - type Error = DkgError; - - fn try_from(value: &'a ContractSafeBytes) -> Result { - Dealing::try_from_bytes(&value.0) - } -} diff --git a/common/dkg/Cargo.toml b/common/dkg/Cargo.toml index 33ec03447a..525001f42e 100644 --- a/common/dkg/Cargo.toml +++ b/common/dkg/Cargo.toml @@ -12,9 +12,10 @@ bitvec = "1.0.0" # unfortunately until https://github.com/zkcrypto/bls12_381/issues/10 is resolved, we have to rely on the fork # as we need to be able to serialize Gt so that we could create the lookup table for baby-step-giant-step algorithm bls12_381 = { git = "https://github.com/jstuczyn/bls12_381", branch ="gt-serialisation", default-features = false, features = ["alloc", "pairings", "experimental", "zeroize"] } - +nym-contracts-common = { path = "../cosmwasm-smart-contracts/contracts-common", optional = true } bs58 = "0.4" + lazy_static = "1.4.0" rand = { version = "0.8.5", default-features = false} rand_chacha = "0.3" @@ -41,3 +42,7 @@ criterion = "0.3" [[bench]] name = "benchmarks" harness = false + +[features] +default = [] +cw-types = ["nym-contracts-common"] \ No newline at end of file diff --git a/common/dkg/src/dealing.rs b/common/dkg/src/dealing.rs index d92a9ba6b4..ff31c5736e 100644 --- a/common/dkg/src/dealing.rs +++ b/common/dkg/src/dealing.rs @@ -307,6 +307,24 @@ impl Dealing { } } +#[cfg(feature = "cw-types")] +impl<'a> From<&'a Dealing> for nym_contracts_common::dealings::ContractSafeBytes { + fn from(dealing: &'a Dealing) -> Self { + nym_contracts_common::dealings::ContractSafeBytes(dealing.to_bytes()) + } +} + +#[cfg(feature = "cw-types")] +impl<'a> TryFrom<&'a nym_contracts_common::dealings::ContractSafeBytes> for Dealing { + type Error = DkgError; + + fn try_from( + value: &'a nym_contracts_common::dealings::ContractSafeBytes, + ) -> Result { + Dealing::try_from_bytes(&value.0) + } +} + // this assumes all dealings have been verified pub fn try_recover_verification_keys( dealings: &[Dealing], diff --git a/nym-api/Cargo.toml b/nym-api/Cargo.toml index a1ae9478b5..f64d624708 100644 --- a/nym-api/Cargo.toml +++ b/nym-api/Cargo.toml @@ -75,12 +75,12 @@ credentials = { path = "../common/credentials" } nym-crypto = { path = "../common/crypto" } cw3 = { version = "0.13.4" } cw4 = { version = "0.13.4" } -dkg = { path = "../common/dkg" } +dkg = { path = "../common/dkg", features = ["cw-types"] } gateway-client = { path = "../common/client-libs/gateway-client" } nym-inclusion-probability = { path = "../common/inclusion-probability" } nym-mixnet-contract-common = { path = "../common/cosmwasm-smart-contracts/mixnet-contract" } nym-vesting-contract-common = { path = "../common/cosmwasm-smart-contracts/vesting-contract" } -nym-contracts-common = { path = "../common/cosmwasm-smart-contracts/contracts-common", features = ["dkg"] } +nym-contracts-common = { path = "../common/cosmwasm-smart-contracts/contracts-common" } multisig-contract-common = { path = "../common/cosmwasm-smart-contracts/multisig-contract" } nymcoconut = { path = "../common/nymcoconut" } nym-sphinx = { path = "../common/nymsphinx" }