Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Sanka555 on February 28, 2021, 10:59:57 AM



Title: How to get the number of satoshi using adress?
Post by: Sanka555 on February 28, 2021, 10:59:57 AM
Java, Spring,  Eclipce, bitcoinj

I'm trying to get the number of satoshi using the private key.
First I get the address
everything prints it fine.
then I try to find out the amount...


NetworkParameters params = MainNetParams.get();

Wallet wallet = new Wallet(params);
BlockStore blockStore = new MemoryBlockStore(params);
BlockChain chain;
try {
chain = new BlockChain(params, wallet, blockStore);

PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.addWallet(wallet);
peerGroup.start();
peerGroup.downloadBlockChain ();

model.addAttribute("balance", wallet.getBalance());


hangs tightly.
How to find out the correct amount on the account? I have a synchronized Core / Can I get it out of it somehow?

thank you very much in any your advices


Quote
2021-02-28 13:00:00.044  INFO 7496 --- [eerGroup Thread] o.bitcoinj.wallet.DeterministicKeyChain  : 133 keys needed for M/0H/0 = 0 issued + 100 lookahead size + 33 lookahead threshold - 0 num children
2021-02-28 13:00:00.145  INFO 7496 --- [eerGroup Thread] o.bitcoinj.wallet.DeterministicKeyChain  : Took 101.2 ms
2021-02-28 13:00:00.146  INFO 7496 --- [eerGroup Thread] o.bitcoinj.wallet.DeterministicKeyChain  : 133 keys needed for M/0H/1 = 0 issued + 100 lookahead size + 33 lookahead threshold - 0 num children
2021-02-28 13:00:00.235  INFO 7496 --- [eerGroup Thread] o.bitcoinj.wallet.DeterministicKeyChain  : Took 88.82 ms
2021-02-28 13:00:00.243  INFO 7496 --- [eerGroup Thread] org.bitcoinj.core.PeerGroup              : Starting ...
2021-02-28 13:00:01.250  INFO 7496 --- [eerGroup Thread] org.bitcoinj.core.PeerGroup              : Localhost peer not detected.
2021-02-28 13:00:01.251  INFO 7496 --- [eerGroup Thread] org.bitcoinj.core.PeerGroup              : Peer discovery took 9.320 μs and returned 0 items


Title: Re: How to get the number of satoshi using adress?
Post by: aliashraf on February 28, 2021, 08:22:40 PM
You are going the hard way. For bitcoinj, I'd suggest to start with WalletAppKit wrapper, it has already integrated all the components you are trying to synchronize. Just follow the instructions in the document, and you will be fine.

As of your code, I think it fails primarily because of network connectivity or misconfiguration. Actually my first diagnosis is that you have initialized the params object for regtest mode while your machine has not a bitcoind process running on it with -regtest argument.

Note: WalletAppKit, works in SPV mode, and it works fine, bitoinj is not a reliable code base for full mode, however.

Edit:
Also note that the PeerGroup class you are using is a blocking I/O class, what you are experiencing may be a blocked object pulling for I/O rather than a dead program.