Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ElectrumClient::server_features method #641

Conversation

thunderbiscuit
Copy link
Member

@thunderbiscuit thunderbiscuit commented Dec 18, 2024

This PR adds two new methods on the electrum client:

  1. server_features. Also exposed is the ServerFeaturesRes struct.
  2. estimate_fee

TODO:

  • Changelog notice
  • Swift test
  • API docs

Notes to the reviewers

I added a live test with a testnet electrum server. Note that my test with our standard mempool.space signet server returned an error (with a nice error message!) saying the server did not support the server_features method.

Note that those 2 tests don't run in the CI here because they are live tests, but I have run them both locally and they work well.

You can run these APIs locally in a Kotlin script:

cd bdk-jvm
just build-macos-aarch64
just publish-local

# cd ~/temp-or-whatever/
touch fees.main.kts
kotlin fees.main.kts

fees.main.kts

// fees.main.kts

@file:Repository("file:///~/.m2/repository/")
@file:DependsOn("org.bitcoindevkit:bdk-jvm:1.0.0-beta.6-SNAPSHOT")

import org.bitcoindevkit.ServerFeaturesRes
import org.bitcoindevkit.ElectrumClient

val electrumClient: ElectrumClient = ElectrumClient("ssl://electrum.blockstream.info:50002")
val features: ServerFeaturesRes = electrumClient.serverFeatures()
println("Server Features:\n$features")

val fees6 = electrumClient.estimateFee(6uL)
println("Fees to be in the next block: $fees6")

Changelog notice

Added:
  - ElectrumClient::server_features [#641]
  - ServerFeaturesRes struct [#641]
  - ElectrumClient::estimate_fee [#641]

[#641]: https://github.com/bitcoindevkit/bdk-ffi/pull/641

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

@thunderbiscuit thunderbiscuit force-pushed the feature/electrum-server-features branch 2 times, most recently from e6d0f42 to ce0b4d4 Compare December 18, 2024 18:36
@thunderbiscuit thunderbiscuit requested a review from reez December 18, 2024 18:52
@thunderbiscuit thunderbiscuit force-pushed the feature/electrum-server-features branch from 51289c5 to 01a64d1 Compare December 19, 2024 15:52
@reez
Copy link
Collaborator

reez commented Jan 6, 2025

Starting to review this! Will add comments and have this review finished in the next day-

@reez
Copy link
Collaborator

reez commented Jan 6, 2025

Thanks for the helpful guide to test this locally like this, I ran it, and one comment just to double check I'm on the same page with how this works is println("Fees to be in the next block: $fees6") should be something more like println("Estimated fee rate for confirmation within 6 blocks: $fees6, since fees6 is requesting an estimate for 6 blocks instead of for the next block. No code changes or anything necessary obviously since its not code in the PR but just for local testing, but more bringing it up in case I'm misunderstanding something.

// fees.main.kts

@file:Repository("file:///~/.m2/repository/")
@file:DependsOn("org.bitcoindevkit:bdk-jvm:1.0.0-beta.6-SNAPSHOT")

import org.bitcoindevkit.ServerFeaturesRes
import org.bitcoindevkit.ElectrumClient

val electrumClient: ElectrumClient = ElectrumClient("ssl://electrum.blockstream.info:50002")
val features: ServerFeaturesRes = electrumClient.serverFeatures()
println("Server Features:\n$features")

val fees6 = electrumClient.estimateFee(6uL)
println("Fees to be in the next block: $fees6")

Copy link
Collaborator

@reez reez left a comment

Choose a reason for hiding this comment

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

ACK 01a64d1

A few comments/thoughts

  • I ran the local tests and the live tests for bdk-jvm (thanks for also adding the companion swift live test), was kind of fun to run those and see the output

  • Thanks for adding the code comments in the UDL for all of ElectrumClient

  • The companion to the estimate_fee method but for EsploraClient would be get_fee_estimates? (If so, that something I can look into adding at some point, the only reason I was wondering/asking is just because I got curious what the similar method would be for EsploraClient when I was reviewing this)

@reez reez mentioned this pull request Jan 6, 2025
5 tasks
@thunderbiscuit
Copy link
Member Author

Yeah it's too bad the Esplora equivalent is not just a 1-for-1 match. Previously the clients were all adhering to a trait in the bdk crate so they all had that method on them (the inner implementation was a little different but I don't think we needed to do anything on our end if I remember correctly). In this case we'll have to find exactly how to do it for Esplora to offer it there (and you're right I don't think it's the same method name!).

@thunderbiscuit thunderbiscuit force-pushed the feature/electrum-server-features branch from 01a64d1 to 6518846 Compare January 6, 2025 18:14
@thunderbiscuit thunderbiscuit merged commit 6518846 into bitcoindevkit:master Jan 6, 2025
25 checks passed
@reez reez mentioned this pull request Jan 10, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants