Skip to content

Refactor API and clean up house#157

Open
luisschwab wants to merge 12 commits intobitcoindevkit:masterfrom
luisschwab:chore/api-fixups
Open

Refactor API and clean up house#157
luisschwab wants to merge 12 commits intobitcoindevkit:masterfrom
luisschwab:chore/api-fixups

Conversation

@luisschwab
Copy link
Copy Markdown
Member

@luisschwab luisschwab commented Jan 7, 2026

Closes #142.
Closes #146.
Closes #148.
Closes #150.

This PR does a bunch of cleanup, standardizes and adds missing documentation, fixes inconsistencies and redundancies in the API, and uses rust-bitcoin types where possible.

Changelog

# Added
- Add `impl From<EsploraTx> to Transaction` and `impl From<&EsploraTx> to Transaction`
- Add `sat_per_vbyte_to_feerate` utility function in `api.rs`
- Add `get_block_infos` (returns `Vec<BlockInfo>`)

# Breaking
- Rename `scripthash_txs` to `get_scripthash_txs`
- Remove `PrevOut` in favor of reusing `Vout`
- Rename `Tx` to `EsploraTx`
- Remove `EsploraTx::fee()` method (use `EsploraTx.fee` instead)
- Remove `EsploraTx::weight()` method (use `Esplora.weight` instead)
- Change `get_fee_estimates` to return `HashMap<u16, FeeRate>` instead of `HashMap<u16, f64>`
- Change `convert_fee_rate` to accept `HashMap<u16, FeeRate>` and return `Option<FeeRate>` instead of `Option<f32>`
- Change `submit_package` `maxfeerate` parameter from `Option<f64>` to `Option<FeeRate>`
- Change `submit_package` `maxburnamount` parameter from `Option<f64>` to `Option<Amount>`
- Change all bitcoin amount fields from `u64` to `Amount`
- Change all weight fields from `u64` to `Weight`

# Changed
- Deprecate `BlockSummary` and `get_blocks` (to be removed on v0.14.0)
- Replace `std::` with `core::` where applicable
- Reorder API structs into logical groups: transaction, block, address, script hash, UTXO, mempool
- Reorder client methods into logical groups: transaction, block, address, script hash, mempool
- Improve documentation for `api.rs`, `async.rs`, `blocking.rs`, and `lib.rs`
- Update copyright notice to `2020-2026`

@coveralls
Copy link
Copy Markdown

coveralls commented Jan 7, 2026

Pull Request Test Coverage Report for Build 22006096792

Details

  • 21 of 22 (95.45%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.007%) to 87.257%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/api.rs 1 2 50.0%
Totals Coverage Status
Change from base Build 22002487177: 0.007%
Covered Lines: 1438
Relevant Lines: 1648

💛 - Coveralls

@luisschwab luisschwab changed the title chore(api): remove BlockSummary and PrevOut, rename scripthash_txs to get_scripthash_txs chore(api)!: remove BlockSummary and PrevOut, rename scripthash_txs to get_scripthash_txs Jan 7, 2026
Copy link
Copy Markdown
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cACK dbbe555

@oleonardolima oleonardolima moved this to In Progress in BDK Chain Jan 7, 2026
@luisschwab luisschwab marked this pull request as ready for review January 20, 2026 20:11
Copy link
Copy Markdown
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK eccf30d

I'm also wondering on how disruptive it'll be on downstream, see VM's comment, though it'll be in a major release.

@luisschwab
Copy link
Copy Markdown
Member Author

Makes sense. We can remove the deprecated function on v14.

Copy link
Copy Markdown
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 530ebea

@luisschwab luisschwab changed the title chore(api)!: remove BlockSummary and PrevOut, rename scripthash_txs to get_scripthash_txs Refactor API structs Feb 14, 2026
@luisschwab luisschwab changed the title Refactor API structs Refactor API Feb 18, 2026
@luisschwab
Copy link
Copy Markdown
Member Author

I'll rebase this one since we decided to deprecate get_blocks instead of removing it outright.

@oleonardolima oleonardolima self-requested a review March 5, 2026 15:55
@oleonardolima oleonardolima added enhancement New feature or request api A breaking API change labels Mar 5, 2026
Removes `BlockSummary`, as it omitted information
returned by Esplora. This removes `get_blocks` and
adds `get_block_infos` (`get_blocks` was deprecated
in v0.12.3).
The `PrevOut` struct is identical to `Vout`.
@luisschwab luisschwab changed the title Refactor API Refactor API and clean up house Apr 1, 2026
@luisschwab luisschwab force-pushed the chore/api-fixups branch 2 times, most recently from f2a2a16 to 8337a89 Compare April 1, 2026 23:10
@luisschwab luisschwab requested review from oleonardolima and removed request for oleonardolima April 1, 2026 23:14
@luisschwab
Copy link
Copy Markdown
Member Author

Pushed 8337a89 completing the work. It's a big one, but mostly documentation and moving things around.

@luisschwab luisschwab requested a review from notmandatory April 2, 2026 16:40
Copy link
Copy Markdown

@yan-pi yan-pi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 8337a89

This commit:
  - Renames `Tx` to `EsploraTx`: more explicit. `Tx` is not precise about what it is.
  - Remove `EsploraTx::fee`, since the field is already public.
  - Implements `From<EsploraTx>`/`From<&EsploraTx>` to `Transaction` conversions.
  - Reorders structs into logical groups: Transaction, Block, Address, ScriptHash, UTXO, and Mempool.
  - Improves documentation.
  - Updates copyright notice to `2020-2026`.
This commit:
  - Reorders methods into logical groups: transaction, block, address,
    script hash, and mempool.
  - Improves documentation throughout: clearer summaries, consistent
    style, and proper intra-doc links.
  - Moves `Sleeper`, `DefaultSleeper`, and `is_status_retryable` to the
    top of the file for better readability.
  - Updates return types from `Tx` to `EsploraTx` following the rename.
  - Removes unused `log` imports.
  - Updates copyright notice to `2020-2026`.
This commit:
  - Changes `get_fee_estimates` to return `HashMap<u16, FeeRate>` instead of `HashMap<u16, f64>`.
  - Changes `convert_fee_rate` to accept `HashMap<u16, FeeRate>` and return `Option<FeeRate>` instead of `Option<f32>`.
  - Adds `sat_per_vbyte_to_feerate` to `api.rs` to convert the raw `f64` sat/vbyte values returned by the Esplora API into `FeeRate`.
  - Updates the `feerate_parsing` test accordingly.
This commit:
  - Rewrites crate-level docs:
    - Cleaner structure
    - Usage examples for async and blocking clients
    - Feature table instead of a bullet list
  - Improves `Builder` documentation
  - Improves `Error` documentation
  - Replaces `std::` with `core::` where applicable
  - Updates copyright notice to `2020-2026`
Re-add with a deprecation warning. These should be removed for the v0.14.0 release.
@luisschwab luisschwab requested a review from yan-pi April 10, 2026 15:23
@luisschwab luisschwab added documentation Improvements or additions to documentation chore labels Apr 10, 2026
Only casting to `u64` would always round down.
Rounding (`.round()`) and then casting to `u64`
is more precise.

Also updates the fee JSON on `test_feerate_parsing`
with current values which include sub-1 sat fees:

```
curl https://mempool.space/api/fee-estimates | jq 'to_entries | sort_by(.key | tonumber) | from_entries'
```
Copy link
Copy Markdown

@yan-pi yan-pi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK df3b306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api A breaking API change chore documentation Improvements or additions to documentation enhancement New feature or request

Projects

Status: In Progress

5 participants