Skip to content
Snippets Groups Projects
Select Git revision
  • 2219a948c538b59230da3505087506ccde78ae87
  • master default protected
  • network/gtest-1000 protected
  • upgradable-multisig
  • runtime/gtest-1000
  • network/gdev-800 protected
  • cgeek/issue-297-cpu
  • gdev-800-tests
  • update-docker-compose-rpc-squid-names
  • fix-252
  • 1000i100-test
  • hugo/tmp-0.9.1
  • network/gdev-803 protected
  • hugo/endpoint-gossip
  • network/gdev-802 protected
  • hugo/distance-precompute
  • network/gdev-900 protected
  • tuxmain/anonymous-tx
  • debug/podman
  • hugo/195-doc
  • hugo/195-graphql-schema
  • gtest-1000-0.11.0 protected
  • gtest-1000 protected
  • gdev-900-0.10.1 protected
  • gdev-900-0.10.0 protected
  • gdev-900-0.9.2 protected
  • gdev-800-0.8.0 protected
  • gdev-900-0.9.1 protected
  • gdev-900-0.9.0 protected
  • gdev-803 protected
  • gdev-802 protected
  • runtime-801 protected
  • gdev-800 protected
  • runtime-800-bis protected
  • runtime-800 protected
  • runtime-800-backup protected
  • runtime-701 protected
  • runtime-700 protected
  • runtime-600 protected
  • runtime-500 protected
  • v0.4.1 protected
41 results

chain_spec.rs

