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 ord wallet runics command #3734

Merged
merged 6 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 4 additions & 0 deletions src/subcommand/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use {
pub mod balance;
mod batch_command;
pub mod cardinals;
pub mod runics;
pub mod create;
pub mod dump;
pub mod inscribe;
Expand Down Expand Up @@ -47,6 +48,8 @@ pub(crate) enum Subcommand {
Batch(batch_command::Batch),
#[command(about = "List unspent cardinal outputs in wallet")]
Cardinals,
#[command(about = "List unspent runic outputs in wallet")]
Runics,
#[command(about = "Create new wallet")]
Create(create::Create),
#[command(about = "Dump wallet descriptors")]
Expand Down Expand Up @@ -101,6 +104,7 @@ impl WalletCommand {
Subcommand::Balance => balance::run(wallet),
Subcommand::Batch(batch) => batch.run(wallet),
Subcommand::Cardinals => cardinals::run(wallet),
Subcommand::Runics => runics::run(wallet),
Subcommand::Create(_) | Subcommand::Restore(_) => unreachable!(),
Subcommand::Dump => dump::run(wallet),
Subcommand::Inscribe(inscribe) => inscribe.run(wallet),
Expand Down
37 changes: 37 additions & 0 deletions src/subcommand/wallet/runics.rs
ldiego08 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use super::*;

#[derive(Serialize, Deserialize)]
pub struct RunicUtxo {
pub output: OutPoint,
pub rune: SpacedRune,
pub rune_balance: u128,
ldiego08 marked this conversation as resolved.
Show resolved Hide resolved
pub amount: u64,
ldiego08 marked this conversation as resolved.
Show resolved Hide resolved
}

pub(crate) fn run(wallet: Wallet) -> SubcommandResult {
let unspent_outputs = wallet.utxos();
let runic_utxos = wallet.get_runic_outputs()?;

let runic_utxos = unspent_outputs
.iter()
.flat_map(|(output, txout)| {
if runic_utxos.contains(output) {
wallet
.get_runes_balances_for_output(output)
.unwrap()
.into_iter()
.map(|(rune, pile)| RunicUtxo {
rune,
rune_balance: pile.amount,
amount: txout.value,
output: *output,
})
.collect()
} else {
vec![]
}
})
.collect::<Vec<RunicUtxo>>();

Ok(Some(Box::new(runic_utxos)))
}
Loading