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)
        }
     }
 }
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.