Skip to content

Commit

Permalink
mesh-1097: extract weights
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 16, 2020
1 parent efa40a0 commit d87dae6
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

17 changes: 14 additions & 3 deletions pallets/corporate-actions/src/lib.rs
Expand Up @@ -43,6 +43,7 @@ use frame_support::{
decl_error, decl_event, decl_module, decl_storage,
dispatch::{DispatchError, DispatchResult},
ensure,
weights::Weight,
};
use pallet_asset as asset;
use pallet_identity as identity;
Expand Down Expand Up @@ -83,10 +84,20 @@ pub struct TargetIdentities {
treatment: TargetTreatment,
}

/// Weight abstraction for the corporate actions module.
pub trait WeightInfo {
fn set_default_targets(targets: &TargetIdentities) -> Weight;
fn set_default_withholding_tax() -> Weight;
fn set_did_withholding_tax() -> Weight;
}

/// The module's configuration trait.
pub trait Trait: frame_system::Trait + BalancesTrait + IdentityTrait + asset::Trait {
/// The overarching event type.
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;

/// Weight information for extrinsics in the corporate actions pallet.
type WeightInfo: WeightInfo;
}

type Identity<T> = identity::Module<T>;
Expand Down Expand Up @@ -137,7 +148,7 @@ decl_module! {
/// initialize the default event for this module
fn deposit_event() = default;

#[weight = 999_999_999_999]
#[weight = <T as Trait>::WeightInfo::set_default_targets(&targets)]
fn set_default_targets(origin, ticker: Ticker, targets: TargetIdentities) {
// Verify authorization + all identities are token holders.
let caa = Self::ensure_ca_agent(origin, ticker)?;
Expand All @@ -163,7 +174,7 @@ decl_module! {
/// ## Arguments
/// - `ticker` that the withholding tax will apply to.
/// - `tax` that should be withheld when distributing dividends, etc.
#[weight = 999_999_999_999]
#[weight = <T as Trait>::WeightInfo::set_default_withholding_tax()]
fn set_default_withholding_tax(origin, ticker: Ticker, tax: Permill) {
let caa = Self::ensure_ca_agent(origin, ticker)?;
let old = DefaultWitholdingTax::mutate(ticker, |slot| mem::replace(slot, tax));
Expand All @@ -178,7 +189,7 @@ decl_module! {
/// - `ticker` that the withholding tax will apply to.
/// - `taxed_did` that will have its withholding tax updated.
/// - `tax` that should be withheld when distributing dividends, etc.
#[weight = 999_999_999_999]
#[weight = <T as Trait>::WeightInfo::set_did_withholding_tax()]
fn set_did_withholding_tax(origin, ticker: Ticker, taxed_did: IdentityId, tax: Option<Permill>) {
// Verify authorization + `taxed_did` is token holder.
let caa = Self::ensure_ca_agent(origin, ticker)?;
Expand Down
1 change: 1 addition & 0 deletions pallets/runtime/develop/src/runtime.rs
Expand Up @@ -714,6 +714,7 @@ impl polymesh_contracts::Trait for Runtime {

impl pallet_corporate_actions::Trait for Runtime {
type Event = Event;
type WeightInfo = polymesh_weights::pallet_corporate_actions::WeightInfo;
}

impl exemption::Trait for Runtime {
Expand Down
1 change: 1 addition & 0 deletions pallets/runtime/testnet/src/runtime.rs
Expand Up @@ -712,6 +712,7 @@ impl polymesh_contracts::Trait for Runtime {

impl pallet_corporate_actions::Trait for Runtime {
type Event = Event;
type WeightInfo = polymesh_weights::pallet_corporate_actions::WeightInfo;
}

impl exemption::Trait for Runtime {
Expand Down
2 changes: 2 additions & 0 deletions pallets/runtime/tests/Cargo.toml
Expand Up @@ -81,6 +81,7 @@ frame-benchmarking = { git = "https://github.com/paritytech/substrate", tag = "v

test_client = { package = "substrate-test-runtime-client", git = "https://github.com/paritytech/substrate", tag = "v2.0.0", optional = true }
substrate-test-utils = { git = "https://github.com/paritytech/substrate", tag = "v2.0.0", optional = true }
polymesh-weights = { path = "../../weights", default-features = false }

[dev-dependencies]
libsecp256k1 = { version = "0.3.5", default-features = false }
Expand All @@ -106,6 +107,7 @@ std = [
"pallet-committee/std",
"pallet-compliance-manager/std",
"pallet-contracts/std",
"polymesh-weights/std",
"pallet-group-rpc-runtime-api/std",
"pallet-group/std",
"pallet-identity/std",
Expand Down
1 change: 1 addition & 0 deletions pallets/runtime/tests/src/storage.rs
Expand Up @@ -511,6 +511,7 @@ impl bridge::Trait for TestStorage {

impl corporate_actions::Trait for TestStorage {
type Event = Event;
type WeightInfo = polymesh_weights::pallet_corporate_actions::WeightInfo;
}

impl exemption::Trait for TestStorage {
Expand Down
2 changes: 2 additions & 0 deletions pallets/weights/Cargo.toml
Expand Up @@ -7,13 +7,15 @@ edition = "2018"
[dependencies]
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, tag = "v2.0.0" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, tag = "v2.0.0" }
pallet-corporate-actions = { path = "../corporate-actions", default-features = false }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, tag = "v2.0.0" }

[features]
default = ["std"]
no_std = []
std = [
"frame-support/std",
"pallet-corporate-actions/std",
"pallet-timestamp/std",
"frame-system/std"
]
1 change: 1 addition & 0 deletions pallets/weights/src/lib.rs
Expand Up @@ -18,4 +18,5 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod frame_system;
pub mod pallet_corporate_actions;
pub mod pallet_timestamp;
15 changes: 15 additions & 0 deletions pallets/weights/src/pallet_corporate_actions.rs
@@ -0,0 +1,15 @@
use frame_support::weights::Weight;
use pallet_corporate_actions::TargetIdentities;

pub struct WeightInfo;
impl pallet_corporate_actions::WeightInfo for WeightInfo {
fn set_default_targets(_: &TargetIdentities) -> Weight {
999_999_999_999
}
fn set_default_withholding_tax() -> Weight {
999_999_999_999
}
fn set_did_withholding_tax() -> Weight {
999_999_999_999
}
}

0 comments on commit d87dae6

Please sign in to comment.