bitcoindevkit / bitcoindevkit/bdk_wallet

Add spent trait to improve sent_and_received()

Open
#31 12 comments 0 reactions 1 assignee Claimed by @YuriQueirozAndrade View on GitHub
good first issue
Dominant language
Rust
Stars
59
Forks
105
Avg merge
10d 9h
Merged PRs (30d)
1

Description

**Describe the enhancement**
Add a `TxAmountSpent` trait to improve how transaction spending amounts are calculated. The trait will add a `.spent()` method to tuples returned by `sent_and_received()`, calculating total amount spent including fees.

**Use case**
```rust
// Current: Manual calculation needed
let (sent, received) = wallet.sent_and_received(&tx);
let fee = wallet.calculate_fee(&tx)?;
let total = sent - received + fee; // Error-prone

// Proposed: Clean trait implementation
let (sent, received) = wallet.sent_and_received(&tx);
let total = (sent, received, fee).spent(); // Clear and consistent
```

**Additional context**
- Non-breaking change that extends existing functionality
- Makes transaction cost calculations more intuitive
- Helps prevent calculation errors
- Small, focused improvement suitable for a first-time contributor

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.