Skip to content
Snippets Groups Projects
Select Git revision
  • badf52ce4bc3eb9429fe769d43a23292009efe30
  • master default protected
  • elois-ci-refactor protected
  • gtest
  • hugo/gtest
  • json-output
  • nostr
  • 48-error-base-58-requirement-is-violated
  • no-rename
  • hugo/tx-comments
  • poka/dev
  • hugo/dev
  • tuxmain/mail
  • test-gtest
  • 0.4.3-gtest-RC1
  • 0.4.3-RC2
  • 0.4.3-RC1
  • 0.4.2
  • 0.4.1
  • 0.4.0
  • 0.3.0
  • 0.2.17
  • 0.2.16
  • 0.2.15
  • 0.2.14
  • 0.2.13
  • 0.2.12
  • 0.2.10
  • 0.2.9
  • 0.2.8
  • 0.2.7
  • 0.2.6
  • 0.2.5
33 results

net_test.rs

Blame
    • Nicolas80's avatar
      badf52ce
      Adding db persistence for all SecretFormat of vault keys as well as supporting derivations · badf52ce
      Nicolas80 authored
      * Added "/.idea" exclusion in .gitignore (for when using JetBrains IDEs)
      * Added dialoguer dependency for easier user input handling (see in inputs.rs)
      * Added sea-orm dependency to allow having DB entity mappings and use a local sqlite file database
      * Added rstest test dependency for parameterized tests support
      * Added derivation tests for each SecretFormat (including cesium v1 key derivation, using sp_core::ed25519::Pair)
      * Made a lot of changes to add vault_account and vault_derivation db tables to persist vault keys & derivations
      * Added support for KeyPair::Ed25519 linking to sp_core::ed25519::Pair which can be created from secret seed retrieved from nacl::sign::Keypair (which is created from cesium id + secret)
      ** This was necessary to allow deriving keys from "cesium v1" keys (to be reviewed - it might be a bad idea to permit that from a security point of view)
      * Only kept original (substrate) keyfiles support for migration (use "vault list-files" and "vault migrate")
      * Added possibility to give either "-a" Address or "-v" Vault Name as general option
      * Added extra commands in Vault
      ** list-files: (deprecated)List available key files (needs to be migrated with command "vault migrate" in order to use them)
      ** migrate: (deprecated)Migrate old key files into db (will have to provide password for each key)
      ** 'list' now has sub-commands 'all' or 'root' to show all keys or only root keys (without derivation path)
      ** use: "Use specific vault key (changes the config address)", which will have the same behaviour as `gcli <-a <Address>|-v <VaultName>> config save` (left a FIXME in there to review)
      ** derivation: Add a derivation to an existing (root) vault key
      ** rename: Give a meaningful vault name to a vault key or derivation
      ** remove: Remove a vault key (and potential derivations if it's a root key)
      * Had to bubble up "await" and "async" in a lot of places
      * ...
      badf52ce
      History
      Adding db persistence for all SecretFormat of vault keys as well as supporting derivations
      Nicolas80 authored
      * Added "/.idea" exclusion in .gitignore (for when using JetBrains IDEs)
      * Added dialoguer dependency for easier user input handling (see in inputs.rs)
      * Added sea-orm dependency to allow having DB entity mappings and use a local sqlite file database
      * Added rstest test dependency for parameterized tests support
      * Added derivation tests for each SecretFormat (including cesium v1 key derivation, using sp_core::ed25519::Pair)
      * Made a lot of changes to add vault_account and vault_derivation db tables to persist vault keys & derivations
      * Added support for KeyPair::Ed25519 linking to sp_core::ed25519::Pair which can be created from secret seed retrieved from nacl::sign::Keypair (which is created from cesium id + secret)
      ** This was necessary to allow deriving keys from "cesium v1" keys (to be reviewed - it might be a bad idea to permit that from a security point of view)
      * Only kept original (substrate) keyfiles support for migration (use "vault list-files" and "vault migrate")
      * Added possibility to give either "-a" Address or "-v" Vault Name as general option
      * Added extra commands in Vault
      ** list-files: (deprecated)List available key files (needs to be migrated with command "vault migrate" in order to use them)
      ** migrate: (deprecated)Migrate old key files into db (will have to provide password for each key)
      ** 'list' now has sub-commands 'all' or 'root' to show all keys or only root keys (without derivation path)
      ** use: "Use specific vault key (changes the config address)", which will have the same behaviour as `gcli <-a <Address>|-v <VaultName>> config save` (left a FIXME in there to review)
      ** derivation: Add a derivation to an existing (root) vault key
      ** rename: Give a meaningful vault name to a vault key or derivation
      ** remove: Remove a vault key (and potential derivations if it's a root key)
      * Had to bubble up "await" and "async" in a lot of places
      * ...
    net_test.rs 2.79 KiB
    use crate::*;
    
    use sp_core::DeriveJunction;
    use subxt::ext::sp_runtime::MultiAddress;
    
    pub async fn repart(data: &Data, target: u32, actual_repart: Option<u32>) -> anyhow::Result<()> {
    	let KeyPair::Sr25519(keypair) = data.keypair().await else {
    		panic!("Cesium keys not implemented there")
    	};
    	let mut pairs = Vec::new();
    	for i in actual_repart.unwrap_or_default()..target {
    		let pair_i = keypair
    			.derive(std::iter::once(DeriveJunction::hard::<u32>(i)), None)
    			.map_err(|_| anyhow!("Fail to derive //{}", i))?
    			.0;
    		pairs.push((i, pair_i));
    	}
    
    	for (i, pair_i) in &pairs {
    		/*let _ = api
    			.tx()
    			.balances()
    			.transfer_allow_death(MultiAddress::Id(pair_i.public().into()), 501)?
    			.sign_and_submit_then_watch(&signer, DefaultExtrinsicParamsBuilder::new())
    			.await?
    			.wait_for_in_block()
    			.await?;
    		signer.increment_nonce();*/
    
    		if let Some(pair_i_account) = data
    			.client()
    			.storage()
    			.at_latest()
    			.await?
    			.fetch(&runtime::storage().system().account(&pair_i.public().into()))
    			.await?
    		{
    			log::info!("account //{} balance: {}", i, pair_i_account.data.free);
    		}
    	}
    
    	Ok(())
    }
    
    pub async fn spam_roll(data: &Data, actual_repart: usize) -> anyhow::Result<()> {
    	let KeyPair::Sr25519(keypair) = data.keypair().await else {
    		panic!("Cesium keys not implemented there")
    	};
    	let client = data.client();
    	let mut nonce = 0;
    	let mut pairs =
    		Vec::<(PairSigner<Runtime, sr25519::Pair>, AccountId)>::with_capacity(actual_repart);
    	for i in 0..actual_repart {
    		let pair_i = keypair
    			.derive(std::iter::once(DeriveJunction::hard::<u32>(i as u32)), None)
    			.map_err(|_| anyhow!("Fail to derive //{}", i))?
    			.0;
    		let account_id_i = pair_i.public().into();
    		pairs.push((PairSigner::new(pair_i), account_id_i));
    	}
    
    	loop {
    		let mut watchers = Vec::with_capacity(actual_repart);
    		for i in 0..(actual_repart - 1) {
    			let dest: AccountId = pairs[i + 1].1.clone();
    			let watcher = client
    				.tx()
    				.create_signed_offline(
    					&runtime::tx()
    						.balances()