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


Java UnreadableWalletException类代码示例

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


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

示例1: loadFromFile

import com.google.bitcoin.store.UnreadableWalletException; //导入依赖的package包/类
/**
 * Returns a wallet deserialized from the given file.
 */
public static Wallet loadFromFile(File f) throws UnreadableWalletException {
    try {
        FileInputStream stream = null;
        try {
            stream = new FileInputStream(f);
            return loadFromFileStream(stream);
        } finally {
            if (stream != null) stream.close();
        }
    } catch (IOException e) {
        throw new UnreadableWalletException("Could not open file", e);
    }
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:17,代码来源:Wallet.java

示例2: loadFromFileStream

import com.google.bitcoin.store.UnreadableWalletException; //导入依赖的package包/类
/**
 * Returns a wallet deserialized from the given input stream.
 */
public static Wallet loadFromFileStream(InputStream stream) throws UnreadableWalletException {
    Wallet wallet = new WalletProtobufSerializer().readWallet(stream);
    if (!wallet.isConsistent()) {
        log.error("Loaded an inconsistent wallet");
    }
    return wallet;
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:11,代码来源:Wallet.java

示例3: loadExtensions

import com.google.bitcoin.store.UnreadableWalletException; //导入依赖的package包/类
private static void loadExtensions(Wallet wallet, Protos.Wallet walletProto) throws UnreadableWalletException {
    final Map<String, WalletExtension> extensions = wallet.getExtensions();
    for (Protos.Extension extProto : walletProto.getExtensionList()) {
        String id = extProto.getId();
        WalletExtension extension = extensions.get(id);
        if (extension == null) {
            if (extProto.getMandatory()) {
                // If the extension is the ORG_MULTIBIT_WALLET_PROTECT or ORG_MULTIBIT_WALLET_PROTECT_2 then we know about that.
                // This is a marker extension to prevent earlier versions of multibit loading encrypted wallets.
                
                // Unfortunately I merged the recognition of the ORG_MULTIBIT_WALLET_PROTECT mandatory extension into the v0.4 code
                // so it could load encrypted wallets mistakenly.
                
                // Hence the v0.5 code now writes ORG_MULTIBIT_WALLET_PROTECT_2.
                if (!(extProto.getId().equals(MultiBitWalletProtobufSerializer.ORG_MULTIBIT_WALLET_PROTECT) || 
                        extProto.getId().equals(MultiBitWalletProtobufSerializer.ORG_MULTIBIT_WALLET_PROTECT_2))) {
                    throw new UnreadableWalletException("Did not understand a mandatory extension in the wallet of '" + extProto.getId() + "'");
                }
            }
        } else {
            log.info("Loading wallet extension {}", id);
            try {
                extension.deserializeWalletExtension(wallet, extProto.getData().toByteArray());
            } catch (Exception e) {
                if (extProto.getMandatory())
                    throw new UnreadableWalletException("Could not parse mandatory extension in wallet: " + id);
            }
        }
    }
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:31,代码来源:MultiBitWalletProtobufSerializer.java

示例4: loadFromFileStream

import com.google.bitcoin.store.UnreadableWalletException; //导入依赖的package包/类
/**
 * Returns a wallet deserialized from the given input stream.
 */
public static Wallet loadFromFileStream(InputStream stream) throws UnreadableWalletException {
    Wallet wallet;

    wallet = new MultiBitWalletProtobufSerializer().readWallet(stream);
    if (!wallet.isConsistent()) {
       log.error("Loaded an inconsistent wallet");
    }

    return wallet;
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:14,代码来源:Wallet.java

示例5: connectTransactionOutputs

import com.google.bitcoin.store.UnreadableWalletException; //导入依赖的package包/类
private WalletTransaction connectTransactionOutputs(org.bitcoinj.wallet.Protos.Transaction txProto) throws UnreadableWalletException {
    Transaction tx = txMap.get(txProto.getHash());
    final WalletTransaction.Pool pool;
    switch (txProto.getPool()) {
        case DEAD: pool = WalletTransaction.Pool.DEAD; break;
        case PENDING: pool = WalletTransaction.Pool.PENDING; break;
        case SPENT: pool = WalletTransaction.Pool.SPENT; break;
        case UNSPENT: pool = WalletTransaction.Pool.UNSPENT; break;
        // Upgrade old wallets: inactive pool has been merged with the pending pool.
        // Remove this some time after 0.9 is old and everyone has upgraded.
        // There should not be any spent outputs in this tx as old wallets would not allow them to be spent
        // in this state.
        case INACTIVE:
        case PENDING_INACTIVE:
            pool = WalletTransaction.Pool.PENDING;
            break;
        default:
            throw new UnreadableWalletException("Unknown transaction pool: " + txProto.getPool());
    }
    for (int i = 0 ; i < tx.getOutputs().size() ; i++) {
        TransactionOutput output = tx.getOutputs().get(i);
        final Protos.TransactionOutput transactionOutput = txProto.getTransactionOutput(i);
        if (transactionOutput.hasSpentByTransactionHash()) {
            final ByteString spentByTransactionHash = transactionOutput.getSpentByTransactionHash();
            Transaction spendingTx = txMap.get(spentByTransactionHash);
            final int spendingIndex = transactionOutput.getSpentByTransactionIndex();
            if (spendingTx != null ) {
                TransactionInput input = checkNotNull(spendingTx.getInput(spendingIndex));
                input.connect(output);
            }
        }
    }
    
    if (txProto.hasConfidence()) {
        Protos.TransactionConfidence confidenceProto = txProto.getConfidence();
        TransactionConfidence confidence = tx.getConfidence();
        readConfidence(tx, confidenceProto, confidence);
    }

    return new WalletTransaction(pool, tx);
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:42,代码来源:MultiBitWalletProtobufSerializer.java

示例6: readConfidence

import com.google.bitcoin.store.UnreadableWalletException; //导入依赖的package包/类
private void readConfidence(Transaction tx, Protos.TransactionConfidence confidenceProto,
                            TransactionConfidence confidence) throws UnreadableWalletException {
    // We are lenient here because tx confidence is not an essential part of the wallet.
    // If the tx has an unknown type of confidence, ignore.
    if (!confidenceProto.hasType()) {
        log.warn("Unknown confidence type for tx {}", tx.getHashAsString());
        return;
    }
    ConfidenceType confidenceType;
    switch (confidenceProto.getType()) {
        case BUILDING: confidenceType = ConfidenceType.BUILDING; break;
        case DEAD: confidenceType = ConfidenceType.DEAD; break;
        // These two are equivalent (must be able to read old wallets).
        case NOT_IN_BEST_CHAIN: confidenceType = ConfidenceType.PENDING; break;
        case PENDING: confidenceType = ConfidenceType.PENDING; break;
        case UNKNOWN:
            // Fall through.
        default:
            confidenceType = ConfidenceType.UNKNOWN; break;
    }
    confidence.setConfidenceType(confidenceType);
    if (confidenceProto.hasAppearedAtHeight()) {
        if (confidence.getConfidenceType() != ConfidenceType.BUILDING) {
            log.warn("Have appearedAtHeight but not BUILDING for tx {}", tx.getHashAsString());
            return;
        }
        confidence.setAppearedAtChainHeight(confidenceProto.getAppearedAtHeight());
    }
    if (confidenceProto.hasDepth()) {
        if (confidence.getConfidenceType() != ConfidenceType.BUILDING) {
            log.warn("Have depth but not BUILDING for tx {}", tx.getHashAsString());
            return;
        }
        confidence.setDepthInBlocks(confidenceProto.getDepth());
    }
    if (confidenceProto.hasWorkDone()) {
        if (confidence.getConfidenceType() != ConfidenceType.BUILDING) {
            log.warn("Have workDone but not BUILDING for tx {}", tx.getHashAsString());
            return;
        }
        confidence.setWorkDone(BigInteger.valueOf(confidenceProto.getWorkDone()));
    }
    if (confidenceProto.hasOverridingTransaction()) {
        if (confidence.getConfidenceType() != ConfidenceType.DEAD) {
            log.warn("Have overridingTransaction but not OVERRIDDEN for tx {}", tx.getHashAsString());
            return;
        }
        Transaction overridingTransaction =
            txMap.get(confidenceProto.getOverridingTransaction());
        if (overridingTransaction == null) {
            log.warn("Have overridingTransaction that is not in wallet for tx {}", tx.getHashAsString());
            return;
        }
        confidence.setOverridingTransaction(overridingTransaction);
    }
    for (Protos.PeerAddress proto : confidenceProto.getBroadcastByList()) {
        InetAddress ip;
        try {
            ip = InetAddress.getByAddress(proto.getIpAddress().toByteArray());
        } catch (UnknownHostException e) {
            throw new UnreadableWalletException("Peer IP address does not have the right length", e);
        }
        int port = proto.getPort();
        PeerAddress address = new PeerAddress(ip, port);
        address.setServices(BigInteger.valueOf(proto.getServices()));
        confidence.markBroadcastBy(address);
    }
    switch (confidenceProto.getSource()) {
        case SOURCE_SELF: confidence.setSource(TransactionConfidence.Source.SELF); break;
        case SOURCE_NETWORK: confidence.setSource(TransactionConfidence.Source.NETWORK); break;
        case SOURCE_UNKNOWN:
            // Fall through.
        default: confidence.setSource(TransactionConfidence.Source.UNKNOWN); break;
    }
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:76,代码来源:MultiBitWalletProtobufSerializer.java

示例7: init

import com.google.bitcoin.store.UnreadableWalletException; //导入依赖的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.store.UnreadableWalletException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。