Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiasset integration #119

Merged
merged 9 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -528,3 +531,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>;
}