Blame
    • Hugo Trentesaux's avatar
      ca6c877e
      gtest genesis new format (nodes/rust/duniter-v2s!168) · ca6c877e
      Hugo Trentesaux authored
      * fix smith certification validity
      
      * get values of parameters
      
      * tuxmain review
      
      * add checks and improve formatting
      
      * improve genesis parsing
      
      adds info
      
      * fix json with new format
      
      * fix warnings
      
      * new gtest genesis format
      
      * get build working with gtest feature
      
      `cargo build --features gtest --no-default-features`
      
      * update lib.rs
      
      * update cargo.toml
      
      * add readme for runtimes
      ca6c877e
      History
      gtest genesis new format (nodes/rust/duniter-v2s!168)
      Hugo Trentesaux authored
      * fix smith certification validity
      
      * get values of parameters
      
      * tuxmain review
      
      * add checks and improve formatting
      
      * improve genesis parsing
      
      adds info
      
      * fix json with new format
      
      * fix warnings
      
      * new gtest genesis format
      
      * get build working with gtest feature
      
      `cargo build --features gtest --no-default-features`
      
      * update lib.rs
      
      * update cargo.toml
      
      * add readme for runtimes
    oneshot.rs 4.34 KiB
    use crate::*;
    
    /// define oneshot account subcommands
    #[derive(Clone, Default, Debug, clap::Parser)]
    pub enum Subcommand {
    	/// get balance of oneshot account
    	#[default]
    	Balance,
    	/// create a oneshot account
    	Create { balance: u64, dest: AccountId },
    	/// consume a oneshot account
    	Consume {
    		dest: AccountId,
    		#[clap(long = "oneshot")]
    		dest_oneshot: bool,
    	},
    	/// consume a oneshot account whith remaining sent to an other account
    	ConsumeWithRemaining {
    		balance: u64,
    		dest: AccountId,
    		#[clap(long = "one")]
    		dest_oneshot: bool,
    		remaining_to: AccountId,
    		#[clap(long = "rem-one")]
    		remaining_to_oneshot: bool,
    	},
    }
    
    /// handle oneshot commands
    pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliError> {
    	// build indexer because it is needed for all subcommands
    	let mut data = data.build_client().await?;
    	// match subcommand
    	match command {
    		Subcommand::Balance => oneshot_account_balance(&data).await?,
    		Subcommand::Create { balance, dest } => {
    			data = data.build_client().await?;
    			create_oneshot_account(&data, balance, dest).await?;
    		}
    		Subcommand::Consume { dest, dest_oneshot } => {
    			data = data.build_client().await?;
    			consume_oneshot_account(&data, dest, dest_oneshot).await?;
    		}
    		Subcommand::ConsumeWithRemaining {
    			balance,
    			dest,
    			dest_oneshot,
    			remaining_to,
    			remaining_to_oneshot,
    		} => {
    			data = data.build_client().await?;
    			consume_oneshot_account_with_remaining(
    				&data,
    				balance,
    				dest,
    				dest_oneshot,
    				remaining_to,
    				remaining_to_oneshot,
    			)
    			.await?;
    		}
    	};
    
    	Ok(())
    }
    
    /// get balance of oneshot account
    pub async fn oneshot_account_balance(data: &Data) -> Result<(), subxt::Error> {
    	println!(
    		"balance of oneshot account {} is: {}",
    		data.address(),
    		data.client()
    			.storage()
    			.at_latest()
    			.await?
    			.fetch(
    				&runtime::storage()
    					.oneshot_account()
    					.oneshot_accounts(data.address()),
    			)
    			.await?
    			.unwrap_or(0)
    	);
    
    	Ok(())
    }
    
    /// create oneshot account
    pub async fn create_oneshot_account(
    	data: &Data,
    	balance: u64,
    	dest: AccountId,
    ) -> Result<(), subxt::Error> {
    	submit_call_and_look_event::<
    		runtime::oneshot_account::events::OneshotAccountCreated,
    		StaticPayload<runtime::oneshot_account::calls::types::CreateOneshotAccount>,
    	>(
    		data,
    		&runtime::tx()
    			.oneshot_account()
    			.create_oneshot_account(dest.into(), balance),
    	)
    	.await
    }
    
    /// consume oneshot account
    pub async fn consume_oneshot_account(
    	data: &Data,
    	dest: AccountId,
    	dest_oneshot: bool,
    ) -> Result<(), subxt::Error> {
    	let client = data.client();
    	let number = client
    		.storage()
    		.at_latest()
    		.await?
    		.fetch(&runtime::storage().system().number())
    		.await?
    		.unwrap();
    	let payload = &runtime::tx().oneshot_account().consume_oneshot_account(
    		number,
    		if dest_oneshot {
    			runtime::runtime_types::pallet_oneshot_account::types::Account::Oneshot(dest.into())
    		} else {
    			runtime::runtime_types::pallet_oneshot_account::types::Account::Normal(dest.into())
    		},
    	);
    	submit_call_and_look_event::<
    		runtime::oneshot_account::events::OneshotAccountConsumed,
    		StaticPayload<runtime::oneshot_account::calls::types::ConsumeOneshotAccount>,
    	>(data, payload)
    	.await
    }
    
    /// consume oneshot account with remaining
    pub async fn consume_oneshot_account_with_remaining(
    	data: &Data,
    	balance: u64,
    	dest: AccountId,
    	dest_oneshot: bool,
    	remaining_to: AccountId,
    	remaining_to_oneshot: bool,
    ) -> Result<(), subxt::Error> {
    	let client = data.client();
    
    	let number = client
    		.storage()
    		.at_latest()
    		.await?
    		.fetch(&runtime::storage().system().number())
    		.await?
    		.unwrap();
    
    	let payload = &runtime::tx()
    		.oneshot_account()
    		.consume_oneshot_account_with_remaining(
    			number,
    			if dest_oneshot {
    				runtime::runtime_types::pallet_oneshot_account::types::Account::Oneshot(dest.into())
    			} else {
    				runtime::runtime_types::pallet_oneshot_account::types::Account::Normal(dest.into())
    			},
    			if remaining_to_oneshot {
    				runtime::runtime_types::pallet_oneshot_account::types::Account::Oneshot(
    					remaining_to.into(),
    				)
    			} else {
    				runtime::runtime_types::pallet_oneshot_account::types::Account::Normal(
    					remaining_to.into(),
    				)
    			},
    			balance,
    		);
    
    	submit_call_and_look_event::<
    		runtime::oneshot_account::events::OneshotAccountConsumed,
    		StaticPayload<runtime::oneshot_account::calls::types::ConsumeOneshotAccountWithRemaining>,
    	>(data, payload)
    	.await
    }