Skip to content

Commit

Permalink
Multiasset integration (#119)
Browse files Browse the repository at this point in the history
* Added orml pallets

* Update config and types

* Added native currency id to config

* Runtime config, benchmark errors

* Testing mixer with non-native currency

* Making create_new non-dispatchable

Co-authored-by: Drew Stone <drewstone329@gmail.com>
  • Loading branch information
Filip Lazovic and drewstone committed Mar 22, 2021
1 parent e8b43d2 commit 9c899dd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
17 changes: 17 additions & 0 deletions pallets/mixer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub mod tests;
mod benchmarking;
pub mod weights;

pub mod traits;

use codec::{Decode, Encode};
use frame_support::{debug, dispatch, ensure, traits::Get, weights::Weight};
use frame_system::ensure_signed;
Expand All @@ -70,6 +72,7 @@ use sp_runtime::{
ModuleId,
};
use sp_std::prelude::*;
use traits::ExtendedMixer;
use weights::WeightInfo;

pub use pallet::*;
Expand Down Expand Up @@ -562,3 +565,17 @@ impl<T: Config> Module<T> {
Ok(())
}
}

impl<T: Config> ExtendedMixer<T::AccountId, CurrencyIdOf<T>, BalanceOf<T>> for Pallet<T> {
fn create_new(
account_id: T::AccountId,
currency_id: CurrencyIdOf<T>,
size: BalanceOf<T>,
) -> Result<(), dispatch::DispatchError> {
let depth: u8 = <T as merkle::Config>::MaxTreeDepth::get();
let mixer_id: T::GroupId = T::Group::create_group(Self::account_id(), true, depth)?;
let mixer_info = MixerInfo::<T>::new(T::DepositLength::get(), size, Vec::new(), currency_id);
MixerGroups::<T>::insert(mixer_id, mixer_info);
Ok(())
}
}
11 changes: 9 additions & 2 deletions pallets/mixer/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::*;
use crate::mock::{new_test_ext, AccountId, Balances, MerkleGroups, Mixer, MixerCall, Origin, System, Test, Tokens};
use crate::mock::{
new_test_ext, AccountId, Balance, Balances, CurrencyId, MerkleGroups, Mixer, MixerCall, Origin, System, Test,
Tokens,
};
use bulletproofs::{r1cs::Prover, BulletproofGens, PedersenGens};
use bulletproofs_gadgets::{
fixed_deposit_tree::builder::FixedDepositTreeBuilder,
Expand Down Expand Up @@ -335,7 +338,11 @@ fn should_make_mixer_with_non_native_token() {
new_test_ext().execute_with(|| {
let currency_id = 1;
assert_ok!(Mixer::initialize());
assert_ok!(Mixer::create_new(Origin::signed(4), currency_id, 1_000));
assert_ok!(<Mixer as ExtendedMixer<AccountId, CurrencyId, Balance>>::create_new(
4,
currency_id,
1_000
));

let pc_gens = PedersenGens::default();
let poseidon = default_hasher(16400);
Expand Down
6 changes: 6 additions & 0 deletions pallets/mixer/src/traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use frame_support::dispatch;

pub trait ExtendedMixer<AccountId, CurrencyId, Balance> {
fn create_new(account_id: AccountId, currency_id: CurrencyId, size: Balance)
-> Result<(), dispatch::DispatchError>;
}

0 comments on commit 9c899dd

Please sign in to comment.