Skip to content

Commit

Permalink
refactor: new derivation in pallet rings
Browse files Browse the repository at this point in the history
  • Loading branch information
arrudagates committed Dec 3, 2023
1 parent 02582d1 commit 63c6687
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 129 deletions.
2 changes: 1 addition & 1 deletion INV4/pallet-inv4/src/inv4_core.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::pallet::*;
use crate::{
account_derivation::CoreAccountDerivation,
fee_handling::{FeeAsset, FeeAssetNegativeImbalance, MultisigFeeHandler},
origin::{ensure_multisig, INV4Origin},
util::CoreAccountConversion,
};
use frame_support::{
pallet_prelude::*,
Expand Down
13 changes: 4 additions & 9 deletions INV4/pallet-inv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ mod tests;

//pub mod migrations;

pub mod account_derivation;
mod dispatch;
pub mod fee_handling;
pub mod inv4_core;
mod lookup;
pub mod multisig;
pub mod origin;
pub mod util;
pub mod voting;
pub mod weights;

pub use account_derivation::CoreAccountDerivation;
use fee_handling::FeeAsset;
pub use lookup::INV4Lookup;
pub use util::CoreAccountConversion;
pub use weights::WeightInfo;

#[frame_support::pallet]
Expand Down Expand Up @@ -152,14 +152,9 @@ pub mod pallet {

type FeeCharger: MultisigFeeHandler<Self>;

#[pallet::constant]
type GenesisHash: Get<<Self as frame_system::Config>::Hash>;

#[pallet::constant]
type GlobalNetworkId: Get<NetworkId>;
const GLOBAL_NETWORK_ID: NetworkId;

#[pallet::constant]
type ParaId: Get<u32>;
const PARA_ID: u32;

#[pallet::constant]
type MaxCallSize: Get<u32>;
Expand Down
2 changes: 1 addition & 1 deletion INV4/pallet-inv4/src/multisig.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::pallet::{self, *};
use crate::{
account_derivation::CoreAccountDerivation,
fee_handling::FeeAsset,
origin::{ensure_multisig, INV4Origin},
util::CoreAccountConversion,
voting::{Tally, Vote},
};
use core::{
Expand Down
4 changes: 2 additions & 2 deletions INV4/pallet-inv4/src/origin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
account_derivation::CoreAccountDerivation,
pallet::{self, Origin, Pallet},
util::CoreAccountConversion,
Config,
};
use codec::{Decode, Encode, MaxEncodedLen};
Expand All @@ -26,7 +26,7 @@ where
}

pub fn to_account_id(&self) -> T::AccountId {
Pallet::<T>::derive_core_account(self.id.clone())
Pallet::<T>::derive_core_account(self.id)
}
}

