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

Fix send runes #3484

Merged
merged 20 commits into from
May 2, 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
Prev Previous commit
Next Next commit
Amend
  • Loading branch information
raphjaph committed May 2, 2024
commit 98ea8ae9963f9cbf2b1c6f5d0ba7a24b1a6873d6
33 changes: 18 additions & 15 deletions src/subcommand/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,33 +237,36 @@ impl Send {
let mut with_runes_change = true;
let mut multiple_runes_in_input = false;

let _balances = wallet
let balances = wallet
.get_runic_outputs()?
.into_iter()
.filter(|output| !inscribed_outputs.contains(output))
.filter_map(|output| {
wallet
.get_runes_balances_for_output(&output)
.ok()
.map(|balance| (output, balance))
.map(|balance| {
(
output,
balance
.into_iter()
.map(|(spaced_rune, pile)| (spaced_rune.rune, pile))
.collect::<BTreeMap<Rune, Pile>>(),
)
})
})
// .flatten()
.collect::<BTreeMap<OutPoint, Vec<_>>>();
.collect::<BTreeMap<OutPoint, BTreeMap<Rune, Pile>>>();

for output in wallet.get_runic_outputs()? {
if inscribed_outputs.contains(&output) {
continue;
}

if wallet.get_runes_balances_for_output(&output)?.len() > 1 {
for (output, runes) in balances {
if runes.len() > 1 {
multiple_runes_in_input = true;
}

let balance = wallet.get_rune_balance_in_output(&output, entry.spaced_rune.rune)?;

if balance > 0 {
input_runes += balance;
input.push(output);
if let Some(balance) = runes.get(&spaced_rune.rune) {
if balance.amount > 0 {
input_runes += balance.amount;
input.push(output);
}
}

if input_runes >= amount {
Expand Down
30 changes: 15 additions & 15 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,21 +231,21 @@ impl Wallet {
)
}

pub(crate) fn get_rune_balance_in_output(&self, output: &OutPoint, rune: Rune) -> Result<u128> {
Ok(
self
.get_runes_balances_for_output(output)?
.iter()
.map(|(spaced_rune, pile)| {
if spaced_rune.rune == rune {
pile.amount
} else {
0
}
})
.sum(),
)
}
// pub(crate) fn get_rune_balance_in_output(&self, output: &OutPoint, rune: Rune) -> Result<u128> {
// Ok(
// self
// .get_runes_balances_for_output(output)?
// .iter()
// .map(|(spaced_rune, pile)| {
// if spaced_rune.rune == rune {
// pile.amount
// } else {
// 0
// }
// })
// .sum(),
// )
// }

pub(crate) fn get_rune(
&self,
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ fn sending_spaced_rune_works() {
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1000:A•AAAAAAAAAAAA",
)
.core(&core)
.ord(&ord)
.ord(&ord)
.run_and_deserialize_output::<Send>();

core.mine_blocks(1);
Expand Down