Move samples into tests
This commit is contained in:
parent
157b1875c5
commit
a671c4f86b
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,5 +15,5 @@ xcuserdata
|
|||||||
.lsp
|
.lsp
|
||||||
.clj-kondo
|
.clj-kondo
|
||||||
.idea
|
.idea
|
||||||
android/src/main/kotlin/org/bitcoindevkit/bdk.kt
|
bdk-android/lib/src/main/kotlin/org/bitcoindevkit/bdk.kt
|
||||||
jvm/src/main/kotlin/org/bitcoindevkit/bdk.kt
|
bdk-jvm/lib/src/main/kotlin/org/bitcoindevkit/bdk.kt
|
||||||
|
@ -29,7 +29,7 @@ tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
|
|||||||
moduleName.set("bdk-android")
|
moduleName.set("bdk-android")
|
||||||
moduleVersion.set("0.9.0")
|
moduleVersion.set("0.9.0")
|
||||||
includes.from("Module.md")
|
includes.from("Module.md")
|
||||||
samples.from("src/main/kotlin/org/bitcoindevkit/Samples.kt")
|
samples.from("src/test/kotlin/org/bitcoindevkit/Samples.kt")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
package org.bitcoindevkit
|
|
||||||
|
|
||||||
class Samples {
|
|
||||||
val blockchainConfig: BlockchainConfig = BlockchainConfig.Electrum(
|
|
||||||
ElectrumConfig(
|
|
||||||
url = "ssl://electrum.blockstream.info:60002",
|
|
||||||
socks5 = null,
|
|
||||||
retry = 5u,
|
|
||||||
timeout = null,
|
|
||||||
stopGap = 10u
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
@ -37,14 +37,40 @@ enum class AddressIndex {
|
|||||||
/** Return a new address after incrementing the current descriptor index. */
|
/** Return a new address after incrementing the current descriptor index. */
|
||||||
NEW,
|
NEW,
|
||||||
|
|
||||||
/**
|
/** Return the address for the current descriptor index if it has not been used in a received transaction. Otherwise return a new address as with `AddressIndex.NEW`. Use with caution, if the wallet has not yet detected an address has been used it could return an already used address. This function is primarily meant for situations where the caller is untrusted; for example when deriving donation addresses on-demand for a public web page. */
|
||||||
* Return the address for the current descriptor index if it has not been used in a received transaction. Otherwise return a new address as with `AddressIndex.NEW`. Use with caution, if the wallet has not yet detected an address has been used it could return an already used address. This function is primarily meant for situations where the caller is untrusted; for example when deriving donation addresses on-demand for a public web page.
|
|
||||||
*/
|
|
||||||
LAST_UNUSED,
|
LAST_UNUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Balance differentiated in various categories
|
||||||
|
*
|
||||||
|
* @sample org.bitcoindevkit.balanceSample
|
||||||
|
*/
|
||||||
|
data class Balance (
|
||||||
|
/** All coinbase outputs not yet matured. */
|
||||||
|
var immature: ULong,
|
||||||
|
|
||||||
|
/** Unconfirmed UTXOs generated by a wallet tx. */
|
||||||
|
var trustedPending: ULong,
|
||||||
|
|
||||||
|
/** Unconfirmed UTXOs received from an external wallet. */
|
||||||
|
var untrustedPending: ULong,
|
||||||
|
|
||||||
|
/** Confirmed and immediately spendable balance. */
|
||||||
|
var confirmed: ULong,
|
||||||
|
|
||||||
|
/** The sum of trustedPending and confirmed coins. */
|
||||||
|
var spendable: ULong,
|
||||||
|
|
||||||
|
/** The whole balance visible to the wallet. */
|
||||||
|
var total: ULong
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type that can contain any of the database configurations defined by the library.
|
* Type that can contain any of the database configurations defined by the library.
|
||||||
|
*
|
||||||
|
* @sample org.bitcoindevkit.memoryDatabaseConfigExample
|
||||||
|
* @sample org.bitcoindevkit.sqliteDatabaseConfigExample
|
||||||
*/
|
*/
|
||||||
sealed class DatabaseConfig {
|
sealed class DatabaseConfig {
|
||||||
/** Configuration for an in-memory database */
|
/** Configuration for an in-memory database */
|
||||||
@ -79,7 +105,7 @@ data class SledDbConfiguration(
|
|||||||
/**
|
/**
|
||||||
* Configuration for an Electrum blockchain.
|
* Configuration for an Electrum blockchain.
|
||||||
*
|
*
|
||||||
* @sample org.bitcoindevkit.Samples.blockchainConfig
|
* @sample org.bitcoindevkit.electrumBlockchainConfigExample
|
||||||
*/
|
*/
|
||||||
data class ElectrumConfig (
|
data class ElectrumConfig (
|
||||||
/** URL of the Electrum server (such as ElectrumX, Esplora, BWT) may start with `ssl://` or `tcp://` and include a port, e.g. `ssl://electrum.blockstream.info:60002`. */
|
/** URL of the Electrum server (such as ElectrumX, Esplora, BWT) may start with `ssl://` or `tcp://` and include a port, e.g. `ssl://electrum.blockstream.info:60002`. */
|
||||||
|
44
api-docs/src/test/kotlin/org/bitcoindevkit/Samples.kt
Normal file
44
api-docs/src/test/kotlin/org/bitcoindevkit/Samples.kt
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package org.bitcoindevkit
|
||||||
|
|
||||||
|
fun balanceSample() {
|
||||||
|
object LogProgress : Progress {
|
||||||
|
override fun update(progress: Float, message: String?) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
val memoryDatabaseConfig = DatabaseConfig.Memory
|
||||||
|
private val blockchainConfig = BlockchainConfig.Electrum(
|
||||||
|
ElectrumConfig(
|
||||||
|
"ssl://electrum.blockstream.info:60002",
|
||||||
|
null,
|
||||||
|
5u,
|
||||||
|
null,
|
||||||
|
200u
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val wallet = Wallet(descriptor, null, Network.TESTNET, memoryDatabaseConfig)
|
||||||
|
val blockchain = Blockchain(blockchainConfig)
|
||||||
|
wallet.sync(blockchain, LogProgress)
|
||||||
|
|
||||||
|
val balance: Balance = wallet.getBalance()
|
||||||
|
println("Total wallet balance is ${balance.total}")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun electrumBlockchainConfigExample() {
|
||||||
|
val blockchainConfig = BlockchainConfig.Electrum(
|
||||||
|
ElectrumConfig(
|
||||||
|
"ssl://electrum.blockstream.info:60002",
|
||||||
|
null,
|
||||||
|
5u,
|
||||||
|
null,
|
||||||
|
200u
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun memoryDatabaseConfigExample() {
|
||||||
|
val memoryDatabaseConfig = DatabaseConfig.Memory
|
||||||
|
}
|
||||||
|
|
||||||
|
fun sqliteDatabaseConfigExample() {
|
||||||
|
val databaseConfig = DatabaseConfig.Sqlite(SqliteDbConfiguration("bdk-sqlite"))
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user