Expand Down
2 changes: 1 addition & 1 deletion INV4/pallet-inv4/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl ExtBuilder {
(BOB, INITIAL_BALANCE),
(CHARLIE, INITIAL_BALANCE),
(
util::derive_core_account::<Test, u32, u32>(0u32),
account_derivation::derive_core_account::<Test, u32, u32>(0u32),
INITIAL_BALANCE,
),
],
Expand Down
20 changes: 10 additions & 10 deletions INV4/pallet-inv4/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn create_core_works() {
assert_eq!(
INV4::core_storage(0u32),
Some(CoreInfo {
account: util::derive_core_account::<Test, u32, u32>(0u32),
account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
metadata: vec![].try_into().unwrap(),
minimum_support: Perbill::from_percent(1),
required_approval: Perbill::from_percent(1),
Expand Down Expand Up @@ -77,7 +77,7 @@ fn create_core_works() {
assert_eq!(
INV4::core_storage(1u32),
Some(CoreInfo {
account: util::derive_core_account::<Test, u32, u32>(1u32),
account: account_derivation::derive_core_account::<Test, u32, u32>(1u32),
metadata: vec![1, 2, 3].try_into().unwrap(),
minimum_support: Perbill::from_percent(100),
required_approval: Perbill::from_percent(100),
Expand Down Expand Up @@ -160,7 +160,7 @@ fn set_parameters_works() {
assert_eq!(
INV4::core_storage(0u32),
Some(CoreInfo {
account: util::derive_core_account::<Test, u32, u32>(0u32),
account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
metadata: vec![1, 2, 3].try_into().unwrap(),
minimum_support: Perbill::from_percent(100),
required_approval: Perbill::from_percent(100),
Expand Down Expand Up @@ -438,7 +438,7 @@ fn operate_multisig_works() {
System::assert_has_event(
Event::MultisigExecuted {
core_id: 0u32,
executor_account: util::derive_core_account::<Test, u32, u32>(0u32),
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
voter: ALICE,
call: call.clone(),
call_hash: <<Test as frame_system::Config>::Hashing as Hash>::hash_of(&call),
Expand Down Expand Up @@ -468,7 +468,7 @@ fn operate_multisig_works() {
System::assert_has_event(
Event::MultisigVoteStarted {
core_id: 0u32,
executor_account: util::derive_core_account::<Test, u32, u32>(0u32),
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
voter: ALICE,
votes_added: Vote::Aye(CoreSeedBalance::get()),
call_hash: <<Test as frame_system::Config>::Hashing as Hash>::hash_of(&call),
Expand Down Expand Up @@ -815,7 +815,7 @@ fn vote_multisig_works() {
System::assert_has_event(
Event::MultisigVoteAdded {
core_id: 0u32,
executor_account: util::derive_core_account::<Test, u32, u32>(0u32),
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
voter: BOB,
votes_added: Vote::Nay(CoreSeedBalance::get()),
current_votes: Tally::from_parts(
Expand Down Expand Up @@ -866,7 +866,7 @@ fn vote_multisig_works() {
System::assert_has_event(
Event::MultisigExecuted {
core_id: 0u32,
executor_account: util::derive_core_account::<Test, u32, u32>(0u32),
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
voter: BOB,
call: call2.clone(),
call_hash: <<Test as frame_system::Config>::Hashing as Hash>::hash_of(&call2),
Expand Down Expand Up @@ -1043,7 +1043,7 @@ fn withdraw_vote_multisig_works() {
System::assert_has_event(
Event::MultisigVoteAdded {
core_id: 0u32,
executor_account: util::derive_core_account::<Test, u32, u32>(0u32),
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
voter: BOB,
votes_added: Vote::Nay(CoreSeedBalance::get()),
current_votes: Tally::from_parts(
Expand Down Expand Up @@ -1093,7 +1093,7 @@ fn withdraw_vote_multisig_works() {
System::assert_has_event(
Event::MultisigVoteWithdrawn {
core_id: 0u32,
executor_account: util::derive_core_account::<Test, u32, u32>(0u32),
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
voter: BOB,
votes_removed: Vote::Nay(CoreSeedBalance::get()),
call_hash: <<Test as frame_system::Config>::Hashing as Hash>::hash_of(&call2),
Expand Down Expand Up @@ -1134,7 +1134,7 @@ fn withdraw_vote_multisig_works() {
System::assert_has_event(
Event::MultisigVoteWithdrawn {
core_id: 0u32,
executor_account: util::derive_core_account::<Test, u32, u32>(0u32),
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
voter: ALICE,
votes_removed: Vote::Aye(CoreSeedBalance::get()),
call_hash: <<Test as frame_system::Config>::Hashing as Hash>::hash_of(&call2),
Expand Down
55 changes: 0 additions & 55 deletions INV4/pallet-inv4/src/util.rs

This file was deleted.

4 changes: 2 additions & 2 deletions OCIF/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub use pallet::*;
pub mod pallet {
use pallet_inv4::{
origin::{ensure_multisig, INV4Origin},
CoreAccountConversion,
CoreAccountDerivation,
};

use super::*;
Expand Down Expand Up @@ -758,7 +758,7 @@ pub mod pallet {
)?;

let core_account =
<pallet_inv4::Pallet<T> as CoreAccountConversion<T>>::derive_core_account(core_id);
<pallet_inv4::Pallet<T> as CoreAccountDerivation<T>>::derive_core_account(core_id);

<T as pallet::Config>::Currency::resolve_creating(&core_account, reward_imbalance);
Self::deposit_event(Event::<T>::CoreClaimed {
Expand Down
Loading

0 comments on commit 63c6687

Please sign in to comment.