Skip to content

Commit

Permalink
Move traits to primitives (#250)
Browse files Browse the repository at this point in the history
### Description

Traits are primitive data types which are used across the pallets &
runtime. Being in a separate module in the root directory does not make
sense.

### Types of Changes
<!--- What types of changes does your code introduce? -->
- [x] Tech Debt (Code improvements)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Dependency upgrade (A change in substrate or any 3rd party crate
version)

### Migrations and Hooks
<!--- Check the following box with an x if the following applies: -->
- [ ] This change requires a runtime migration.
- [ ] Modifies `on_initialize`
- [ ] Modifies `on_finalize`

### Checklist
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [x] Change has been tested locally.
- [ ] Change adds / updates tests.
- [ ] Changelog doc updated.
  • Loading branch information
rakanalh authored Jan 25, 2024
1 parent 262d44b commit 3d4034e
Show file tree
Hide file tree
Showing 33 changed files with 88 additions and 88 deletions.
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

### Types of Changes
<!--- What types of changes does your code introduce? -->
- [ ] Tech Debt (Code improvements)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Expand Down
23 changes: 4 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pallets/ddc-clusters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2021"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
ddc-primitives = { version = "4.8.8", default-features = false, path = "../../primitives" }
ddc-traits = { version = "4.8.8", default-features = false, path = "../../traits" }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", optional = true }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
Expand Down
10 changes: 5 additions & 5 deletions pallets/ddc-clusters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ pub(crate) mod mock;
mod tests;

use ddc_primitives::{
traits::{
cluster::{ClusterCreator, ClusterVisitor, ClusterVisitorError},
staking::{StakerCreator, StakingVisitor, StakingVisitorError},
},
ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterId, ClusterParams,
ClusterPricingParams, NodePubKey, NodeType,
};
use ddc_traits::{
cluster::{ClusterCreator, ClusterVisitor, ClusterVisitorError},
staking::{StakerCreator, StakingVisitor, StakingVisitorError},
};
use frame_support::{
assert_ok,
pallet_prelude::*,
Expand All @@ -61,7 +61,7 @@ pub type BalanceOf<T> =

#[frame_support::pallet]
pub mod pallet {
use ddc_traits::cluster::{ClusterManager, ClusterManagerError};
use ddc_primitives::traits::cluster::{ClusterManager, ClusterManagerError};

use super::*;

Expand Down
6 changes: 4 additions & 2 deletions pallets/ddc-clusters/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

#![allow(dead_code)]

use ddc_primitives::{ClusterId, NodePubKey};
use ddc_traits::staking::{StakerCreator, StakingVisitor, StakingVisitorError};
use ddc_primitives::{
traits::staking::{StakerCreator, StakingVisitor, StakingVisitorError},
ClusterId, NodePubKey,
};
use frame_support::{
construct_runtime, parameter_types,
traits::{ConstBool, ConstU32, ConstU64, Everything, Nothing},
Expand Down
6 changes: 3 additions & 3 deletions pallets/ddc-clusters/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Tests for the module.

use ddc_primitives::{
ClusterBondingParams, ClusterFeesParams, ClusterId, ClusterParams, ClusterPricingParams,
NodeParams, NodePubKey, StorageNodeMode, StorageNodeParams,
traits::cluster::ClusterManager, ClusterBondingParams, ClusterFeesParams, ClusterId,
ClusterParams, ClusterPricingParams, NodeParams, NodePubKey, StorageNodeMode,
StorageNodeParams,
};
use ddc_traits::cluster::ClusterManager;
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
use frame_system::Config;
use hex_literal::hex;
Expand Down
1 change: 0 additions & 1 deletion pallets/ddc-customers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive"

# Cere
ddc-primitives = { version = "4.8.8", default-features = false, path = "../../primitives" }
ddc-traits = { version = "4.8.8", default-features = false, path = "../../traits" }

[dev-dependencies]
frame-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
Expand Down
10 changes: 6 additions & 4 deletions pallets/ddc-customers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ pub(crate) mod mock;
mod tests;

use codec::{Decode, Encode};
use ddc_primitives::{BucketId, ClusterId};
use ddc_traits::{
cluster::{ClusterCreator, ClusterVisitor},
customer::{CustomerCharger, CustomerDepositor},
use ddc_primitives::{
traits::{
cluster::{ClusterCreator, ClusterVisitor},
customer::{CustomerCharger, CustomerDepositor},
},
BucketId, ClusterId,
};
use frame_support::{
parameter_types,
Expand Down
6 changes: 3 additions & 3 deletions pallets/ddc-customers/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Test utilities

use ddc_primitives::{
traits::cluster::{
ClusterCreator, ClusterManager, ClusterManagerError, ClusterVisitor, ClusterVisitorError,
},
ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterId, ClusterParams,
ClusterPricingParams, NodePubKey, NodeType,
};
use ddc_traits::cluster::{
ClusterCreator, ClusterManager, ClusterManagerError, ClusterVisitor, ClusterVisitorError,
};
use frame_support::{
construct_runtime, parameter_types,
traits::{ConstU32, ConstU64, Everything, GenesisBuild},
Expand Down
1 change: 0 additions & 1 deletion pallets/ddc-nodes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2021"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
ddc-primitives = { version = "4.8.8", default-features = false, path = "../../primitives" }
ddc-traits = { version = "4.8.8", default-features = false, path = "../../traits" }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", optional = true }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
Expand Down
10 changes: 6 additions & 4 deletions pallets/ddc-nodes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ pub mod benchmarking;
#[cfg(any(feature = "runtime-benchmarks", test))]
pub mod testing_utils;

use ddc_primitives::{ClusterId, NodeParams, NodePubKey, StorageNodePubKey};
use ddc_traits::{
node::{NodeCreator, NodeVisitor, NodeVisitorError},
staking::StakingVisitor,
use ddc_primitives::{
traits::{
node::{NodeCreator, NodeVisitor, NodeVisitorError},
staking::StakingVisitor,
},
ClusterId, NodeParams, NodePubKey, StorageNodePubKey,
};
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion pallets/ddc-nodes/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![allow(dead_code)]

use ddc_traits::staking::{StakingVisitor, StakingVisitorError};
use ddc_primitives::traits::staking::{StakingVisitor, StakingVisitorError};
use frame_support::{
construct_runtime, parameter_types,
traits::{ConstU32, ConstU64, Everything},
Expand Down
1 change: 0 additions & 1 deletion pallets/ddc-payouts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"
byte-unit = { version = "4.0.19", default-features = false, features = ["u128"] }
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
ddc-primitives = { version = "4.8.8", default-features = false, path = "../../primitives" }
ddc-traits = { version = "4.8.8", default-features = false, path = "../../traits" }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", optional = true }
frame-election-provider-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
Expand Down
14 changes: 8 additions & 6 deletions pallets/ddc-payouts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ pub(crate) mod mock;
#[cfg(test)]
mod tests;

use ddc_primitives::{ClusterId, DdcEra, MILLICENTS};
use ddc_traits::{
cluster::{ClusterCreator as ClusterCreatorType, ClusterVisitor as ClusterVisitorType},
customer::{
CustomerCharger as CustomerChargerType, CustomerDepositor as CustomerDepositorType,
use ddc_primitives::{
traits::{
cluster::{ClusterCreator as ClusterCreatorType, ClusterVisitor as ClusterVisitorType},
customer::{
CustomerCharger as CustomerChargerType, CustomerDepositor as CustomerDepositorType,
},
pallet::PalletVisitor as PalletVisitorType,
},
pallet::PalletVisitor as PalletVisitorType,
ClusterId, DdcEra, MILLICENTS,
};
use frame_election_provider_support::SortedListProvider;
use frame_support::{
Expand Down
10 changes: 5 additions & 5 deletions pallets/ddc-payouts/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#![allow(dead_code)]

use ddc_primitives::{
traits::{
cluster::{ClusterCreator, ClusterVisitor, ClusterVisitorError},
customer::{CustomerCharger, CustomerDepositor},
pallet::PalletVisitor,
},
ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterParams, ClusterPricingParams,
NodeType, DOLLARS,
};
use ddc_traits::{
cluster::{ClusterCreator, ClusterVisitor, ClusterVisitorError},
customer::{CustomerCharger, CustomerDepositor},
pallet::PalletVisitor,
};
use frame_election_provider_support::SortedListProvider;
use frame_support::{
construct_runtime, parameter_types,
Expand Down
1 change: 0 additions & 1 deletion pallets/ddc-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2021"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
ddc-primitives = { version = "4.8.8", default-features = false, path = "../../primitives" }
ddc-traits = { version = "4.8.8", default-features = false, path = "../../traits" }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40", optional = true }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
Expand Down
6 changes: 3 additions & 3 deletions pallets/ddc-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ pub mod weights;
use core::fmt::Debug;

use codec::{Decode, Encode, HasCompact};
pub use ddc_primitives::{ClusterId, NodePubKey, NodeType};
use ddc_traits::{
use ddc_primitives::traits::{
cluster::{ClusterCreator, ClusterVisitor, ClusterVisitorError},
node::{NodeCreator, NodeVisitor},
staking::{StakerCreator, StakingVisitor, StakingVisitorError},
};
pub use ddc_primitives::{ClusterId, NodePubKey, NodeType};
#[cfg(feature = "std")]
use frame_support::assert_ok;
use frame_support::{
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<

#[frame_support::pallet]
pub mod pallet {
use ddc_traits::{cluster::ClusterManager, node::NodeVisitorError};
use ddc_primitives::traits::{cluster::ClusterManager, node::NodeVisitorError};

use super::*;

Expand Down
8 changes: 4 additions & 4 deletions pallets/ddc-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use std::cell::RefCell;

use ddc_primitives::{
traits::{
cluster::{ClusterManager, ClusterManagerError, ClusterVisitor, ClusterVisitorError},
node::{NodeVisitor, NodeVisitorError},
},
ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterParams, ClusterPricingParams,
NodeParams, NodePubKey, StorageNodePubKey,
};
use ddc_traits::{
cluster::{ClusterManager, ClusterManagerError, ClusterVisitor, ClusterVisitorError},
node::{NodeVisitor, NodeVisitorError},
};
use frame_support::{
construct_runtime,
dispatch::DispatchResult,
Expand Down
10 changes: 9 additions & 1 deletion primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ codec = { package = "parity-scale-codec", version = "3.1.5", default-features =
scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
serde = { version = "1.0.136", default-features = false, features = ["derive"], optional = true }

frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }

[features]
default = ["std"]
Expand All @@ -18,6 +21,11 @@ std = [
"scale-info/std",
"serde",
"sp-core/std",
"sp-std/std",
"sp-runtime/std",
]
runtime-benchmarks = []
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
2 changes: 2 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use serde::{Deserialize, Serialize};
use sp_core::hash::H160;
use sp_runtime::{AccountId32, Perquintill, RuntimeDebug};

pub mod traits;

pub const MILLICENTS: u128 = 100_000;
pub const CENTS: u128 = 1_000 * MILLICENTS; // assume this is worth about a cent.
pub const DOLLARS: u128 = 100 * CENTS;
Expand Down
9 changes: 5 additions & 4 deletions traits/src/cluster.rs → primitives/src/traits/cluster.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use codec::{Decode, Encode};
use ddc_primitives::{
ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterId, ClusterParams,
ClusterPricingParams, NodePubKey, NodeType,
};
use frame_support::dispatch::DispatchResult;
use frame_system::Config;
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;

use crate::{
ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterId, ClusterParams,
ClusterPricingParams, NodePubKey, NodeType,
};

pub trait ClusterVisitor<T: Config> {
fn ensure_cluster(cluster_id: &ClusterId) -> Result<(), ClusterVisitorError>;

Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions traits/src/lib.rs → primitives/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ pub mod node;
pub mod pallet;
pub mod staking;
pub mod validator;

pub use cluster::*;
pub use customer::*;
pub use node::*;
pub use pallet::*;
pub use staking::*;
pub use validator::*;
Loading

0 comments on commit 3d4034e

Please sign in to comment.