When downloading the blockchain my application is become unusable, is there an issue with my code or am I using the BitcoinJ library incorrectly?

0

I am building a Bitcoin wallet with the BitcoinJ Library, after looking at the example of fetching a transaction that they have shown on their github it shows that you need to download the blockchain however.

When attempting to download the blockchain to view the balance of my wallet, it begins to lock up and become unusable. I have even tried downloading the blockchain in an async task like so, but still the app becomes completely unusable and the UI doesn't even load. What am I missing? I thought that the download wouldn't be that large as I am attempting to create an SPV wallet which from what I understand doesn't download the entire blockchain, or is this something I need to configure seperately?

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
         DownloadBlockchain().execute()
    }

    inner class DownloadBlockchain : AsyncTask<Void, Int, String>() {
        override fun doInBackground(vararg p0: Void?): String {
            Globals.peerGroup?.startAsync()
            Globals.peerGroup?.downloadBlockChain()
            return "complete"
        }

        override fun onPostExecute(result: String?) {
            super.onPostExecute(result)
            Globals.peerGroup?.stopAsync()
            Globals.wallet?.saveToFile(Globals.walletFile)
        }
     }
 }

Ben Moore

Posted 2019-02-19T16:03:24.163

Reputation: 1

Answers

0

The downloadBlockChain() method looks like it downloads the whole blockchain. It looks like the PeerGroup.setFastCatchupTime method might be helpful to prevent it from downloading full blocks before that time. I imagine you'll use a method or change a boolean value to only download block headers for your SPV wallet, but I don't know where that would be.

https://bitcoinj.github.io/speeding-up-chain-sync may be a useful reference.

Vecna

Posted 2019-02-19T16:03:24.163

Reputation: 304