Skip to content
Snippets Groups Projects
Select Git revision
  • b748ae5e9a848f62d301515bda6dada7619ee26d
  • dev default protected
  • release/1.9.1 protected
  • pini-1.8-docker
  • pini-sync-onlypeers
  • duniter-v2s-issue-123-industrialize-releases
  • feature/build-aarch64-nodejs16
  • release/1.8 protected
  • pini-docker
  • ci_tags
  • fix/1448/1.8/txs_not_stored
  • feature/node-20
  • fix/1441/node_summary_with_storage
  • fix/1442/improve_bma_tx_history
  • feature/wotwizard-1.8
  • release/1.9 protected
  • 1.7 protected
  • feature/docker-set-latest protected
  • feature/fast-docker-build-1.8.4
  • fast-docker-build protected
  • feature/dump-distance
  • v1.8.7 protected
  • v1.8.7-rc4 protected
  • v1.8.7-rc3 protected
  • v1.8.7-rc2 protected
  • v1.8.7-rc1 protected
  • v1.8.6 protected
  • v1.7.23 protected
  • v1.8.5 protected
  • v1.8.4 protected
  • v1.8.3 protected
  • v1.8.2 protected
  • v1.8.1 protected
  • v1.8.0 protected
  • v1.8.0-rc1 protected
  • v1.8.0-beta5 protected
  • v1.8.0-beta4 protected
  • v1.8.0-beta3 protected
  • v1.8.0-beta2 protected
  • v1.8.0-beta protected
  • v1.7.21 protected
41 results

server.js

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)
    	}
    }
    impl std::error::Error for GcliError {}
    impl From<subxt::Error> for GcliError {
    	fn from(e: subxt::Error) -> GcliError {
    		GcliError::Subxt(e)
    	}
    }
    impl From<anyhow::Error> for GcliError {
    	fn from(e: anyhow::Error) -> GcliError {
    		GcliError::Anyhow(e)
    	}
    }