From 17b371200097d9523266066806a117d1237240dc Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Tue, 6 Dec 2022 15:17:10 -0500 Subject: [PATCH] Update JVM and Android API docs to version 0.25 and add samples --- README.md | 2 +- .../src/main/kotlin/org/bitcoindevkit/bdk.kt | 19 +++++++++++++--- .../test/kotlin/org/bitcoindevkit/Samples.kt | 22 ++++++++++++++----- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e239151..af04793 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ CI Status Rustc Version 1.61.0+ Chat on Discord -

+

The workspace in this repository creates the `libbdkffi` multi-language library for the Rust-based [bdk] library from the [Bitcoin Dev Kit] project. The `bdk-ffi-bindgen` package builds a tool for diff --git a/api-docs/kotlin/src/main/kotlin/org/bitcoindevkit/bdk.kt b/api-docs/kotlin/src/main/kotlin/org/bitcoindevkit/bdk.kt index f6c1640..5ac06b9 100644 --- a/api-docs/kotlin/src/main/kotlin/org/bitcoindevkit/bdk.kt +++ b/api-docs/kotlin/src/main/kotlin/org/bitcoindevkit/bdk.kt @@ -94,6 +94,8 @@ sealed class DatabaseConfig { * Configuration type for a SQLite database. * * @property path Main directory of the DB. + * + * @sample org.bitcoindevkit.sqliteDatabaseConfigSample */ data class SqliteDbConfiguration( var path: String, @@ -137,6 +139,8 @@ data class ElectrumConfig ( * @property concurrency Number of parallel requests sent to the esplora service (default: 4). * @property stopGap Stop searching addresses for transactions after finding an unused gap of this length. * @property timeout Socket timeout. + * + * @sample org.bitcoindevkit.esploraBlockchainConfigSample */ data class EsploraConfig ( var baseUrl: String, @@ -213,7 +217,7 @@ class PartiallySignedBitcoinTransaction(psbtBase64: String) { fun txid(): String {} /** Return the transaction as bytes. */ - fun `extractTx`(): List + fun extractTx(): List /** * Combines this PartiallySignedTransaction with another PSBT as described by BIP 174. @@ -343,6 +347,9 @@ class Progress { * After creating the TxBuilder, you set options on it until finally calling `.finish` to consume the builder and generate the transaction. * * Each method on the TxBuilder returns an instance of a new TxBuilder with the option set/added. + * + * @sample org.bitcoindevkit.txBuilderResultSample1 + * @sample org.bitcoindevkit.txBuilderResultSample2 */ class TxBuilder() { /** Add data as an output using OP_RETURN. */ @@ -476,6 +483,9 @@ class DerivationPath(path: String) {} * @sample org.bitcoindevkit.descriptorSecretKeyExtendSample */ class DescriptorSecretKey(network: Network, mnemonic: Mnemonic, password: String?) { + /** Build a DescriptorSecretKey from a String */ + fun fromString(secretKey: String): DescriptorSecretKey {} + /** Derive a private descriptor at a given path. */ fun derive(path: DerivationPath): DescriptorSecretKey {} @@ -500,11 +510,14 @@ class DescriptorSecretKey(network: Network, mnemonic: Mnemonic, password: String * @param password The optional passphrase that can be provided as per BIP-39. */ class DescriptorPublicKey(network: Network, mnemonic: String, password: String?) { + /** Build a DescriptorPublicKey from a String */ + fun fromString(publicKey: String): DescriptorPublicKey {} + /** Derive a public descriptor at a given path. */ - fun derive(path: DerivationPath): DescriptorSecretKey + fun derive(path: DerivationPath): DescriptorPublicKey /** Extend the public descriptor with a custom path. */ - fun extend(path: DerivationPath): DescriptorSecretKey + fun extend(path: DerivationPath): DescriptorPublicKey /** Return the public descriptor as a string. */ fun asString(): String diff --git a/api-docs/kotlin/src/test/kotlin/org/bitcoindevkit/Samples.kt b/api-docs/kotlin/src/test/kotlin/org/bitcoindevkit/Samples.kt index 34840ec..a411eb0 100644 --- a/api-docs/kotlin/src/test/kotlin/org/bitcoindevkit/Samples.kt +++ b/api-docs/kotlin/src/test/kotlin/org/bitcoindevkit/Samples.kt @@ -44,6 +44,18 @@ fun electrumBlockchainConfigSample() { ) } +fun esploraBlockchainConfigSample() { + val esploraURL: String = "http://10.0.2.2:3002" + val esploraConfig: EsploraConfig = EsploraConfig( + baseUrl = esploraURL, + proxy = null, + concurrency = 4u, + stopGap = 20UL, + timeout = null + ) + val blockchainConfig = BlockchainConfig.Esplora(config = esploraConfig) +} + fun memoryDatabaseConfigSample() { val memoryDatabaseConfig = DatabaseConfig.Memory } @@ -102,9 +114,9 @@ fun blockchainSample() { fun txBuilderResultSample1() { val faucetAddress = Address("tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt") // TxBuilderResult is a data class, which means you can use destructuring declarations on it to - // open it up in its component parts + // open it up into its component parts val (psbt, txDetails) = TxBuilder() - .addRecipient(faucetAddress.scriptPubkey(), 1000u) + .addRecipient(faucetAddress.scriptPubkey(), 1000uL) .feeRate(1.2f) .finish(wallet) @@ -115,7 +127,7 @@ fun txBuilderResultSample1() { fun txBuilderResultSample2() { val faucetAddress = Address("tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt") val txBuilderResult: TxBuilderResult = TxBuilder() - .addRecipient(faucetAddress.scriptPubkey(), 1000u) + .addRecipient(faucetAddress.scriptPubkey(), 1000uL) .feeRate(1.2f) .finish(wallet) @@ -200,7 +212,7 @@ fun createTransaction() { val paymentAddress: Address = Address("tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt") val (psbt, txDetails) = TxBuilder() - .addRecipient(faucetAddress.scriptPubkey(), 1000u) + .addRecipient(faucetAddress.scriptPubkey(), 1000uL) .feeRate(1.2f) .finish(wallet) @@ -213,7 +225,7 @@ fun walletSample() { val internalDescriptor = "wpkh(tprv8hwWMmPE4BVNxGdVt3HhEERZhondQvodUY7Ajyseyhudr4WabJqWKWLr4Wi2r26CDaNCQhhxEfVULesmhEfZYyBXdE/84h/1h/0h/1/*)" val sqliteDatabaseConfig = DatabaseConfig.Sqlite(SqliteDbConfiguration("bdk-sqlite")) - val wallet = BdkWallet( + val wallet = Wallet( descriptor = externalDescriptor, changeDescriptor = internalDescriptor, network = Network.TESTNET,