Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dry-run flag to resume command #3592

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>))
}
}
Loading