mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +00:00
@@ -33,7 +33,6 @@ use sp_runtime::{
|
||||
generic::Era, traits::{Block as BlockT, Header as HeaderT, SignedExtension, Verify, IdentifyAccount}
|
||||
};
|
||||
use node_transaction_factory::RuntimeAdapter;
|
||||
use node_transaction_factory::modes::Mode;
|
||||
use sp_inherents::InherentData;
|
||||
use sp_timestamp;
|
||||
use sp_finality_tracker;
|
||||
@@ -41,14 +40,10 @@ use sp_finality_tracker;
|
||||
type AccountPublic = <Signature as Verify>::Signer;
|
||||
|
||||
pub struct FactoryState<N> {
|
||||
block_no: N,
|
||||
|
||||
mode: Mode,
|
||||
start_number: u32,
|
||||
rounds: u32,
|
||||
round: u32,
|
||||
block_in_round: u32,
|
||||
num: u32,
|
||||
blocks: u32,
|
||||
transactions: u32,
|
||||
block_number: N,
|
||||
index: u32,
|
||||
}
|
||||
|
||||
type Number = <<node_primitives::Block as BlockT>::Header as HeaderT>::Number;
|
||||
@@ -78,63 +73,35 @@ impl RuntimeAdapter for FactoryState<Number> {
|
||||
type Number = Number;
|
||||
|
||||
fn new(
|
||||
mode: Mode,
|
||||
num: u64,
|
||||
rounds: u64,
|
||||
blocks: u32,
|
||||
transactions: u32,
|
||||
) -> FactoryState<Self::Number> {
|
||||
FactoryState {
|
||||
mode,
|
||||
num: num as u32,
|
||||
round: 0,
|
||||
rounds: rounds as u32,
|
||||
block_in_round: 0,
|
||||
block_no: 0,
|
||||
start_number: 0,
|
||||
blocks,
|
||||
transactions,
|
||||
block_number: 0,
|
||||
index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn block_no(&self) -> Self::Number {
|
||||
self.block_no
|
||||
fn block_number(&self) -> u32 {
|
||||
self.block_number
|
||||
}
|
||||
|
||||
fn block_in_round(&self) -> Self::Number {
|
||||
self.block_in_round
|
||||
fn blocks(&self) -> u32 {
|
||||
self.blocks
|
||||
}
|
||||
|
||||
fn rounds(&self) -> Self::Number {
|
||||
self.rounds
|
||||
fn transactions(&self) -> u32 {
|
||||
self.transactions
|
||||
}
|
||||
|
||||
fn num(&self) -> Self::Number {
|
||||
self.num
|
||||
}
|
||||
|
||||
fn round(&self) -> Self::Number {
|
||||
self.round
|
||||
}
|
||||
|
||||
fn start_number(&self) -> Self::Number {
|
||||
self.start_number
|
||||
}
|
||||
|
||||
fn mode(&self) -> &Mode {
|
||||
&self.mode
|
||||
}
|
||||
|
||||
fn set_block_no(&mut self, val: Self::Number) {
|
||||
self.block_no = val;
|
||||
}
|
||||
|
||||
fn set_block_in_round(&mut self, val: Self::Number) {
|
||||
self.block_in_round = val;
|
||||
}
|
||||
|
||||
fn set_round(&mut self, val: Self::Number) {
|
||||
self.round = val;
|
||||
fn set_block_number(&mut self, value: u32) {
|
||||
self.block_number = value;
|
||||
}
|
||||
|
||||
fn transfer_extrinsic(
|
||||
&self,
|
||||
&mut self,
|
||||
sender: &Self::AccountId,
|
||||
key: &Self::Secret,
|
||||
destination: &Self::AccountId,
|
||||
@@ -143,10 +110,12 @@ impl RuntimeAdapter for FactoryState<Number> {
|
||||
genesis_hash: &<Self::Block as BlockT>::Hash,
|
||||
prior_block_hash: &<Self::Block as BlockT>::Hash,
|
||||
) -> <Self::Block as BlockT>::Extrinsic {
|
||||
let index = self.extract_index(&sender, prior_block_hash);
|
||||
let phase = self.extract_phase(*prior_block_hash);
|
||||
let phase = self.block_number() as Self::Phase;
|
||||
let extra = Self::build_extra(self.index, phase);
|
||||
self.index += 1;
|
||||
|
||||
sign::<Self>(CheckedExtrinsic {
|
||||
signed: Some((sender.clone(), Self::build_extra(index, phase))),
|
||||
signed: Some((sender.clone(), extra)),
|
||||
function: Call::Balances(
|
||||
BalancesCall::transfer(
|
||||
pallet_indices::address::Address::Id(destination.clone().into()),
|
||||
@@ -157,12 +126,12 @@ impl RuntimeAdapter for FactoryState<Number> {
|
||||
}
|
||||
|
||||
fn inherent_extrinsics(&self) -> InherentData {
|
||||
let timestamp = (self.block_no as u64 + 1) * MinimumPeriod::get();
|
||||
let timestamp = (self.block_number as u64 + 1) * MinimumPeriod::get();
|
||||
|
||||
let mut inherent = InherentData::new();
|
||||
inherent.put_data(sp_timestamp::INHERENT_IDENTIFIER, ×tamp)
|
||||
.expect("Failed putting timestamp inherent");
|
||||
inherent.put_data(sp_finality_tracker::INHERENT_IDENTIFIER, &self.block_no)
|
||||
inherent.put_data(sp_finality_tracker::INHERENT_IDENTIFIER, &self.block_number)
|
||||
.expect("Failed putting finalized number inherent");
|
||||
inherent
|
||||
}
|
||||
@@ -180,49 +149,16 @@ impl RuntimeAdapter for FactoryState<Number> {
|
||||
}
|
||||
|
||||
/// Generates a random `AccountId` from `seed`.
|
||||
fn gen_random_account_id(seed: &Self::Number) -> Self::AccountId {
|
||||
let pair: sr25519::Pair = sr25519::Pair::from_seed(&gen_seed_bytes(*seed));
|
||||
fn gen_random_account_id(seed: u32) -> Self::AccountId {
|
||||
let pair: sr25519::Pair = sr25519::Pair::from_seed(&gen_seed_bytes(seed));
|
||||
AccountPublic::from(pair.public()).into_account()
|
||||
}
|
||||
|
||||
/// Generates a random `Secret` from `seed`.
|
||||
fn gen_random_account_secret(seed: &Self::Number) -> Self::Secret {
|
||||
let pair: sr25519::Pair = sr25519::Pair::from_seed(&gen_seed_bytes(*seed));
|
||||
fn gen_random_account_secret(seed: u32) -> Self::Secret {
|
||||
let pair: sr25519::Pair = sr25519::Pair::from_seed(&gen_seed_bytes(seed));
|
||||
pair
|
||||
}
|
||||
|
||||
fn extract_index(
|
||||
&self,
|
||||
_account_id: &Self::AccountId,
|
||||
_block_hash: &<Self::Block as BlockT>::Hash,
|
||||
) -> Self::Index {
|
||||
// TODO get correct index for account via api. See #2587.
|
||||
// This currently prevents the factory from being used
|
||||
// without a preceding purge of the database.
|
||||
if self.mode == Mode::MasterToN || self.mode == Mode::MasterTo1 {
|
||||
self.block_no() as Self::Index
|
||||
} else {
|
||||
match self.round() {
|
||||
0 =>
|
||||
// if round is 0 all transactions will be done with master as a sender
|
||||
self.block_no() as Self::Index,
|
||||
_ =>
|
||||
// if round is e.g. 1 every sender account will be new and not yet have
|
||||
// any transactions done
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_phase(
|
||||
&self,
|
||||
_block_hash: <Self::Block as BlockT>::Hash
|
||||
) -> Self::Phase {
|
||||
// TODO get correct phase via api. See #2587.
|
||||
// This currently prevents the factory from being used
|
||||
// without a preceding purge of the database.
|
||||
self.block_no() as Self::Phase
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_seed_bytes(seed: u32) -> [u8; 32] {
|
||||
|
||||
Reference in New Issue
Block a user