I have attached a wallet (1499237862.dat) I am getting a balance mismatch. 
Could you explain why this happens. I am getting *0.08125 BTC  *via this 
code:


public class WalletBalanceWithoutSync {
 public static void main(String[] args) throws UnreadableWalletException{
 File file = new File("1499237862.dat");
 Wallet wallet = Wallet.loadFromFile(file);
 System.out.println(wallet);
 System.out.println(wallet.getBalance(BalanceType.AVAILABLE_SPENDABLE).
toFriendlyString());// 0.08125 BTC
 System.out.println(wallet.getBalance(BalanceType.ESTIMATED_SPENDABLE).
toFriendlyString());// 0.08125 BTC
 }
} 


But with this code i am getting *0.06105 BTC:*

public class ReadHdWallet {
 public static void main(String[] args) {
 File file = new File("1499237862.dat");
 NetworkParameters params = TestNet3Params.get();
 try {
 Wallet wallet = Wallet.loadFromFile(file);
 BlockStore blockStore = new MemoryBlockStore(params);
 BlockChain blockChain = new BlockChain(params, blockStore);
 blockChain.addWallet(wallet);
 PeerGroup peerGroup = new PeerGroup(params, blockChain);
 peerGroup.addAddress(new PeerAddress(InetAddress.getByName("127.0.0.1"), 
18333));


 peerGroup.startAsync();
 peerGroup.downloadBlockChain();
 wallet.saveToFile(file);


 System.out.println(wallet.getBalance(BalanceType.AVAILABLE_SPENDABLE).
toFriendlyString());// 0.06105 BTC
 System.out.println(wallet.getBalance(BalanceType.ESTIMATED_SPENDABLE).
toFriendlyString());// 0.06105 BTC
 System.out.println(wallet.toString());
 } catch (UnreadableWalletException ex) {
 ex.printStackTrace();
 } catch (BlockStoreException e) {
 e.printStackTrace();
 } catch (IOException e) {
 e.printStackTrace();
 }
 }
}





On Friday, June 30, 2017 at 11:19:21 PM UTC+5:30, Andreas Schildbach wrote:
>
> For each wallet you want to query the balance of, you will need to sync 
> the blockchain. You can batch-process a number of wallets at the same 
> time though, as you can add multiple wallets to PeerGroup. 
>
> Bitcoinj does not "download" the blockchain, at least it doesn't keep 
> enough information to query balances (UTXOs). 
>
>
>
> On 06/30/2017 02:36 PM, [email protected] <javascript:> 
> wrote: 
> > I have a myWallet.dat file which has 3 BTC . I have created a program to 
> > listen changes in a directory (/opt/bitcoin/wallet) and i have used this 
> > listener program with my bitcoin project , What i want is that if i put 
> > myWallet.dat file in that directory i want it to synchronize with block 
> > chain and get actual balance from it. 
> > 
> > If i use *Wallet.loadFromFile("WALLET_LOCATION")* method to get wallet 
> > object of wallet file and add to block chain like this 
> > *abstractBlockChainObject.addWallet(wallet) , *Consider The block chain 
> > is 100% downloaded , So my question is if i add wallet object like this 
> > will it synchronize my wallet with block chain. 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "bitcoinj" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> > an email to [email protected] <javascript:> 
> > <mailto:[email protected] <javascript:>>. 
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"bitcoinj" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Attachment: 1499237862.dat
Description: Binary data

Reply via email to