Skip to content

Commit

Permalink
Review and improve assets-registrar (paritytech#232)
Browse files Browse the repository at this point in the history
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
  • Loading branch information
koushiro authored Sep 10, 2020
1 parent 6c7b28e commit 80bc2e3
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 75 deletions.
53 changes: 27 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion primitives/assets-registrar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "xp-assets-registrar"
version = "2.0.0-alpha.0"
authors = ["ChainX community <https://www.chainx.org>"]
authors = ["The ChainX Authors"]
edition = "2018"

[dependencies]
Expand Down
5 changes: 5 additions & 0 deletions primitives/assets-registrar/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// Copyright 2019-2020 ChainX Project Authors. Licensed under GPL-3.0.

//! The asset registrar primitives.
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(missing_docs)]

use chainx_primitives::AssetId;
use frame_support::dispatch::DispatchResult;
Expand Down
2 changes: 1 addition & 1 deletion xpallets/assets-registrar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "xpallet-assets-registrar"
version = "2.0.0-alpha.0"
authors = ["ChainX community <https://www.chainx.org>"]
authors = ["The ChainX Authors"]
edition = "2018"

[dependencies]
Expand Down
6 changes: 4 additions & 2 deletions xpallets/assets-registrar/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use super::*;
// Copyright 2019-2020 ChainX Project Authors. Licensed under GPL-3.0.

pub use frame_benchmarking::{account, benchmarks};
use frame_benchmarking::benchmarks;
use frame_system::RawOrigin;

use super::*;

const ASSET_ID: AssetId = 8888;

fn b_asset_info_test_data<T: Trait>() -> AssetInfo {
Expand Down
10 changes: 6 additions & 4 deletions xpallets/assets-registrar/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2019-2020 ChainX Project Authors. Licensed under GPL-3.0.

//! This crate provides the feature of managing the native and foreign assets' meta information.
//!
//! The foreign asset hereby means it's not the native token of the system(PCX for ChainX)
Expand Down Expand Up @@ -28,12 +30,11 @@ use frame_support::{
};
use frame_system::ensure_root;

// ChainX
use chainx_primitives::{AssetId, Decimals, Desc, Token};
use xpallet_support::info;

pub use verifier::*;
pub use weight_info::WeightInfo;
pub use self::verifier::*;
pub use self::weight_info::WeightInfo;
pub use xp_assets_registrar::RegistrarHandler;

#[derive(PartialEq, Eq, Ord, PartialOrd, Clone, Copy, Encode, Decode, RuntimeDebug)]
Expand Down Expand Up @@ -190,7 +191,7 @@ decl_error! {
/// only allow ASCII alphanumeric character or '-', '.', '|', '~'
InvalidChar,
/// only allow ASCII alphanumeric character
InvalidAsscii,
InvalidAscii,
/// The asset already exists.
AssetAlreadyExists,
/// The asset is already valid, no need to recover.
Expand All @@ -201,6 +202,7 @@ decl_error! {
AssetDoesNotExist,
}
}

decl_storage! {
trait Store for Module<T: Trait> as XAssetsRegistrar {
/// Asset id list for each Chain.
Expand Down
9 changes: 6 additions & 3 deletions xpallets/assets-registrar/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::*;
use crate::{Module, Trait};
use chainx_primitives::AssetId;
// Copyright 2019-2020 ChainX Project Authors. Licensed under GPL-3.0.

use frame_support::{
assert_noop, assert_ok, impl_outer_event, impl_outer_origin, parameter_types, sp_io,
weights::Weight,
Expand All @@ -12,8 +11,11 @@ use sp_runtime::{
Perbill,
};

use chainx_primitives::AssetId;
use xpallet_protocol::X_BTC;

use crate::*;

/// The AccountId alias in this test module.
pub(crate) type BlockNumber = u64;

Expand Down Expand Up @@ -118,6 +120,7 @@ impl ExtBuilder {
let ext = sp_io::TestExternalities::new(storage);
ext
}

pub fn build_and_execute(self, test: impl FnOnce() -> ()) {
let btc_assets = btc();
let assets = vec![(btc_assets.0, btc_assets.1, true, true)];
Expand Down
Loading

0 comments on commit 80bc2e3

Please sign in to comment.