Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
}
/// 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)
}
}