Java 类org.bitcoinj.core.listeners.DownloadProgressTracker 实例源码

项目:uidcore-java    文件:NodeUtils.java   
/**
 * Synchronize a list of {@code Wallet} against the BlockChain.
 * 
 * @param params the NetworkParameters to use
 * @param wallets the list of Wallet
 * @param chainFile the chain file to use
 * @param listener the listener to inform for status changes
 */
public static void syncBlockChain(UniquidNodeConfiguration configuration, final List<Wallet> wallets, final File chainFile, 
        final DownloadProgressTracker listener, final NativePeerEventListener peerListener) {

    try {
        NetworkParameters params = configuration.getNetworkParameters();

        BlockStore chainStore = new SPVBlockStore(params, chainFile);

        for (Wallet wallet : wallets) {

            if ((wallet.getLastBlockSeenHeight() < 1) &&
                    (openStream(params) != null)) {

                try {

                    CheckpointManager.checkpoint(params, openStream(params), chainStore,
                            configuration.getCreationTime());

                    StoredBlock head = chainStore.getChainHead();
                    LOGGER.info("Skipped to checkpoint " + head.getHeight() + " at "
                             + Utils.dateTimeFormat(head.getHeader().getTimeSeconds() * 1000));

                } catch (Throwable t) {

                    LOGGER.warn("Problem using checkpoints", t);

                }

                break;
            }

        }

        BlockChain chain = new BlockChain(params, wallets, chainStore);

        final PeerGroup peerGroup = new PeerGroup(params, chain);
        peerGroup.setUserAgent("UNIQUID", "0.1");
        peerGroup.setMaxPeersToDiscoverCount(3);
        peerGroup.setMaxConnections(2);

        if (params.getDnsSeeds() != null &&
                params.getDnsSeeds().length > 0) {
            peerGroup.addPeerDiscovery(new DnsDiscovery(params));
        } else if (params.getAddrSeeds() != null &&
                    params.getAddrSeeds().length > 0) {
                        peerGroup.addPeerDiscovery(new SeedPeers(params.getAddrSeeds(), params));
        } else {
            throw new Exception("Problem with Peers discovery!");
        }

        LOGGER.info("BLOCKCHAIN Preparing to download blockchain...");

        peerGroup.addConnectedEventListener(peerListener);
        peerGroup.addDisconnectedEventListener(peerListener);
        peerGroup.addDiscoveredEventListener(peerListener);
        peerGroup.start();
        peerGroup.startBlockChainDownload(listener);
        listener.await();
        peerGroup.stop();
        chainStore.close();

        LOGGER.info("BLOCKCHAIN downloaded.");

    } catch (Exception ex) {

        LOGGER.error("Exception catched ", ex);

    }
}
项目:cryptwallet    文件:MainController.java   
public DownloadProgressTracker progressBarUpdater() {
    return model.getDownloadProgressTracker();
}
项目:dashj    文件:RestoreFromSeed.java   
public static void main(String[] args) throws Exception {
    NetworkParameters params = TestNet3Params.get();

    // Bitcoinj supports hierarchical deterministic wallets (or "HD Wallets"): https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
    // HD wallets allow you to restore your wallet simply from a root seed. This seed can be represented using a short mnemonic sentence as described in BIP 39: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki

    // Here we restore our wallet from a seed with no passphrase. Also have a look at the BackupToMnemonicSeed.java example that shows how to backup a wallet by creating a mnemonic sentence.
    String seedCode = "yard impulse luxury drive today throw farm pepper survey wreck glass federal";
    String passphrase = "";
    Long creationtime = 1409478661L;

    DeterministicSeed seed = new DeterministicSeed(seedCode, null, passphrase, creationtime);

    // The wallet class provides a easy fromSeed() function that loads a new wallet from a given seed.
    Wallet wallet = Wallet.fromSeed(params, seed);

    // Because we are importing an existing wallet which might already have transactions we must re-download the blockchain to make the wallet picks up these transactions
    // You can find some information about this in the guides: https://bitcoinj.github.io/working-with-the-wallet#setup
    // To do this we clear the transactions of the wallet and delete a possible existing blockchain file before we download the blockchain again further down.
    System.out.println(wallet.toString());
    wallet.clearTransactions(0);
    File chainFile = new File("restore-from-seed.spvchain");
    if (chainFile.exists()) {
        chainFile.delete();
    }

    // Setting up the BlochChain, the BlocksStore and connecting to the network.
    SPVBlockStore chainStore = new SPVBlockStore(params, chainFile);
    BlockChain chain = new BlockChain(params, chainStore);
    PeerGroup peers = new PeerGroup(params, chain);
    peers.addPeerDiscovery(new DnsDiscovery(params));

    // Now we need to hook the wallet up to the blockchain and the peers. This registers event listeners that notify our wallet about new transactions.
    chain.addWallet(wallet);
    peers.addWallet(wallet);

    DownloadProgressTracker bListener = new DownloadProgressTracker() {
        @Override
        public void doneDownload() {
            System.out.println("blockchain downloaded");
        }
    };

    // Now we re-download the blockchain. This replays the chain into the wallet. Once this is completed our wallet should know of all its transactions and print the correct balance.
    peers.start();
    peers.startBlockChainDownload(bListener);

    bListener.await();

    // Print a debug message with the details about the wallet. The correct balance should now be displayed.
    System.out.println(wallet.toString());

    // shutting down again
    peers.stop();
}
项目:dashj    文件:MainController.java   
public DownloadProgressTracker progressBarUpdater() {
    return model.getDownloadProgressTracker();
}
项目:bitcoinj    文件:RestoreFromSeed.java   
public static void main(String[] args) throws Exception {
    NetworkParameters params = TestNet3Params.get();

    // Bitcoinj supports hierarchical deterministic wallets (or "HD Wallets"): https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
    // HD wallets allow you to restore your wallet simply from a root seed. This seed can be represented using a short mnemonic sentence as described in BIP 39: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki

    // Here we restore our wallet from a seed with no passphrase. Also have a look at the BackupToMnemonicSeed.java example that shows how to backup a wallet by creating a mnemonic sentence.
    String seedCode = "yard impulse luxury drive today throw farm pepper survey wreck glass federal";
    String passphrase = "";
    Long creationtime = 1409478661L;

    DeterministicSeed seed = new DeterministicSeed(seedCode, null, passphrase, creationtime);

    // The wallet class provides a easy fromSeed() function that loads a new wallet from a given seed.
    Wallet wallet = Wallet.fromSeed(params, seed);

    // Because we are importing an existing wallet which might already have transactions we must re-download the blockchain to make the wallet picks up these transactions
    // You can find some information about this in the guides: https://bitcoinj.github.io/working-with-the-wallet#setup
    // To do this we clear the transactions of the wallet and delete a possible existing blockchain file before we download the blockchain again further down.
    System.out.println(wallet.toString());
    wallet.clearTransactions(0);
    File chainFile = new File("restore-from-seed.spvchain");
    if (chainFile.exists()) {
        chainFile.delete();
    }

    // Setting up the BlochChain, the BlocksStore and connecting to the network.
    SPVBlockStore chainStore = new SPVBlockStore(params, chainFile);
    BlockChain chain = new BlockChain(params, chainStore);
    PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.addPeerDiscovery(new DnsDiscovery(params));

    // Now we need to hook the wallet up to the blockchain and the peers. This registers event listeners that notify our wallet about new transactions.
    chain.addWallet(wallet);
    peerGroup.addWallet(wallet);

    DownloadProgressTracker bListener = new DownloadProgressTracker() {
        @Override
        public void doneDownload() {
            System.out.println("blockchain downloaded");
        }
    };

    // Now we re-download the blockchain. This replays the chain into the wallet. Once this is completed our wallet should know of all its transactions and print the correct balance.
    peerGroup.start();
    peerGroup.startBlockChainDownload(bListener);

    bListener.await();

    // Print a debug message with the details about the wallet. The correct balance should now be displayed.
    System.out.println(wallet.toString());

    // shutting down again
    peerGroup.stop();
}
项目:bitcoinj    文件:MainController.java   
public DownloadProgressTracker progressBarUpdater() {
    return model.getDownloadProgressTracker();
}
项目:uidcore-java    文件:NodeUtils.java   
/**
 * Synchronize a single of {@code Wallet} against the BlockChain.
 * 
 * @param params the NetworkParameters to use
 * @param wallet the Wallet to synchronize
 * @param chainFile the chain file to use
 * @param listener the listener to inform for status changes
 */
public static void syncBlockChain(UniquidNodeConfiguration configuration, final Wallet wallet, final File chainFile, 
        final DownloadProgressTracker listener, final NativePeerEventListener peerListener) {

    syncBlockChain(configuration, Arrays.asList(new Wallet[] { wallet }), chainFile, listener, peerListener);

}
项目:cryptwallet    文件:BitcoinUIModel.java   
public DownloadProgressTracker getDownloadProgressTracker() { return syncProgressUpdater; }
项目:dashj    文件:BitcoinUIModel.java   
public DownloadProgressTracker getDownloadProgressTracker() { return syncProgressUpdater; }
项目:bitcoinj    文件:BitcoinUIModel.java   
public DownloadProgressTracker getDownloadProgressTracker() { return syncProgressUpdater; }