Skip to content

Commit

Permalink
Add dry-run flag to resume command (#3592)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipelincoln committed Apr 19, 2024
1 parent 97b7364 commit 036ef68
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/subcommand/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub(crate) enum Subcommand {
#[command(about = "Restore wallet")]
Restore(restore::Restore),
#[command(about = "Resume pending etchings")]
Resume,
Resume(resume::Resume),
#[command(about = "List wallet satoshis")]
Sats(sats::Sats),
#[command(about = "Send sat or inscription")]
Expand Down Expand Up @@ -109,7 +109,7 @@ impl WalletCommand {
Subcommand::Mint(mint) => mint.run(wallet),
Subcommand::Outputs => outputs::run(wallet),
Subcommand::Receive(receive) => receive.run(wallet),
Subcommand::Resume => resume::run(wallet),
Subcommand::Resume(resume) => resume.run(wallet),
Subcommand::Sats(sats) => sats.run(wallet),
Subcommand::Send(send) => send.run(wallet),
Subcommand::Transactions(transactions) => transactions.run(wallet),
Expand Down
53 changes: 36 additions & 17 deletions src/subcommand/wallet/resume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,47 @@ use super::*;
pub struct ResumeOutput {
pub etchings: Vec<batch::Output>,
}
#[derive(Debug, Parser)]
pub(crate) struct Resume {
#[arg(long, help = "Don't broadcast transactions.")]
pub(crate) dry_run: bool,
}

pub(crate) fn run(wallet: Wallet) -> SubcommandResult {
let mut etchings = Vec::new();
loop {
if SHUTTING_DOWN.load(atomic::Ordering::Relaxed) {
break;
}
impl Resume {
pub(crate) fn run(self, wallet: Wallet) -> SubcommandResult {
let mut etchings = Vec::new();
loop {
if SHUTTING_DOWN.load(atomic::Ordering::Relaxed) {
break;
}

for (rune, entry) in wallet.pending_etchings()? {
if wallet.is_mature(&entry.commit)? {
etchings.push(wallet.send_etching(rune, &entry)?);
for (rune, entry) in wallet.pending_etchings()? {
if self.dry_run {
etchings.push(batch::Output {
reveal_broadcast: false,
..entry.output.clone()
});
continue;
};

if wallet.is_mature(&entry.commit)? {
etchings.push(wallet.send_etching(rune, &entry)?);
}
}
}

if wallet.pending_etchings()?.is_empty() {
break;
}
if wallet.pending_etchings()?.is_empty() {
break;
}

if self.dry_run {
break;
}

if !wallet.integration_test() {
thread::sleep(Duration::from_secs(5));
if !wallet.integration_test() {
thread::sleep(Duration::from_secs(5));
}
}
}

Ok(Some(Box::new(ResumeOutput { etchings }) as Box<dyn Output>))
Ok(Some(Box::new(ResumeOutput { etchings }) as Box<dyn Output>))
}
}

0 comments on commit 036ef68

Please sign in to comment.