Getting steadiness/downloading blockhain with bitcoinj

0
63


I’m taking part in round with bitoinj and I can not seem to even get essentially the most primary performance working.

What I wish to do: I’ve one pockets with one deal with. I wish to dowload blockchain and from that, get the pockets steadiness.

What I did is following code (in scala, nevertheless it is kind of the identical factor as Java), the pockets is in deal with.walet, I would like the blockain to be saved at saved.blockchain:

val params = NetworkParameters.prodNet
val walletFile = new java.io.File("deal with.pockets");
val pockets = Pockets.loadFromFile(walletFile)

val key = pockets.keychain.get(0)
val deal with:String = key.toAddress(params).toString
println("ADDRESS IS : "+deal with)

val blockStore = new BoundedOverheadBlockStore(params, new java.io.File("saved.blockchain"))
val chain = new BlockChain(params, pockets, blockStore)
val peerGroup = new PeerGroup(params, chain)
peerGroup.setUserAgent("BitToy", "0.1")

peerGroup.addPeerDiscovery(new DnsDiscovery(params))
peerGroup.addWallet(pockets)
println("START DOWNLOADING BLOCKCHAIN")

peerGroup.begin()
peerGroup.downloadBlockChain()
peerGroup.cease()
println("DONE; BALANCE IS :")
println(pockets.getBalance)

I do have steadiness on the deal with within the pockets.

Now, after I run it for the primary time, the blockchain (or, reasonably, the headers) will get downloaded and I see the proper steadiness. Nevertheless, after I run it for second time, I simply see:

ADDRESS IS : [correct address here]
Aug 19, 2012 8:06:00 AM com.google.bitcoin.retailer.BoundedOverheadBlockStore load
INFO: Studying block retailer from saved.blockchain
Aug 19, 2012 8:06:00 AM com.google.bitcoin.retailer.BoundedOverheadBlockStore load
INFO: Learn chain head from disk: 00000000000001b10c347b5ec05f9a1910d541905c5cd8827784a5c3e0695c95
Aug 19, 2012 8:06:00 AM com.google.bitcoin.core.BlockChain <init>
INFO: chain head is at peak 194575:
v1 block: 
   earlier block: 00000000000005ac50dc06021362cd4c284fafd4a1bdb7bad2849c978a875bb1
   merkle root: 158aedd0bc3386c7686f85ab933fd9e3ecb38e348b121ed0e61e2e776eda04a1
   time: [1345356028] Solar Aug 19 08:00:28 CEST 2012
   problem goal (nBits): 436709470
   nonce: 4238997601

START DOWNLOADING BLOCKCHAIN
Aug 19, 2012 8:06:31 AM com.google.bitcoin.discovery.DnsDiscovery getPeers
INFO: DNS lookup for dnsseed.bitcoin.dashjr.org failed.
Aug 19, 2012 8:06:36 AM com.google.bitcoin.core.TCPNetworkConnection$NetworkHandler channelConnected
INFO: Asserting ourselves as: /BitCoinJ:0.6-SNAPSHOT/BitMessage:0.1/
Aug 19, 2012 8:06:41 AM com.google.bitcoin.core.Peer$PeerHandler exceptionCaught
INFO: com.google.bitcoin.core.Peer$PeerHandler@193f6e2 - No path to host
Aug 19, 2012 8:06:46 AM com.google.bitcoin.core.Peer$PeerHandler exceptionCaught
INFO: com.google.bitcoin.core.Peer$PeerHandler@61736e - No path to host
Aug 19, 2012 8:06:52 AM com.google.bitcoin.core.TCPNetworkConnection$NetworkHandler channelConnected
INFO: Asserting ourselves as: /BitCoinJ:0.6-SNAPSHOT/BitMessage:0.1/
Aug 19, 2012 8:06:52 AM com.google.bitcoin.core.PeerGroup handleNewPeer
INFO: Peer(seed.bitcoin.sipa.be/50.130.4.89:8333): New peer
Aug 19, 2012 8:06:52 AM com.google.bitcoin.core.PeerGroup handleNewPeer
INFO:   beginning block chain obtain
Aug 19, 2012 8:06:52 AM com.google.bitcoin.core.PeerGroup setDownloadPeer
INFO: Setting obtain peer: Peer(seed.bitcoin.sipa.be/50.130.4.89:8333)
Downloading block chain of measurement 0. 
Completed downloading block chain
Aug 19, 2012 8:06:52 AM com.google.bitcoin.core.Peer blockChainDownload
INFO: Peer(seed.bitcoin.sipa.be/50.130.4.89:8333): blockChainDownload(0000000000000000000000000000000000000000000000000000000000000000) present head = 00000000000001b10c347b5ec05f9a1910d541905c5cd8827784a5c3e0695c95
DONE; BALANCE IS :
0
Aug 19, 2012 8:06:52 AM com.google.bitcoin.core.PeerGroup$PeerGroupThread run
INFO: shutdown begin

and the steadiness is zero. If I delete the saved blockchain and let it re-download once more, it really works once more, however just for one time.

What am I doing improper?

LEAVE A REPLY

Please enter your comment!
Please enter your name here