Skip to content

Commit

Permalink
Feature/balances system (paritytech#163)
Browse files Browse the repository at this point in the history
* move balances&transaction-payment into chainx

* fix assets

* fix gateway

* fix xcontracts

* add transfer_with_memo in pallet-balances

* add debug in pallet-transaction-payment

* fix bug for `TotalAssetBalance`

* add assets test

* Balances migration for Mining and DEX (paritytech#162)

* Add sketch of generic-reserves

* Introduce NativeReservedType

* Add move_reserved_asset()

* Only record NativeReservedType in generic-reserves

* Change storage item name to NativeReserves

* Replace xpallet_assets with Currency

* Impl Staking issue and move_balance

* LockableCurrency is required

* Test mint_should_work()

* Impl bond_reserve()

* Finish balances migration for Staking

* Remove xpallet-assets in Staking

* Replace T::Balance with BalanceOf<T> in DEX

* Impl native reserves

* Pass partial DEX tests

* Do not silence the asset error

* Curreny in assets has be Reserable and Lockable

* Use Currency from assets if neccesary

* Migrate mining/asset

* Add StakingInterface in mining/asset

* Fix a fatal storage naming error

* Pass mining/asset tests

* Pass DEX tests

* Fix runtime migration

* Fix balances genesis

The balances has duplicated items which are problematic.

* finish xassets tests

* add doc for rpc

Co-authored-by: Liu-Cheng Xu <xuliuchengxlc@gmail.com>
  • Loading branch information
atenjin and liuchengxu committed Jul 31, 2020
1 parent 5f28f80 commit efde0d5
Show file tree
Hide file tree
Showing 63 changed files with 5,051 additions and 1,434 deletions.
134 changes: 78 additions & 56 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ members = [
"primitives/mining/staking",
"rpc",

"frame/balances",
"frame/transaction-payment",
"frame/transaction-payment/rpc",
"frame/transaction-payment/rpc/runtime-api",

"xpallets/assets",
"xpallets/assets/rpc",
"xpallets/assets/rpc/runtime-api",
Expand All @@ -37,9 +42,6 @@ members = [
"xpallets/mining/staking/rpc/runtime-api",
"xpallets/protocol",
"xpallets/support",
"xpallets/transaction-payment",
"xpallets/transaction-payment/rpc",
"xpallets/transaction-payment/rpc/runtime-api",
]

[profile.release]
Expand Down
53 changes: 29 additions & 24 deletions cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::collections::BTreeMap;
use std::convert::TryFrom;

use chainx_runtime::{
constants, trustees, AssetInfo, AssetRestriction, AssetRestrictions, BtcNetwork, BtcParams,
BtcTxVerifier, Chain, ContractsSchedule, NetworkType, TrusteeInfoConfig,
constants, trustees, AssetInfo, AssetRestriction, AssetRestrictions, BtcParams, BtcTxVerifier,
Chain, ContractsSchedule, NetworkType, TrusteeInfoConfig,
};
use chainx_runtime::{AccountId, AssetId, Balance, Runtime, Signature, WASM_BINARY};
use chainx_runtime::{
AuraConfig, GenesisConfig, GrandpaConfig, ImOnlineConfig, SessionConfig, SessionKeys,
SudoConfig, SystemConfig, XAssetsConfig, XContractsConfig, XGatewayBitcoinConfig,
AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, ImOnlineConfig, SessionConfig,
SessionKeys, SudoConfig, SystemConfig, XAssetsConfig, XContractsConfig, XGatewayBitcoinConfig,
XGatewayCommonConfig, XMiningAssetConfig, XSpotConfig, XStakingConfig, XSystemConfig,
};

Expand Down Expand Up @@ -270,6 +270,29 @@ fn testnet_genesis(
)>,
enable_println: bool,
) -> GenesisConfig {
const ENDOWMENT: Balance = 10_000_000 * constants::currency::DOLLARS;
// const STASH: Balance = 100 * constants::currency::DOLLARS;

let balances = endowed
.get(&xpallet_protocol::PCX)
.expect("PCX endowed; qed")
.iter()
.cloned()
.map(|(k, _)| (k, ENDOWMENT))
.collect::<Vec<_>>();

let validators = {
let staking_authorities = initial_authorities
.iter()
.map(|(s, _, _, _, _)| s)
.collect::<Vec<_>>();
balances
.clone()
.into_iter()
.filter(|(v, _)| staking_authorities.contains(&v))
.collect()
};

GenesisConfig {
frame_system: Some(SystemConfig {
code: WASM_BINARY.to_vec(),
Expand All @@ -294,6 +317,7 @@ fn testnet_genesis(
})
.collect::<Vec<_>>(),
}),
pallet_balances: Some(BalancesConfig { balances }),
pallet_sudo: Some(SudoConfig { key: root_key }),
xpallet_system: Some(XSystemConfig {
network_props: NetworkType::Testnet,
Expand Down Expand Up @@ -326,26 +350,7 @@ fn testnet_genesis(
})
},
xpallet_mining_staking: Some(XStakingConfig {
validators: {
let pcx_endowed: std::collections::HashMap<AccountId, Balance> = endowed
.get(&xpallet_protocol::PCX)
.expect("PCX endowed; qed")
.iter()
.cloned()
.collect();
initial_authorities
.iter()
.map(|x| {
(
x.0.clone(),
pcx_endowed
.get(&x.0)
.expect("initial validators must have some balances; qed")
.clone(),
)
})
.collect()
},
validators,
validator_count: 1000,
minimum_validator_count: 4,
sessions_per_era: 12,
Expand Down
43 changes: 43 additions & 0 deletions frame/balances/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "pallet-balances"
version = "2.0.0-rc4"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "Apache-2.0"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/substrate/"
description = "FRAME pallet to manage balances"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
serde = { version = "1.0.101", optional = true }
codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive"] }
sp-std = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", default-features = false }
frame-benchmarking = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", default-features = false, optional = true }
frame-support = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", default-features = false }

chainx-primitives = { path = "../../primitives", default-features = false }

[dev-dependencies]
sp-io = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", default-features = false }
pallet-transaction-payment = { path = "../transaction-payment", default-features = false }

[features]
default = ["std"]
std = [
"serde",
"codec/std",
"sp-std/std",
"sp-runtime/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",

"chainx-primitives/std",
]
runtime-benchmarks = ["frame-benchmarking"]
Loading

0 comments on commit efde0d5

Please sign in to comment.