mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 14:01:02 +00:00
Introduce 128-bit shim for u128/i128 and use it for Balance (#163)
* Add 128-bit shim and use for balance. * Fix tests. * Fix wasm build.
This commit is contained in:
committed by
Robert Habermeier
parent
bc3242ca77
commit
59e8adb604
@@ -140,7 +140,7 @@ pub trait PolkadotApi {
|
|||||||
fn evaluate_block(&self, at: &Self::CheckedBlockId, block: Block) -> Result<()>;
|
fn evaluate_block(&self, at: &Self::CheckedBlockId, block: Block) -> Result<()>;
|
||||||
|
|
||||||
/// Create a block builder on top of the parent block.
|
/// Create a block builder on top of the parent block.
|
||||||
fn build_block(&self, parent: &Self::CheckedBlockId, timestamp: u64) -> Result<Self::BlockBuilder>;
|
fn build_block(&self, parent: &Self::CheckedBlockId, timestamp: Timestamp) -> Result<Self::BlockBuilder>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A checked block ID used for the substrate-client implementation of CheckedBlockId;
|
/// A checked block ID used for the substrate-client implementation of CheckedBlockId;
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ pub use primitives::block::Id as BlockId;
|
|||||||
pub use primitives::block::Log as Log;
|
pub use primitives::block::Log as Log;
|
||||||
|
|
||||||
/// An index to a block.
|
/// An index to a block.
|
||||||
|
/// 32-bits will allow for 136 years of blocks assuming 1 block per second.
|
||||||
|
/// TODO: switch to u32
|
||||||
pub type BlockNumber = u64;
|
pub type BlockNumber = u64;
|
||||||
|
|
||||||
/// Alias to Ed25519 pubkey that identifies an account on the relay chain. This will almost
|
/// Alias to Ed25519 pubkey that identifies an account on the relay chain. This will almost
|
||||||
@@ -60,11 +62,11 @@ pub type AccountId = primitives::AuthorityId;
|
|||||||
/// exactly equivalent to what the substrate calls an "authority".
|
/// exactly equivalent to what the substrate calls an "authority".
|
||||||
pub type SessionKey = primitives::AuthorityId;
|
pub type SessionKey = primitives::AuthorityId;
|
||||||
|
|
||||||
/// Indentifier for a chain.
|
/// Indentifier for a chain. 32-bit should be plenty.
|
||||||
pub type ChainId = u64;
|
pub type ChainId = u32;
|
||||||
|
|
||||||
/// Index of a transaction in the relay chain.
|
/// Index of a transaction in the relay chain. 32-bit should be plenty.
|
||||||
pub type Index = u64;
|
pub type Index = u32;
|
||||||
|
|
||||||
/// A hash of some data used by the relay chain.
|
/// A hash of some data used by the relay chain.
|
||||||
pub type Hash = primitives::H256;
|
pub type Hash = primitives::H256;
|
||||||
@@ -76,4 +78,10 @@ pub type Signature = runtime_primitives::Ed25519Signature;
|
|||||||
pub type Timestamp = u64;
|
pub type Timestamp = u64;
|
||||||
|
|
||||||
/// The balance of an account.
|
/// The balance of an account.
|
||||||
pub type Balance = u64;
|
/// 128-bits (or 38 significant decimal figures) will allow for 10m currency (10^7) at a resolution
|
||||||
|
/// to all for one second's worth of an annualised 50% reward be paid to a unit holder (10^11 unit
|
||||||
|
/// denomination), or 10^18 total atomic units, to grow at 50%/year for 51 years (10^9 multiplier)
|
||||||
|
/// for an eventual total of 10^27 units (27 significant decimal figures).
|
||||||
|
/// We round denomination to 10^12 (12 sdf), and leave the other redundancy at the upper end so
|
||||||
|
/// that 32 bits may be multiplied with a balance in 128 bits without worrying about overflow.
|
||||||
|
pub type Balance = runtime_primitives::U128;
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ mod tests {
|
|||||||
let tx = UncheckedExtrinsic {
|
let tx = UncheckedExtrinsic {
|
||||||
extrinsic: Extrinsic {
|
extrinsic: Extrinsic {
|
||||||
signed: [1; 32],
|
signed: [1; 32],
|
||||||
index: 999u64,
|
index: 999,
|
||||||
function: Call::Timestamp(TimestampCall::set(135135)),
|
function: Call::Timestamp(TimestampCall::set(135135)),
|
||||||
},
|
},
|
||||||
signature: primitives::hash::H512([0; 64]).into(),
|
signature: primitives::hash::H512([0; 64]).into(),
|
||||||
@@ -307,7 +307,7 @@ mod tests {
|
|||||||
fn serialize_checked() {
|
fn serialize_checked() {
|
||||||
let xt = Extrinsic {
|
let xt = Extrinsic {
|
||||||
signed: hex!["0d71d1a9cad6f2ab773435a7dec1bac019994d05d1dd5eb3108211dcf25c9d1e"],
|
signed: hex!["0d71d1a9cad6f2ab773435a7dec1bac019994d05d1dd5eb3108211dcf25c9d1e"],
|
||||||
index: 0u64,
|
index: 0,
|
||||||
function: Call::CouncilVoting(council::voting::Call::propose(Box::new(
|
function: Call::CouncilVoting(council::voting::Call::propose(Box::new(
|
||||||
PrivCall::Consensus(consensus::PrivCall::set_code(
|
PrivCall::Consensus(consensus::PrivCall::set_code(
|
||||||
vec![]
|
vec![]
|
||||||
@@ -316,7 +316,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
let v = Slicable::encode(&xt);
|
let v = Slicable::encode(&xt);
|
||||||
|
|
||||||
let data = hex!["e00000000d71d1a9cad6f2ab773435a7dec1bac019994d05d1dd5eb3108211dcf25c9d1e000000000000000007000000000000006369D39D892B7B87A6769F90E14C618C2B84EBB293E2CC46640136E112C078C75619AC2E0815F2511568736623C055156C8FC427CE2AEE4AE2838F86EFE80208"];
|
let data = hex!["e00000000d71d1a9cad6f2ab773435a7dec1bac019994d05d1dd5eb3108211dcf25c9d1e0000000007000000000000006369D39D892B7B87A6769F90E14C618C2B84EBB293E2CC46640136E112C078C75619AC2E0815F2511568736623C055156C8FC427CE2AEE4AE2838F86EFE80208"];
|
||||||
let uxt: UncheckedExtrinsic = Slicable::decode(&mut &data[..]).unwrap();
|
let uxt: UncheckedExtrinsic = Slicable::decode(&mut &data[..]).unwrap();
|
||||||
assert_eq!(uxt.extrinsic, xt);
|
assert_eq!(uxt.extrinsic, xt);
|
||||||
|
|
||||||
|
|||||||
Generated
+4
-4
@@ -159,7 +159,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "integer-sqrt"
|
name = "integer-sqrt"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/paritytech/integer-sqrt-rs.git#f4cf61482096dc98c1273f46a10849d182b4c23c"
|
source = "git+https://github.com/paritytech/integer-sqrt-rs.git#886e9cb983c46498003878afe965d55caa762025"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "keccak-hash"
|
name = "keccak-hash"
|
||||||
@@ -214,7 +214,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-traits"
|
name = "num-traits"
|
||||||
version = "0.2.2"
|
version = "0.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -618,7 +618,7 @@ name = "substrate-runtime-primitives"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"integer-sqrt 0.1.0 (git+https://github.com/paritytech/integer-sqrt-rs.git)",
|
"integer-sqrt 0.1.0 (git+https://github.com/paritytech/integer-sqrt-rs.git)",
|
||||||
"num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"substrate-codec 0.1.0",
|
"substrate-codec 0.1.0",
|
||||||
@@ -863,7 +863,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
|
"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
|
||||||
"checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882"
|
"checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882"
|
||||||
"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
|
"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
|
||||||
"checksum num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dee092fcdf725aee04dd7da1d21debff559237d49ef1cb3e69bcb8ece44c7364"
|
"checksum num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "775393e285254d2f5004596d69bb8bc1149754570dcc08cf30cabeba67955e28"
|
||||||
"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
|
"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
|
||||||
"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
|
"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
|
||||||
"checksum parity-wasm 0.27.6 (registry+https://github.com/rust-lang/crates.io-index)" = "bd4dc02a80a0315b109e48992c46942c79bcdb8fac416dd575d330ed9ced6cbd"
|
"checksum parity-wasm 0.27.6 (registry+https://github.com/rust-lang/crates.io-index)" = "bd4dc02a80a0315b109e48992c46942c79bcdb8fac416dd575d330ed9ced6cbd"
|
||||||
|
|||||||
BIN
Binary file not shown.
Binary file not shown.
+12
-12
@@ -154,8 +154,8 @@ fn poc_1_testnet_config() -> ChainConfig {
|
|||||||
staking: Some(StakingConfig {
|
staking: Some(StakingConfig {
|
||||||
current_era: 0,
|
current_era: 0,
|
||||||
intentions: initial_authorities.clone(),
|
intentions: initial_authorities.clone(),
|
||||||
transaction_fee: 100,
|
transaction_fee: 100.into(),
|
||||||
balances: endowed_accounts.iter().map(|&k|(k, 1u64 << 60)).collect(),
|
balances: endowed_accounts.iter().map(|&k|(k, (1u128 << 60).into())).collect(),
|
||||||
validator_count: 12,
|
validator_count: 12,
|
||||||
sessions_per_era: 24, // 24 hours per era.
|
sessions_per_era: 24, // 24 hours per era.
|
||||||
bonding_duration: 90, // 90 days per bond.
|
bonding_duration: 90, // 90 days per bond.
|
||||||
@@ -163,13 +163,13 @@ fn poc_1_testnet_config() -> ChainConfig {
|
|||||||
democracy: Some(DemocracyConfig {
|
democracy: Some(DemocracyConfig {
|
||||||
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
|
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
|
||||||
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
|
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
|
||||||
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
|
minimum_deposit: 1000.into(), // 1000 as the minimum deposit for a referendum
|
||||||
}),
|
}),
|
||||||
council: Some(CouncilConfig {
|
council: Some(CouncilConfig {
|
||||||
active_council: vec![],
|
active_council: vec![],
|
||||||
candidacy_bond: 1000, // 1000 to become a council candidate
|
candidacy_bond: 1000.into(), // 1000 to become a council candidate
|
||||||
voter_bond: 100, // 100 down to vote for a candidate
|
voter_bond: 100.into(), // 100 down to vote for a candidate
|
||||||
present_slash_per_voter: 1, // slash by 1 per voter for an invalid presentation.
|
present_slash_per_voter: 1.into(), // slash by 1 per voter for an invalid presentation.
|
||||||
carry_count: 24, // carry over the 24 runners-up to the next council election
|
carry_count: 24, // carry over the 24 runners-up to the next council election
|
||||||
presentation_duration: 120 * 24, // one day for presenting winners.
|
presentation_duration: 120 * 24, // one day for presenting winners.
|
||||||
approval_voting_period: 7 * 120 * 24, // one week period between possible council elections.
|
approval_voting_period: 7 * 120 * 24, // one week period between possible council elections.
|
||||||
@@ -212,8 +212,8 @@ fn testnet_config(initial_authorities: Vec<AuthorityId>) -> ChainConfig {
|
|||||||
staking: Some(StakingConfig {
|
staking: Some(StakingConfig {
|
||||||
current_era: 0,
|
current_era: 0,
|
||||||
intentions: initial_authorities.clone(),
|
intentions: initial_authorities.clone(),
|
||||||
transaction_fee: 1,
|
transaction_fee: 1.into(),
|
||||||
balances: endowed_accounts.iter().map(|&k|(k, 1u64 << 60)).collect(),
|
balances: endowed_accounts.iter().map(|&k|(k, (1u128 << 60).into())).collect(),
|
||||||
validator_count: 2,
|
validator_count: 2,
|
||||||
sessions_per_era: 5,
|
sessions_per_era: 5,
|
||||||
bonding_duration: 2,
|
bonding_duration: 2,
|
||||||
@@ -221,13 +221,13 @@ fn testnet_config(initial_authorities: Vec<AuthorityId>) -> ChainConfig {
|
|||||||
democracy: Some(DemocracyConfig {
|
democracy: Some(DemocracyConfig {
|
||||||
launch_period: 9,
|
launch_period: 9,
|
||||||
voting_period: 18,
|
voting_period: 18,
|
||||||
minimum_deposit: 10,
|
minimum_deposit: 10.into(),
|
||||||
}),
|
}),
|
||||||
council: Some(CouncilConfig {
|
council: Some(CouncilConfig {
|
||||||
active_council: endowed_accounts.iter().filter(|a| initial_authorities.iter().find(|b| a == b).is_none()).map(|a| (a.clone(), 1000000)).collect(),
|
active_council: endowed_accounts.iter().filter(|a| initial_authorities.iter().find(|b| a == b).is_none()).map(|a| (a.clone(), 1000000)).collect(),
|
||||||
candidacy_bond: 10,
|
candidacy_bond: 10.into(),
|
||||||
voter_bond: 2,
|
voter_bond: 2.into(),
|
||||||
present_slash_per_voter: 1,
|
present_slash_per_voter: 1.into(),
|
||||||
carry_count: 4,
|
carry_count: 4,
|
||||||
presentation_duration: 10,
|
presentation_duration: 10,
|
||||||
approval_voting_period: 20,
|
approval_voting_period: 20,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ use std::sync::Arc;
|
|||||||
use polkadot_api::PolkadotApi;
|
use polkadot_api::PolkadotApi;
|
||||||
use primitives::{AccountId, Timestamp};
|
use primitives::{AccountId, Timestamp};
|
||||||
use runtime::{Block, UncheckedExtrinsic, TimestampCall, Call};
|
use runtime::{Block, UncheckedExtrinsic, TimestampCall, Call};
|
||||||
use substrate_runtime_primitives::traits::Checkable;
|
use substrate_runtime_primitives::traits::{Bounded, Checkable};
|
||||||
use transaction_pool::{Pool, Readiness};
|
use transaction_pool::{Pool, Readiness};
|
||||||
use transaction_pool::scoring::{Change, Choice};
|
use transaction_pool::scoring::{Change, Choice};
|
||||||
|
|
||||||
@@ -295,7 +295,7 @@ impl<'a, T: 'a + PolkadotApi> transaction_pool::Ready<VerifiedTransaction> for R
|
|||||||
// transaction-pool trait.
|
// transaction-pool trait.
|
||||||
let (api_handle, at_block) = (&self.api_handle, &self.at_block);
|
let (api_handle, at_block) = (&self.api_handle, &self.at_block);
|
||||||
let next_index = self.known_indices.entry(sender)
|
let next_index = self.known_indices.entry(sender)
|
||||||
.or_insert_with(|| api_handle.index(at_block, sender).ok().unwrap_or_else(u64::max_value));
|
.or_insert_with(|| api_handle.index(at_block, sender).ok().unwrap_or_else(Bounded::max_value));
|
||||||
|
|
||||||
trace!(target: "transaction-pool", "Next index for sender is {}; xt index is {}", next_index, xt.inner.index);
|
trace!(target: "transaction-pool", "Next index for sender is {}; xt index is {}", next_index, xt.inner.index);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user