Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ fn pangolin_build_spec_genesis() -> pangolin_runtime::GenesisConfig {
darwinia_claims: Default::default(),
darwinia_vesting: Default::default(),
pallet_sudo: pangolin_runtime::SudoConfig { key: root.clone() },
darwinia_crab_issuing: pangolin_runtime::CrabIssuingConfig { total_mapped_ring: BUNCH_OF_COINS },
darwinia_crab_issuing: pangolin_runtime::DarwiniaCrabIssuingConfig { total_mapped_ring: BUNCH_OF_COINS, phantom: std::marker::PhantomData },
darwinia_crab_backing: pangolin_runtime::CrabBackingConfig { backed_ring: BUNCH_OF_COINS },
darwinia_ethereum_relay: pangolin_runtime::EthereumRelayConfig {
genesis_header_info: (
Expand Down Expand Up @@ -471,7 +471,7 @@ fn pangolin_development_genesis() -> pangolin_runtime::GenesisConfig {
},
darwinia_vesting: Default::default(),
pallet_sudo: pangolin_runtime::SudoConfig { key: root.clone() },
darwinia_crab_issuing: pangolin_runtime::CrabIssuingConfig { total_mapped_ring: BUNCH_OF_COINS },
darwinia_crab_issuing: pangolin_runtime::DarwiniaCrabIssuingConfig { total_mapped_ring: BUNCH_OF_COINS, phantom: std::marker::PhantomData },
darwinia_crab_backing: pangolin_runtime::CrabBackingConfig { backed_ring: BUNCH_OF_COINS },
darwinia_ethereum_relay: pangolin_runtime::EthereumRelayConfig {
genesis_header_info: (
Expand Down
2 changes: 1 addition & 1 deletion bin/node/runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ frame_support::construct_runtime! {
// Multisig module. Late addition.
Multisig: pallet_multisig::{Module, Call, Storage, Event<T>} = 32,

CrabIssuing: darwinia_crab_issuing::{Module, Call, Storage, Config, Event<T>} = 33,
DarwiniaCrabIssuing: darwinia_crab_issuing::{Module, Call, Storage, Config<T>, Event<T>} = 33,
CrabBacking: darwinia_crab_backing::{Module, Storage, Config<T>} = 34,

EthereumRelay: darwinia_ethereum_relay::{Module, Call, Storage, Config<T>, Event<T>} = 35,
Expand Down
111 changes: 59 additions & 52 deletions frame/bridge/crab/issuing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@

#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;

pub mod weights;
// --- darwinia ---
pub use weights::WeightInfo;
// --- substrate ---
use frame_support::traits::Currency;

#[cfg(test)]
mod mock;
Expand All @@ -42,73 +46,76 @@ mod types {
type RingCurrency<T> = <T as Config>::RingCurrency;
}

// --- substrate ---
use frame_support::{
decl_error, decl_event, decl_module, decl_storage,
traits::{Currency, Get},
};
use sp_runtime::{traits::AccountIdConversion, ModuleId};
// --- darwinia ---
use types::*;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_support::traits::{Currency, Get};
use frame_system::pallet_prelude::*;
use sp_runtime::{traits::AccountIdConversion, ModuleId};
use types::*;

pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
pub trait Config: frame_system::Config {
#[pallet::constant]
type ModuleId: Get<ModuleId>;

type ModuleId: Get<ModuleId>;
type RingCurrency: Currency<AccountId<Self>>;

type RingCurrency: Currency<AccountId<Self>>;
type WeightInfo: WeightInfo;

type WeightInfo: WeightInfo;
}
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
}

decl_event! {
pub enum Event<T>
where
AccountId = AccountId<T>,
RingBalance = RingBalance<T>,
{
// Define the pallet struct placeholder, various pallet function are implemented on it.
#[pallet::pallet]
pub struct Pallet<T>(_);

#[pallet::error]
pub enum Error<T> {}

#[pallet::event]
pub enum Event<T: Config> {
/// Dummy Event. [who, swapped *CRING*, burned Mapped *RING*]
DummyEvent(AccountId, RingBalance, MappedRing),
DummyEvent(AccountId<T>, RingBalance<T>, MappedRing),
}
}

decl_error! {
pub enum Error for Module<T: Config> {
#[pallet::storage]
#[pallet::getter(fn total_mapped_ring)]
pub(super) type TotalMappedRing<T: Config> = StorageValue<_, MappedRing>;

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}

#[pallet::call]
impl<T: Config> Pallet<T> {}

#[pallet::genesis_config]
pub struct GenesisConfig<T> {
pub total_mapped_ring: MappedRing,
pub phantom: std::marker::PhantomData<T>,
}
}

decl_storage! {
trait Store for Module<T: Config> as DarwiniaCrabIssuing {
pub TotalMappedRing get(fn total_mapped_ring) config(): MappedRing;
#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self {
total_mapped_ring: Default::default(),
phantom: Default::default(),
}
}
}

add_extra_genesis {
build(|config| {
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
let _ = T::RingCurrency::make_free_balance_be(
&<Module<T>>::account_id(),
&T::ModuleId::get().into_account(),
T::RingCurrency::minimum_balance(),
);

TotalMappedRing::put(config.total_mapped_ring);
});
}
}

decl_module! {
pub struct Module<T: Config> for enum Call
where
origin: T::Origin
{
type Error = Error<T>;

const ModuleId: ModuleId = T::ModuleId::get();

fn deposit_event() = default;
}
}

impl<T: Config> Module<T> {
pub fn account_id() -> T::AccountId {
T::ModuleId::get().into_account()
<TotalMappedRing<T>>::put(self.total_mapped_ring);
}
}
}
10 changes: 7 additions & 3 deletions frame/bridge/crab/issuing/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
// --- crates ---
use codec::{Decode, Encode};
// --- substrate ---
use frame_support::traits::GenesisBuild;
use frame_system::mocking::*;
use sp_io::TestExternalities;
use sp_runtime::ModuleId;
use sp_runtime::{
testing::{Header, H256},
traits::{BlakeTwo256, IdentityLookup},
Expand Down Expand Up @@ -100,7 +102,7 @@ frame_support::construct_runtime! {
{
System: frame_system::{Module, Call, Storage, Config, Event<T>},
Ring: darwinia_balances::<Instance0>::{Module, Call, Storage, Config<T>, Event<T>},
CrabIssuing: darwinia_crab_issuing::{Module, Call, Storage, Config, Event<T>},
DarwiniaCrabIssuing: darwinia_crab_issuing::{Module, Call, Storage, Config<T>, Event<T>},
}
}

Expand All @@ -117,10 +119,12 @@ pub fn new_test_ext() -> TestExternalities {
}
.assimilate_storage(&mut t)
.unwrap();
darwinia_crab_issuing::GenesisConfig {

darwinia_crab_issuing::GenesisConfig::<Test> {
total_mapped_ring: 4_000,
phantom: std::marker::PhantomData,
}
.assimilate_storage::<Test>(&mut t)
.assimilate_storage(&mut t)
.unwrap();

t.into()
Expand Down