bitcoinj-cash / bitcoinj

A library for working with Bitcoin
http://bitcoinj.cash
Apache License 2.0
66 stars 35 forks source link

Wallet balance always 0 after restore wallet from seed #78

Open KimJinRyul opened 6 years ago

KimJinRyul commented 6 years ago

Hello I've developing some bitcoin cash wallet app on android with this bitcoinj.cash library. I've some problems with restoring wallet from seed. I restored wallet I had created in other wallet app (handcash) and there are some BCH. but restored wallet shows always has a zero balance.

If I send some bch to this newly restored wallet, It will be displayed as successful and it will be displayed with another wallet app(handcash) that I already have.

The newly restored wallet only shows transactions that occurred after it was restored....

how can I fix this issue?

here is the code that i've tried

NetworkParameters parameters = null;
if(walletAppKit == null || !walletAppKit.isRunning()) {
            if(BuildConfig.MAINNET)
                parameters = MainNetParams.get();
            else
                parameters = TestNet3Params.get();

            File walletDir = getFilesDir();
            walletAppKit = new WalletAppKit(parameters, walletDir, WALLET_NAME) {
                @Override
                protected void onSetupCompleted() {
                        wallet().allowSpendingUnconfirmedTransactions();;
                        wallet().addCoinsReceivedEventListener(BitcoinService.this);
                        wallet().addCoinsSentEventListener(BitcoinService.this);
                        walletAppKit.setDownloadListener(new DownloadProgressTracker() {
                            @Override
                            protected void progress(double pct, int blocksSoFar, Date date) {
                                super.progress(pct, blocksSoFar, date);
                                // progressing....
                            }
                        });
                }
            };
            walletAppKit.setBlockingStartup(false);
            walletAppKit.setAutoSave(true);
            walletAppKit.setUserAgent(getString(R.string.app_name), BuildConfig.VERSION_NAME);
            if (mnemonicCode != null) {
                   try {
                        DeterministicSeed seed = new DeterministicSeed(mnemonicCode, null, "", MnemonicCode.BIP39_STANDARDISATION_TIME_SECS);
                        walletAppKit.restoreWalletFromSeed(seed);
                    } catch (UnreadableWalletException e) {
                        e.printStackTrace();
                    }
                }
            }
            walletAppKit.startAsync();
}
KimJinRyul commented 6 years ago

It's finally get all of balances when block chain sync completed... I've used MnemonicCode.BIP39_STANDARDISATION_TIME_SECS for default creationtime.... and it takes over several hours even with good WIFI netwrok condition. is there any way to sync start from recent block?

HashEngineering commented 6 years ago

You can sync from a later block if the wallet, keychain or seed has a more recent creation time. If your app creates a wallet with a random seed then the creation time is known. However the mnemonic phrase has no creation time, unless you let the use enter that in addition to the seed.