Skip to content
Snippets Groups Projects
Select Git revision
  • 94ed2f47cbaaef483fcbc16491f947c9e11b3c41
  • 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

blockchain.rs

Blame
  • blockchain.rs 1.76 KiB
    use crate::*;
    
    /// define blockchain subcommands
    #[derive(Clone, Default, Debug, clap::Parser)]
    pub enum Subcommand {
    	#[clap(hide = true)]
    	Repart {
    		// Number of transactions per block to target
    		target: u32,
    		#[clap(short = 'o', long = "old-repart")]
    		// Old/actual repartition
    		actual_repart: Option<u32>,
    	},
    	#[clap(hide = true)]
    	SpamRoll { actual_repart: usize },
    	/// Get information about runtime
    	RuntimeInfo,
    	/// Check current block
    	#[default]
    	CurrentBlock,
    	/// Create one block manually (manual sealing)
    	#[clap(hide = true)]
    	CreateBlock,
    }
    
    /// handle blockchain commands
    pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> {
    	let mut data = data.build_client().await?;
    	match command {
    		Subcommand::Repart {
    			target,
    			actual_repart,
    		} => commands::net_test::repart(&data, target, actual_repart).await?,
    		Subcommand::SpamRoll { actual_repart } => {
    			commands::net_test::spam_roll(&data, actual_repart).await?
    		}
    		Subcommand::RuntimeInfo => {
    			data = data.fetch_system_properties().await?;
    			commands::runtime::runtime_info(data).await;
    		}
    		Subcommand::CurrentBlock => {
    			println!(
    				"current block on {}: {}",
    				data.cfg.duniter_endpoint,
    				data.client()
    					.storage()
    					.fetch(&runtime::storage().system().number(), None)
    					.await?
    					.unwrap()
    			);
    		}
    		Subcommand::CreateBlock => {
    			data.client()
    				.rpc()
    				.request("engine_createBlock", subxt::rpc::rpc_params![true, true]) // create empty block and finalize
    				.await?; // FIXME this gives a serialization error
    		}
    	}
    	Ok(())
    }
    
    /// get genesis hash
    pub async fn fetch_genesis_hash(data: &Data) -> Result<Hash, anyhow::Error> {
    	Ok(data
    		.client()
    		.storage()
    		.fetch(&runtime::storage().system().block_hash(0), None)
    		.await?
    		.unwrap())
    }