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 6 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
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 @@ -324,7 +324,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 },
darwinia_crab_backing: pangolin_runtime::CrabBackingConfig { backed_ring: BUNCH_OF_COINS },
darwinia_ethereum_relay: pangolin_runtime::EthereumRelayConfig {
genesis_header_info: (
Expand Down Expand Up @@ -477,7 +477,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 },
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 @@ -488,7 +488,7 @@ frame_support::construct_runtime! {
// Multisig module. Late addition.
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 32,

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

EthereumRelay: darwinia_ethereum_relay::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,
Expand Down
135 changes: 67 additions & 68 deletions frame/bridge/crab/issuing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,94 +21,93 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod weights;
// --- darwinia ---

pub use pallet::*;
pub use weights::WeightInfo;

#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;

mod types {
#[frame_support::pallet]
pub mod pallet {
pub mod types {
// --- darwinia ---
use super::*;

// Generic type
pub type AccountId<T> = <T as frame_system::Config>::AccountId;
pub type RingBalance<T> = <RingCurrency<T> as Currency<AccountId<T>>>::Balance;
type RingCurrency<T> = <T as Config>::RingCurrency;
// Simple type
pub type MappedRing = u128;
}
pub use types::*;

// --- substrate ---
use frame_support::{
pallet_prelude::*,
traits::{Currency, Get},
};
use frame_system::pallet_prelude::*;
use sp_runtime::{traits::AccountIdConversion, ModuleId};
// --- darwinia ---
use crate::*;

pub type MappedRing = u128;

pub type AccountId<T> = <T as frame_system::Config>::AccountId;

pub type RingBalance<T> = <RingCurrency<T> as Currency<AccountId<T>>>::Balance;

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::*;

pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;

type ModuleId: Get<ModuleId>;

type RingCurrency: Currency<AccountId<Self>>;

type WeightInfo: WeightInfo;
}

decl_event! {
pub enum Event<T>
where
AccountId = AccountId<T>,
RingBalance = RingBalance<T>,
{
/// Dummy Event. [who, swapped *CRING*, burned Mapped *RING*]
DummyEvent(AccountId, RingBalance, MappedRing),
use crate::weights::WeightInfo;

#[pallet::config]
pub trait Config: frame_system::Config {
// --- substrate ---
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type WeightInfo: WeightInfo;
// --- darwinia ---
#[pallet::constant]
type ModuleId: Get<ModuleId>;
type RingCurrency: Currency<AccountId<Self>>;
}
}

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

decl_storage! {
trait Store for Module<T: Config> as DarwiniaCrabIssuing {
pub TotalMappedRing get(fn total_mapped_ring) config(): MappedRing;
}
#[pallet::error]
pub enum Error<T> {}

#[pallet::storage]
#[pallet::getter(fn total_mapped_ring)]
pub type TotalMappedRing<T: Config> = StorageValue<_, MappedRing>;

add_extra_genesis {
build(|config| {
#[cfg_attr(feature = "std", derive(Default))]
#[pallet::genesis_config]
pub struct GenesisConfig {
pub total_mapped_ring: MappedRing,
}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
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);
});
<TotalMappedRing<T>>::put(self.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;
}
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
}

impl<T: Config> Module<T> {
pub fn account_id() -> T::AccountId {
T::ModuleId::get().into_account()
pub mod migration {
const OLD_PALLET_NAME: &[u8] = b"DarwiniaCrabIssuing";

pub fn migrate(new_pallet_name: &[u8]) {
frame_support::migration::move_pallet(OLD_PALLET_NAME, new_pallet_name);
}
}
18 changes: 11 additions & 7 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 All @@ -31,12 +33,12 @@ use sp_runtime::{
// --- darwinia ---
use crate::{self as darwinia_crab_issuing, *};

// Global primitives
pub type Block = MockBlock<Test>;
pub type UncheckedExtrinsic = MockUncheckedExtrinsic<Test>;

pub type AccountId = u64;
pub type Balance = u128;

// Pallet primitives
pub type CrabIssuingError = Error<Test>;

darwinia_support::impl_test_account_data! {}
Expand Down Expand Up @@ -100,7 +102,7 @@ frame_support::construct_runtime! {
{
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
Ring: darwinia_balances::<Instance0>::{Pallet, Call, Storage, Config<T>, Event<T>},
CrabIssuing: darwinia_crab_issuing::{Pallet, Call, Storage, Config, Event<T>},
DarwiniaCrabIssuing: darwinia_crab_issuing::{Pallet, Call, Storage, Config, Event<T>},
}
}

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

t.into()
Expand Down