Skip to content

Commit 2389e0d

Browse files
authored
Merge pull request #43 from buffrr/fix-wallet-dust-balance
Fix wallet dust balance
2 parents 1b305dd + fee34fe commit 2389e0d

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Bitcoin Spaces
1+
# Spaces on Bitcoin
22

33
Checkout [releases](https://github.com/spacesprotocol/spaces/releases) for an immediately usable binary version of this software.
44

node/src/wallets.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ impl RpcWallet {
177177
dust: unspent
178178
.into_iter()
179179
.filter(|output|
180-
(output.is_spaceout || output.output.txout.value <= SpacesAwareCoinSelection::DUST_THRESHOLD) &&
181-
// trusted pending only
182-
(output.output.confirmation_time.is_confirmed() || output.output.keychain == KeychainKind::Internal)
180+
// confirmed or trusted pending only
181+
(output.output.confirmation_time.is_confirmed() || output.output.keychain == KeychainKind::Internal) &&
182+
(output.space.is_some() || output.output.txout.value <= SpacesAwareCoinSelection::DUST_THRESHOLD)
183183
)
184184
.map(|output| output.output.txout.value)
185185
.sum(),
@@ -449,17 +449,22 @@ impl RpcWallet {
449449
state: &mut LiveSnapshot,
450450
confirmed_only: bool,
451451
) -> anyhow::Result<SpacesAwareCoinSelection> {
452-
// Filters out all "space outs" from the selection.
453-
// Note: This exclusion only applies to confirmed space outs; unconfirmed ones are not excluded.
452+
// Filters out all "spaceouts" with value higher than DUST threshold && all spaceouts representing
453+
// spaces.
454+
//
455+
// Note: This exclusion only applies to confirmed spaceouts; unconfirmed ones are not excluded
456+
// as we cannot easily detect them for now.
454457
// In practice, this should be fine since Spaces coin selection skips dust by default,
455-
// so explicitly excluding space outs may be redundant.
458+
// so explicitly excluding spaceouts may be redundant.
456459
let excluded = Self::list_unspent(wallet, state)?
457460
.into_iter()
458-
.filter(|out| out.is_spaceout)
461+
.filter(|out| out.space.is_some() ||
462+
(out.is_spaceout && out.output.txout.value <= SpacesAwareCoinSelection::DUST_THRESHOLD)
463+
)
459464
.map(|out| SelectionOutput {
460465
outpoint: out.output.outpoint,
461466
is_space: out.space.is_some(),
462-
is_spaceout: true,
467+
is_spaceout: out.is_spaceout,
463468
})
464469
.collect::<Vec<_>>();
465470

@@ -641,14 +646,14 @@ impl RpcWallet {
641646
match store.get_space_info(&spacehash)? {
642647
None => return Err(anyhow!("sendspaces: you don't own `{}`", space)),
643648
Some(full)
644-
if full.spaceout.space.is_none()
645-
|| !full.spaceout.space.as_ref().unwrap().is_owned()
646-
|| !wallet
647-
.spaces
648-
.is_mine(full.spaceout.script_pubkey.as_script()) =>
649-
{
650-
return Err(anyhow!("sendspaces: you don't own `{}`", space));
651-
}
649+
if full.spaceout.space.is_none()
650+
|| !full.spaceout.space.as_ref().unwrap().is_owned()
651+
|| !wallet
652+
.spaces
653+
.is_mine(full.spaceout.script_pubkey.as_script()) =>
654+
{
655+
return Err(anyhow!("sendspaces: you don't own `{}`", space));
656+
}
652657
Some(full) => {
653658
builder =
654659
builder.add_transfer(TransferRequest::Space(SpaceTransfer {

0 commit comments

Comments
 (0)