bitcoindevkit/bdk_wallet

Add spent trait to improve sent_and_received()

Open

#31 创建于 2025年1月30日

在 GitHub 查看
 (12 评论) (0 反应) (1 负责人)Rust (94 fork)auto 404
good first issue

仓库指标

Star
 (54 star)
PR 合并指标
 (PR 指标待抓取)

描述

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

// 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

贡献者指南