• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DownloadProgressTracker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bitcoinj.core.listeners.DownloadProgressTracker的典型用法代码示例。如果您正苦于以下问题:Java DownloadProgressTracker类的具体用法?Java DownloadProgressTracker怎么用?Java DownloadProgressTracker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DownloadProgressTracker类属于org.bitcoinj.core.listeners包,在下文中一共展示了DownloadProgressTracker类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: syncBlockChain

import org.bitcoinj.core.listeners.DownloadProgressTracker; //导入依赖的package包/类
/**
 * 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);

	}
}
 
开发者ID:uniquid,项目名称:uidcore-java,代码行数:78,代码来源:NodeUtils.java


示例2: progressBarUpdater

import org.bitcoinj.core.listeners.DownloadProgressTracker; //导入依赖的package包/类
public DownloadProgressTracker progressBarUpdater() {
    return model.getDownloadProgressTracker();
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:4,代码来源:MainController.java


示例3: main

import org.bitcoinj.core.listeners.DownloadProgressTracker; //导入依赖的package包/类
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();
}
 
开发者ID:HashEngineering,项目名称:dashj,代码行数:56,代码来源:RestoreFromSeed.java


示例4: main

import org.bitcoinj.core.listeners.DownloadProgressTracker; //导入依赖的package包/类
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();
}
 
开发者ID:bitcoinj,项目名称:bitcoinj,代码行数:56,代码来源:RestoreFromSeed.java


示例5: getDownloadProgressTracker

import org.bitcoinj.core.listeners.DownloadProgressTracker; //导入依赖的package包/类
public DownloadProgressTracker getDownloadProgressTracker() { return syncProgressUpdater; } 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:2,代码来源:BitcoinUIModel.java



注:本文中的org.bitcoinj.core.listeners.DownloadProgressTracker类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SearchSuggestionsAdapter类代码示例发布时间:2022-05-22
下一篇:
Java TokenizerMapper类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap