-
- All Implemented Interfaces:
-
java.lang.AutoCloseable,org.bitcoindevkit.Disposable,org.bitcoindevkit.ElectrumClientInterface
public class ElectrumClient implements Disposable, AutoCloseable, ElectrumClientInterface
Wrapper around an electrum_client::ElectrumApi which includes an internal in-memory transaction cache to avoid re-fetching already downloaded transactions.
-
-
Constructor Summary
Constructors Constructor Description ElectrumClient(String url, String socks5)Creates a new bdk client from a electrum_client::ElectrumApi Optional: Set the proxy of the builder
-
Method Summary
Modifier and Type Method Description Unitdestroy()Unitclose()HeaderblockHeader(ULong height)Gets the block header for height height.HeaderNotificationblockHeadersPop()Tries to pop one queued notification for a new block header that we might have received. HeaderNotificationblockHeadersSubscribe()Subscribes to notifications for new block headers, by sending a blockchain.headers.subscribe call. DoubleestimateFee(ULong number)Estimates the fee required in bitcoin per kilobyte to confirm a transaction in numberblocks.TransactionfetchTx(Txid txid)Fetch transaction of given Txid.UpdatefullScan(FullScanRequest request, ULong stopGap, ULong batchSize, Boolean fetchPrevTxouts)Full scan the keychain scripts specified with the blockchain (via an Electrum client) and returns updates for bdk_chain data structures. Unitping()Pings the server. DoublerelayFee()Returns the minimum accepted fee by the server’s node in Bitcoin, not Satoshi. ServerFeaturesResserverFeatures()Returns the capabilities of the server. Updatesync(SyncRequest request, ULong batchSize, Boolean fetchPrevTxouts)Sync a set of scripts with the blockchain (via an Electrum client) for the data specified and returns updates for bdk_chain data structures. TxidtransactionBroadcast(Transaction tx)Broadcasts a transaction to the network. ByteArraytransactionGetRaw(Txid txid)Gets the raw bytes of a transaction with txid. -
-
Method Detail
-
blockHeader
Header blockHeader(ULong height)
Gets the block header for height
height.
-
blockHeadersPop
HeaderNotification blockHeadersPop()
Tries to pop one queued notification for a new block header that we might have received. Returns
Noneif there are no items in the queue.
-
blockHeadersSubscribe
HeaderNotification blockHeadersSubscribe()
Subscribes to notifications for new block headers, by sending a blockchain.headers.subscribe call.
-
estimateFee
Double estimateFee(ULong number)
Estimates the fee required in bitcoin per kilobyte to confirm a transaction in
numberblocks.
-
fetchTx
Transaction fetchTx(Txid txid)
Fetch transaction of given
Txid.If it hits the cache it will return the cached version and avoid making the request.
-
fullScan
Update fullScan(FullScanRequest request, ULong stopGap, ULong batchSize, Boolean fetchPrevTxouts)
Full scan the keychain scripts specified with the blockchain (via an Electrum client) and returns updates for bdk_chain data structures.
request: struct with data required to perform a spk-based blockchain client full scan, seeFullScanRequest.stop_gap: the full scan for each keychain stops after a gap of script pubkeys with no associated transactions.batch_size: specifies the max number of script pubkeys to request for in a single batch request.fetch_prev_txouts: specifies whether we want previousTxOutsfor fee calculation. Note that this requires additional calls to the Electrum server, but is necessary for calculating the fee on a transaction if your wallet does not own the inputs. Methods likeWallet.calculate_feeandWallet.calculate_fee_ratewill return aCalculateFeeError::MissingTxOuterror if those TxOuts are not present in the transaction graph.
-
relayFee
Double relayFee()
Returns the minimum accepted fee by the server’s node in Bitcoin, not Satoshi.
-
serverFeatures
ServerFeaturesRes serverFeatures()
Returns the capabilities of the server.
-
sync
Update sync(SyncRequest request, ULong batchSize, Boolean fetchPrevTxouts)
Sync a set of scripts with the blockchain (via an Electrum client) for the data specified and returns updates for bdk_chain data structures.
request: struct with data required to perform a spk-based blockchain client sync, seeSyncRequest.batch_size: specifies the max number of script pubkeys to request for in a single batch request.fetch_prev_txouts: specifies whether we want previousTxOutsfor fee calculation. Note that this requires additional calls to the Electrum server, but is necessary for calculating the fee on a transaction if your wallet does not own the inputs. Methods likeWallet.calculate_feeandWallet.calculate_fee_ratewill return aCalculateFeeError::MissingTxOuterror if those TxOuts are not present in the transaction graph.
If the scripts to sync are unknown, such as when restoring or importing a keychain that may include scripts that have been used, use full_scan with the keychain.
-
transactionBroadcast
Txid transactionBroadcast(Transaction tx)
Broadcasts a transaction to the network.
-
transactionGetRaw
ByteArray transactionGetRaw(Txid txid)
Gets the raw bytes of a transaction with txid. Returns an error if not found.
-
-
-
-