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
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
Finally done
  • Loading branch information
raphjaph committed May 2, 2024
commit 8b513356bac3fd45dfae7aad1477b4e353b571e2
49 changes: 26 additions & 23 deletions src/subcommand/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,43 +252,46 @@ impl Send {
})
.collect::<BTreeMap<OutPoint, BTreeMap<Rune, Pile>>>();

let mut input_runes = 0;
let mut input = Vec::new();
// let mut selected_rune_inputs: BTreeMap<Rune, Pile> = BTreeMap::new();
let mut with_runes_change = true;
let mut multiple_runes_in_input = false;
let mut inputs = Vec::new();
let mut selected_rune_balances: BTreeMap<Rune, u128> = BTreeMap::new();

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

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

if input_runes >= amount {
if input_runes == amount {
with_runes_change = false;
}
selected_rune_balances
.entry(spaced_rune.rune)
.and_modify(|amount| *amount += balance.amount)
.or_insert(balance.amount);

if multiple_runes_in_input {
with_runes_change = true;
inputs.push(output);
}
}

if selected_rune_balances
.get(&spaced_rune.rune)
.cloned()
.unwrap_or_default()
>= amount
{
break;
}
}

let input_rune_balance = selected_rune_balances
.get(&spaced_rune.rune)
.cloned()
.unwrap_or_default();

let mut with_runes_change = input_rune_balance > amount;

with_runes_change |= selected_rune_balances.len() > 1;

ensure! {
input_runes >= amount,
input_rune_balance >= amount,
"insufficient `{}` balance, only {} in wallet",
spaced_rune,
Pile {
amount: input_runes,
amount: input_rune_balance,
divisibility: entry.divisibility,
symbol: entry.symbol
},
Expand Down Expand Up @@ -328,7 +331,7 @@ impl Send {
let unfunded_transaction = Transaction {
version: 2,
lock_time: LockTime::ZERO,
input: input
input: inputs
.into_iter()
.map(|previous_output| TxIn {
previous_output,
Expand Down
Loading