2021-10-16 14:45:32 +05:30
|
|
|
import uniffi.bdk.*
|
|
|
|
|
|
|
|
class LogProgress: BdkProgress {
|
|
|
|
override fun update(progress: Float, message: String? ) {
|
2021-10-16 16:42:35 +05:30
|
|
|
println("progress: $progress, message: $message")
|
2021-10-16 14:45:32 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun main(args: Array<String>) {
|
2021-10-16 16:42:35 +05:30
|
|
|
println("Configuring an in-memory wallet on electrum..")
|
2021-10-16 14:45:32 +05:30
|
|
|
val descriptor =
|
|
|
|
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)";
|
2021-10-16 16:42:35 +05:30
|
|
|
val amount = 10000uL;
|
|
|
|
val recipient = "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt";
|
2021-10-16 14:45:32 +05:30
|
|
|
val db = DatabaseConfig.Memory("")
|
|
|
|
val client = BlockchainConfig.Electrum(ElectrumConfig("ssl://electrum.blockstream.info:60002", null, 5u, null, 100u))
|
|
|
|
val wallet = OnlineWallet(descriptor, Network.TESTNET, db, client)
|
|
|
|
val address = wallet.getNewAddress()
|
2021-10-16 16:42:35 +05:30
|
|
|
println("Please send $amount satoshis to address: $address")
|
2021-10-16 14:45:32 +05:30
|
|
|
readLine()
|
|
|
|
println("Syncing...")
|
|
|
|
wallet.sync(LogProgress(), null)
|
|
|
|
val balance = wallet.getBalance()
|
|
|
|
println("New wallet balance: $balance")
|
2021-10-16 16:42:35 +05:30
|
|
|
println("Refunding $amount satoshis to $recipient")
|
|
|
|
val psbt = PartiallySignedBitcoinTransaction(wallet, recipient, amount)
|
2021-10-16 14:45:32 +05:30
|
|
|
println("Press any key to exit")
|
|
|
|
readLine()
|
|
|
|
}
|