I’m trying to send all coins from my accounts (generated by HD Wallet) to one account with this code:
fun sendAllFundsOnAddress(address: String) {
val receiver = Address.fromString(params, address)
val tx = Transaction(params)
val balance = Coin.valueOf(walletAppKit.wallet().unspents.map { it.value.value }.sum())
tx.addOutput(balance, receiver)
walletAppKit.wallet().unspents.forEach {
val key = walletAppKit.wallet().findKeyFromAddress(Address.fromString(params, it.scriptPubKey.getToAddress(params).toString()))
tx.addSignedInput(it.outPointFor, it.scriptPubKey, key, Transaction.SigHash.ALL, true)
}
walletAppKit.wallet().commitTx(tx)
val sendRequest = SendRequest.forTx(tx)
walletAppKit.wallet().completeTx(sendRequest)
}
But I get NullPointerException, while it calculates witness (in input signing process).
Could you give any ideas, what’s wrong?