当前位置: 首页>>代码示例>>Java>>正文


Java BlockChain类代码示例

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


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

示例1: WalletHarness

import com.google.bitcoin.core.BlockChain; //导入依赖的package包/类
public WalletHarness(NetworkParameters p) throws BlockStoreException {
    InsecureRandomTest.initInsecureRandom();

    LogManager logManager = LogManager.getLogManager();
    Enumeration<String> loggerNames = logManager.getLoggerNames();
    while (loggerNames.hasMoreElements()) {
        Logger logger = logManager.getLogger(loggerNames.nextElement());
        logger.setLevel(Level.WARNING);
    }

    params = p;
    wallet = new Wallet(params);
    // wallet.keychain.add(new ECKey());

    blockStore = new MemoryBlockStore(params);

    chain = new BlockChain(params, wallet, blockStore);

    hardcodedBlocks = new HardcodedBlocks();
}
 
开发者ID:dustyneuron,项目名称:bitprivacy,代码行数:21,代码来源:WalletHarness.java

示例2: MultiBitPeerGroup

import com.google.bitcoin.core.BlockChain; //导入依赖的package包/类
public MultiBitPeerGroup(BitcoinController bitcoinController, NetworkParameters params, BlockChain chain) {
    super(params, chain);
    this.bitcoinController = bitcoinController;
    this.controller = this.bitcoinController;
    multiBitDownloadListener = new MultiBitDownloadListener(this.bitcoinController);

    setMaxConnections(MAXIMUM_NUMBER_OF_PEERS);
}
 
开发者ID:coinspark,项目名称:sparkbit,代码行数:9,代码来源:MultiBitPeerGroup.java

示例3: backupPrivateKeys

import com.google.bitcoin.core.BlockChain; //导入依赖的package包/类
/**
 * Backup the private keys of the active wallet to a file with name <wallet-name>-data/key-backup/<wallet
 * name>-yyyymmddhhmmss.key
 * 
 * TODO This might be better on the BackupManager
 * 
 * @param passwordToUse
 * @return File to which keys were backed up, or null if they were not.
 * @throws KeyCrypterException
 */
public File backupPrivateKeys(CharSequence passwordToUse) throws IOException, KeyCrypterException {
    File privateKeysBackupFile = null;

    // Only encrypted files are backed up, and they must have a non blank password.
    if (passwordToUse != null && passwordToUse.length() > 0) {
        if (controller.getModel() != null
                && this.bitcoinController.getModel().getActiveWalletWalletInfo() != null
                && this.bitcoinController.getModel().getActiveWalletWalletInfo().getWalletVersion() == MultiBitWalletVersion.PROTOBUF_ENCRYPTED) {
            // Save a backup copy of the private keys, encrypted with the passwordToUse.
            PrivateKeysHandler privateKeysHandler = new PrivateKeysHandler(this.bitcoinController.getModel()
                    .getNetworkParameters());
            String privateKeysBackupFilename = BackupManager.INSTANCE.createBackupFilename(new File(this.bitcoinController.getModel()
                    .getActiveWalletFilename()), BackupManager.PRIVATE_KEY_BACKUP_DIRECTORY_NAME, false, false, BitcoinModel.PRIVATE_KEY_FILE_EXTENSION);
            privateKeysBackupFile = new File(privateKeysBackupFilename);
            BlockChain blockChain = null;
            if (this.bitcoinController.getMultiBitService() != null) {
                blockChain = this.bitcoinController.getMultiBitService().getChain();
            }

            privateKeysHandler.exportPrivateKeys(privateKeysBackupFile, this.bitcoinController.getModel().getActiveWallet(),
                    blockChain, true, passwordToUse, passwordToUse);
        } else {
            log.debug("Wallet '" + this.bitcoinController.getModel().getActiveWalletFilename()
                    + "' private keys not backed up as not PROTOBUF_ENCRYPTED");
        }
    } else {
        log.debug("Wallet '" + this.bitcoinController.getModel().getActiveWalletFilename()
                + "' private keys not backed up password was blank or of zero length");
    }
    return privateKeysBackupFile;
}
 
开发者ID:coinspark,项目名称:sparkbit,代码行数:42,代码来源:FileHandler.java

示例4: init

import com.google.bitcoin.core.BlockChain; //导入依赖的package包/类
public synchronized void init(String n) throws Exception {

        nodeName = n;

        params = TestNet3Params.get();

        walletFile = new File(nodeName + ".wallet");
        try {
            wallet = Wallet.loadFromFile(walletFile);
            System.out.println("Opened wallet " + walletFile.getAbsolutePath());
        } catch (UnreadableWalletException e) {
            wallet = new Wallet(params);
            wallet.addKey(new ECKey());
            System.out.println("Created new wallet "
                    + walletFile.getAbsolutePath());
        }
        wallet.autosaveToFile(walletFile, 1, TimeUnit.SECONDS, null);

        // System.out.println("Reading block store from disk");

        File file = new File(nodeName + ".spvchain");
        boolean chainExistedAlready = file.exists();
        blockStore = new SPVBlockStore(params, file);
        if (!chainExistedAlready) {
            File checkpointsFile = new File("checkpoints");
            if (checkpointsFile.exists()) {
                ECKey key = wallet.getKeys().iterator().next();
                FileInputStream stream = new FileInputStream(checkpointsFile);
                CheckpointManager.checkpoint(params, stream, blockStore,
                        key.getCreationTimeSeconds());
            }
        }

        chain = new BlockChain(params, wallet, blockStore);

        // make sure that we shut down cleanly!
        final WalletMgr walletMgr = this;
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                walletMgr.shutdown();
            }
        });

        txCommands = new TxCommands(this);
    }
 
开发者ID:dustyneuron,项目名称:bitprivacy,代码行数:47,代码来源:WalletMgr.java


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