Merge 45ae8063b1901353907bedeaf2ce7966b1a13af2 into fe368f2b48047a18bd0843d4862599804b4519cf

This commit is contained in:
Jimmy 🦞 2026-03-20 03:37:35 +03:00 committed by GitHub
commit 7bc7ce665b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -99,6 +99,32 @@ pub enum SubcommandReturnValue {
SyncedToBlock(u64),
}
/// Poll the sequencer until a transaction appears in a block.
/// Returns `Ok(true)` if confirmed, `Ok(false)` if timed out.
async fn wait_for_tx_confirmation(
client: &common::sequencer_client::SequencerClient,
tx_hash: HashType,
max_attempts: u32,
poll_interval_ms: u64,
) -> Result<bool> {
for attempt in 1..=max_attempts {
tokio::time::sleep(std::time::Duration::from_millis(poll_interval_ms)).await;
match client.get_transaction_by_hash(tx_hash).await {
Ok(resp) if resp.transaction.is_some() => {
return Ok(true);
}
Ok(_) => {
println!(" Attempt {}/{}: pending...", attempt, max_attempts);
}
Err(e) => {
println!(" Attempt {}/{}: error querying tx: {}", attempt, max_attempts, e);
}
}
}
Ok(false)
}
pub async fn execute_subcommand(
wallet_core: &mut WalletCore,
command: Command,
@ -175,12 +201,35 @@ pub async fn execute_subcommand(
))?;
let message = nssa::program_deployment_transaction::Message::new(bytecode);
let transaction = ProgramDeploymentTransaction::new(message);
let _response = wallet_core
println!("Submitting program deployment transaction...");
let response = wallet_core
.sequencer_client
.send_transaction(NSSATransaction::ProgramDeployment(transaction))
.await
.context("Transaction submission error")?;
let tx_hash = response.tx_hash;
println!("Transaction submitted: {}", tx_hash);
println!("Waiting for confirmation...");
// Poll until the transaction is included in a block
let confirmed = wait_for_tx_confirmation(
&wallet_core.sequencer_client,
tx_hash,
23, // max attempts (3 blocks × 15s, polling every 2s)
2000, // ms between polls (2s)
)
.await?;
if !confirmed {
anyhow::bail!(
"Transaction was not confirmed after timeout. \
Timed out after ~3 blocks (45s). The program may not have been deployed. Check sequencer logs."
);
}
println!("Program deployed successfully! Program ID: {}", tx_hash);
SubcommandReturnValue::Empty
}
};