bitcoinj-cash / bitcoinj

A library for working with Bitcoin
http://bitcoinj.cash
Apache License 2.0
66 stars 35 forks source link

Transaction Rejected for Signature must use SIGHASH_FORKID even when using request.setUseForkId(true) #54

Closed babramovitch closed 6 years ago

babramovitch commented 6 years ago

I'm trying to send a test transaction using Android / Kotlin, and encountered the SIGHASH_FORKID error, but even after using request.setForkId(True) it still doesn't work? Not sure whats going on?

Everything I find out there just says set the flag?

Received Reject: tx for reason 'mandatory-script-verify-flag-failed (Signature must use SIGHASH_FORKID)' (16)

fun send() {
        val recipientAddress = "someAddress"
        val amount = "0.00001"
        val request =
            SendRequest.to(Address.fromBase58(MainNetParams.get(), recipientAddress), Coin.parseCoin(amount))

        request.setUseForkId(true)

        request.feePerKb = Coin.valueOf(1000)

        try {
            kit.wallet().sendCoins(request)
        } catch (e: InsufficientMoneyException) {
            e.printStackTrace()
            Log.i("TAG", "Error")
        }
}
babramovitch commented 6 years ago

I ended up copying my seed, uninstalling the app, and restoring from seed, and it now works.

My best guess is the failed transaction before I set the flag kept trying to send instead of my newest one, and the newest one never actually tried to send?

Maybe this will help anyone else who encounters this issue

HashEngineering commented 6 years ago

Yes, the failed transaction would stay in the wallet file and attempted to be resent every time the PeerGroup or app was restarted.

babramovitch commented 6 years ago

Cool, thanks for the confirmation =)