Skip to content

feat: implement fee model interface with SatoshisPerKilobyte#131

Merged
sgbett merged 5 commits intomasterfrom
feature/94-fee-model
Mar 7, 2026
Merged

feat: implement fee model interface with SatoshisPerKilobyte#131
sgbett merged 5 commits intomasterfrom
feature/94-fee-model

Conversation

@sgbett
Copy link
Copy Markdown
Owner

@sgbett sgbett commented Mar 7, 2026

Summary

Implements the pluggable fee model architecture for HLR #94:

543 lines added across 10 files. Full test suite: 1439 examples, 0 failures.

Closes #94, closes #127, closes #128, closes #129, closes #130

Test plan

  • 2 FeeModel base class specs pass
  • 8 SatoshisPerKilobyte unit specs pass
  • 13 Transaction#fee specs pass (default, custom, numeric, change distribution)
  • 16 conformance specs pass (formula, contract, change, integration)
  • Full suite: 1439 examples, 0 failures
  • RuboCop clean on all changed files

🤖 Generated with Claude Code

sgbett and others added 4 commits March 7, 2026 01:22
Define BSV::Transaction::FeeModel with compute_fee(transaction) contract.
Subclasses must implement to return fee in satoshis.

Implements sub-task #127 of HLR #94.

Co-Authored-By: Claude <noreply@anthropic.com>
Implements BSV::Transaction::FeeModels::SatoshisPerKilobyte with
configurable sat/kB rate (default 50). Fee formula: ceil((size / 1000) * rate)
matching all three reference SDKs.

Also makes Transaction#estimated_size public so fee models can access it.

Implements sub-task #128 of HLR #94.

Co-Authored-By: Claude <noreply@anthropic.com>
Add TransactionOutput#change flag and Transaction#fee(model_or_value)
that accepts a FeeModel, numeric fee, or nil (defaults to 50 sat/kB).
Distributes change equally across change outputs; removes them if
insufficient (excess goes to miners). Backwards-compatible with
existing estimated_fee.

Implements sub-task #129 of HLR #94.

Co-Authored-By: Claude <noreply@anthropic.com>
16 specs validating fee formula against all three reference SDKs,
contract conformance, default rate, change distribution, and
Transaction#fee integration.

Implements sub-task #130 of HLR #94.

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 7, 2026

Codecov Report

❌ Patch coverage is 98.38710% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/bsv/transaction/transaction.rb 97.22% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Use total_input_satoshis (which raises ArgumentError on nil) instead of
silently coercing nil to 0, which could cause silent fund loss to miners.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sgbett sgbett merged commit 0a41198 into master Mar 7, 2026
7 checks passed
@sgbett sgbett deleted the feature/94-fee-model branch March 24, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant