I've found a couple of threads on this, but nothing concrete on how to 
actually do it. The goal is to have a watching wallet in an online app and 
a signing wallet in an offline. The signing wallet would serialize the 
signed tx for the app containing the watching wallet to broadcast. I've 
been at this for about a week and just cant get it working correctly. 
Here's what I have so far (its in Kotlin, I can translate to Java if need 
be). If anyone could point out what I'm doing wrong, that would be great.

*Online App with Watching Wallet:*
// prepare tx to be signed
val sendRequest = SendRequest.to(Address.fromString(networkParams, 
request.to), Coin.valueOf(request.amount))
sendRequest.signInputs = false
watchingWallet.completeTx(sendRequest)

val connectedOutput = sendRequest.tx.inputs.first().connectedOutput
val connectedOutputIndex = connectedOutput?.index ?: 0
val serializedTxToSign = sendRequest.tx.bitcoinSerialize()
rpcService.sendToSigningWallet(serializedTxToSign, connectedOutputIndex)



*Cold App with Signing Wallet:*
val ecKey = ECKey.fromPrivate(signingWallet.currentReceiveKey().privKey)
val tx = Transaction(networkParams, request.serializedTxToSign)
val scriptPubKey = tx.outputs[request.connectedOutputIndex].scriptPubKey

// there's only ever one, but I'm looping anyway...
tx.inputs.forEachIndexed { idx, input ->
            val hash = tx.hashForSignature(idx, scriptPubKey, Transaction.
SigHash.ALL, false)
            if (scriptPubKey.isSentToAddress) {
                val signedHash = ecKey.sign(hash)
                val transactionSignature = TransactionSignature(signedHash, 
Transaction.SigHash.ALL, false)
                input.scriptSig = ScriptBuilder.createInputScript(
transactionSignature, ecKey)
            }
}
val serializedSignedTx = tx.bitcoinSerialize()
rpcService.sendToOnlineApp(serializedSignedTx)

*Back in Online App:*
val signedTx = Transaction(networkParams, serializedSignedTx)
peerGroup.broadcastTransaction(signedTx)

The broadcast seems to kill my PeerGroup connection to my RegTest bitcoin 
node. I'm assuming because the transaction was invalid.
Again, would be amazing if anyone could help me sort this out.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"bitcoinj" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bitcoinj+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to