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 =
|
2021-10-16 20:19:34 +05:30
|
|
|
"pkh(cSQPHDBwXGjVzWRqAHm6zfvQhaTuj1f2bFH58h55ghbjtFwvmeXR)";
|
|
|
|
val amount = 1000uL;
|
2021-10-16 16:42:35 +05:30
|
|
|
val recipient = "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt";
|
2021-10-16 14:45:32 +05:30
|
|
|
val db = DatabaseConfig.Memory("")
|
2021-10-16 20:19:34 +05:30
|
|
|
val client = BlockchainConfig.Electrum(ElectrumConfig("ssl://electrum.blockstream.info:60002", null, 5u, null, 10u))
|
2021-10-16 14:45:32 +05:30
|
|
|
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 20:19:34 +05:30
|
|
|
println("Press Enter to return funds")
|
|
|
|
readLine()
|
|
|
|
println("Creating a partially signed bitcoin transaction with recipient $recipient and amount $amount satoshis...")
|
|
|
|
val transaction = PartiallySignedBitcoinTransaction(wallet, recipient, amount)
|
|
|
|
println("Signing the transaction...")
|
|
|
|
wallet.sign(transaction)
|
|
|
|
println("Broadcasting the signed transaction...")
|
|
|
|
val transactionId = wallet.broadcast(transaction)
|
|
|
|
println("Refunded $amount satoshis to $recipient via transaction id $transactionId")
|
|
|
|
println("Syncing...")
|
|
|
|
wallet.sync(LogProgress(), null)
|
|
|
|
val final_balance = wallet.getBalance()
|
|
|
|
println("New wallet balance: $final_balance")
|
|
|
|
println("Press Enter to exit")
|
2021-10-16 14:45:32 +05:30
|
|
|
readLine()
|
|
|
|
}
|