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

utils.rs

Blame
  • utils.rs 1.85 KiB
    use crate::*;
    
    /// track progress of transaction on the network
    /// until it is in block with success or failure
    pub async fn track_progress(
    	mut progress: TxProgress,
    ) -> Result<ExtrinsicEvents<Runtime>, subxt::Error> {
    	loop {
    		if let Some(status) = progress.next_item().await {
    			match status? {
    				TxStatus::Ready => {
    					println!("transaction submitted to the network, waiting 6 seconds...");
    				}
    				TxStatus::InBlock(in_block) => break in_block,
    				TxStatus::Invalid => {
    					println!("Invalid");
    				}
    				_ => continue,
    			}
    		}
    	}
    	.wait_for_success()
    	.await
    }
    
    /// generic extrinsic submitter
    pub async fn submit_call_and_look_event<E: std::fmt::Debug + StaticEvent, Call: TxPayload>(
    	data: &Data,
    	call: &Call,
    ) -> Result<(), subxt::Error> {
    	let progress = data
    		.client()
    		.tx()
    		.sign_and_submit_then_watch(
    			call,
    			&PairSigner::new(data.keypair()),
    			BaseExtrinsicParamsBuilder::new(),
    		)
    		.await?;
    
    	if data.args.no_wait {
    		return Ok(());
    	}
    	let events = track_progress(progress).await?;
    	if let Some(e) = events.find_first::<E>()? {
    		println!("{e:?}");
    	}
    
    	Ok(())
    }
    
    /// custom error type intended to provide more convenient error message to user
    #[derive(Debug)]
    pub enum GcliError {
    	/// error coming from subxt
    	Subxt(subxt::Error),
    	/// error coming from duniter
    	Duniter(String),
    	/// error coming from indexer
    	Indexer(String),
    	/// logic error (illegal operation or security)
    	Logic(String),
    	/// error coming from anyhow
    	Anyhow(anyhow::Error),
    }
    impl std::fmt::Display for GcliError {
    	fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
    		write!(f, "{:?}", self)
    	}
    }