2022-09-16 07:10:19 -04:00
|
|
|
package org.bitcoindevkit
|
|
|
|
|
2022-09-22 09:56:41 -04:00
|
|
|
fun networkSample() {
|
|
|
|
val wallet = Wallet(
|
|
|
|
descriptor = descriptor,
|
|
|
|
changeDescriptor = changeDescriptor,
|
|
|
|
network = Network.TESTNET,
|
|
|
|
databaseConfig = DatabaseConfig.Memory
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-09-16 07:10:19 -04:00
|
|
|
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}")
|
|
|
|
}
|
|
|
|
|
2022-09-22 09:40:39 -04:00
|
|
|
fun electrumBlockchainConfigSample() {
|
2022-09-16 07:10:19 -04:00
|
|
|
val blockchainConfig = BlockchainConfig.Electrum(
|
|
|
|
ElectrumConfig(
|
2022-09-22 09:56:41 -04:00
|
|
|
url = "ssl://electrum.blockstream.info:60002",
|
|
|
|
socks5 = null,
|
|
|
|
retry = 5u,
|
|
|
|
timeout = null,
|
|
|
|
stopGap = 200u
|
2022-09-16 07:10:19 -04:00
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-09-22 09:40:39 -04:00
|
|
|
fun memoryDatabaseConfigSample() {
|
2022-09-16 07:10:19 -04:00
|
|
|
val memoryDatabaseConfig = DatabaseConfig.Memory
|
|
|
|
}
|
|
|
|
|
2022-09-22 09:40:39 -04:00
|
|
|
fun sqliteDatabaseConfigSample() {
|
2022-09-16 07:10:19 -04:00
|
|
|
val databaseConfig = DatabaseConfig.Sqlite(SqliteDbConfiguration("bdk-sqlite"))
|
|
|
|
}
|
2022-09-22 09:40:39 -04:00
|
|
|
|
|
|
|
fun addressIndexSample() {
|
|
|
|
val wallet: Wallet = Wallet(
|
|
|
|
descriptor = descriptor,
|
|
|
|
changeDescriptor = changeDescriptor,
|
|
|
|
network = Network.TESTNET,
|
|
|
|
databaseConfig = DatabaseConfig.Memory
|
|
|
|
)
|
|
|
|
|
|
|
|
fun getLastUnusedAddress(): AddressInfo {
|
|
|
|
return wallet.getAddress(AddressIndex.LAST_UNUSED)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun addressInfoSample() {
|
|
|
|
val wallet: Wallet = Wallet(
|
|
|
|
descriptor = descriptor,
|
|
|
|
changeDescriptor = changeDescriptor,
|
|
|
|
network = Network.TESTNET,
|
|
|
|
databaseConfig = DatabaseConfig.Memory
|
|
|
|
)
|
|
|
|
|
|
|
|
fun getLastUnusedAddress(): AddressInfo {
|
|
|
|
return wallet.getAddress(AddressIndex.NEW)
|
|
|
|
}
|
|
|
|
|
|
|
|
val newAddress: AddressInfo = getLastUnusedAddress()
|
|
|
|
|
|
|
|
println("New address at index ${newAddress.index} is ${newAddress.address}")
|
|
|
|
}
|
2022-09-22 09:56:41 -04:00
|
|
|
|
|
|
|
fun blockchainSample() {
|
|
|
|
val blockchainConfig: BlockchainConfig = BlockchainConfig.Electrum(
|
|
|
|
ElectrumConfig(
|
|
|
|
electrumURL,
|
|
|
|
null,
|
|
|
|
5u,
|
|
|
|
null,
|
|
|
|
10u
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
val blockchain: Blockchain = Blockchain(blockchainConfig)
|
|
|
|
|
|
|
|
blockchain.broadcast(signedPsbt)
|
|
|
|
}
|
|
|
|
|