Skip to content

Commit

Permalink
feat: consume-ack retry
Browse files Browse the repository at this point in the history
  • Loading branch information
liyukun committed Nov 17, 2023
1 parent 64978b9 commit 720d35d
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion examples/sudt-transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async fn main() -> Result<()> {
Commands::CreateStCell { sudt } => {
create_st_cell(config, sk, sender_lock_script, sudt).await
}
Commands::ConsumeAck => consume_ack(&config, sk, sender_lock_script).await,
Commands::ConsumeAck => consume_ack_retry(&config, sk, sender_lock_script).await,
Commands::Send {
sudt,
receiver,
Expand All @@ -145,6 +145,30 @@ async fn main() -> Result<()> {
}
}

async fn consume_ack_retry(
config: &Config,
sk: secp256k1::SecretKey,
sender_lock_script: packed::Script,
) -> Result<()> {
loop {
match consume_ack(&config, sk, sender_lock_script.clone()).await {
Ok(()) => return Ok(()),
Err(e) => {
if let Some(re) = e.downcast_ref::<ckb_sdk::RpcError>() {
match re {
ckb_sdk::RpcError::Rpc(re) if should_retry_code(re.code.code()) => {
println!("Will retry, error: {e:#}");
tokio::time::sleep(Duration::from_secs(5)).await;
continue;
}
_ => return Err(e),
}
}
}
}
}
}

async fn consume_ack(
config: &Config,
sk: secp256k1::SecretKey,
Expand Down

0 comments on commit 720d35d

Please sign in to comment.