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


Java ConfidenceType.BUILDING属性代码示例

本文整理汇总了Java中org.bitcoinj.core.TransactionConfidence.ConfidenceType.BUILDING属性的典型用法代码示例。如果您正苦于以下问题:Java ConfidenceType.BUILDING属性的具体用法?Java ConfidenceType.BUILDING怎么用?Java ConfidenceType.BUILDING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.bitcoinj.core.TransactionConfidence.ConfidenceType的用法示例。


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

示例1: isMature

/**
 * A transaction is mature if it is either a building coinbase tx that is as deep or deeper than the required coinbase depth, or a non-coinbase tx.
 */
public boolean isMature() {
    if (!isCoinBase())
        return true;

    if (getConfidence().getConfidenceType() != ConfidenceType.BUILDING)
        return false;

    return getConfidence().getDepthInBlocks() >= params.getSpendableCoinbaseDepth();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:12,代码来源:Transaction.java

示例2: readConfidence

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() != TransactionConfidence.ConfidenceType.BUILDING) {
            log.warn("Have appearedAtHeight but not BUILDING for tx {}", tx.getHashAsString());
            return;
        }
        confidence.setAppearedAtChainHeight(confidenceProto.getAppearedAtHeight());
    }
    if (confidenceProto.hasDepth()) {
        if (confidence.getConfidenceType() != TransactionConfidence.ConfidenceType.BUILDING) {
            log.warn("Have depth but not BUILDING for tx {}", tx.getHashAsString());
            return;
        }
        confidence.setDepthInBlocks(confidenceProto.getDepth());
    }
}
 
开发者ID:devrandom,项目名称:java-stratum,代码行数:36,代码来源:ElectrumMultiWallet.java

示例3: notifyNewBestBlock

/**
 * <p>Called by the {@link BlockChain} when a new block on the best chain is seen, AFTER relevant wallet
 * transactions are extracted and sent to us UNLESS the new block caused a re-org, in which case this will
 * not be called (the {@link Wallet#reorganize(StoredBlock, java.util.List, java.util.List)} method will
 * call this one in that case).</p>
 * <p/>
 * <p>Used to update confidence data in each transaction and last seen block hash. Triggers auto saving.
 * Invokes the onWalletChanged event listener if there were any affected transactions.</p>
 */
@Override
public void notifyNewBestBlock(StoredBlock block) throws VerificationException {
    // Check to see if this block has been seen before.
    Sha256Hash newBlockHash = block.getHeader().getHash();
    if (newBlockHash.equals(getLastBlockSeenHash()))
        return;
    lock.lock();
    try {
        // Store the new block hash.
        setLastBlockSeenHash(newBlockHash);
        setLastBlockSeenHeight(block.getHeight());
        setLastBlockSeenTimeSecs(block.getHeader().getTimeSeconds());
        // TODO: Clarify the code below.
        // Notify all the BUILDING transactions of the new block.
        // This is so that they can update their depth.
        Set<Transaction> transactions = getTransactions(true);
        for (Transaction tx : transactions) {
            if (ignoreNextNewBlock.contains(tx.getHash())) {
                // tx was already processed in receive() due to it appearing in this block, so we don't want to
                // increment the tx confidence depth twice, it'd result in miscounting.
                ignoreNextNewBlock.remove(tx.getHash());
            } else if (tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING) {
                tx.getConfidence().incrementDepthInBlocks();
                confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
            }
        }

        informConfidenceListenersIfNotReorganizing();
        maybeQueueOnWalletChanged();
        // Coalesce writes to avoid throttling on disk access when catching up with the chain.
        saveLater();
    } finally {
        lock.unlock();
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:44,代码来源:Wallet.java

示例4: subtractDepth

/**
 * Subtract the supplied depth from the given transactions.
 */
private void subtractDepth(int depthToSubtract, Collection<Transaction> transactions) {
    for (Transaction tx : transactions) {
        if (tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING) {
            tx.getConfidence().setDepthInBlocks(tx.getConfidence().getDepthInBlocks() - depthToSubtract);
            confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
        }
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:11,代码来源:Wallet.java

示例5: writeConfidence

private static void writeConfidence(Protos.Transaction.Builder txBuilder,
                                    TransactionConfidence confidence,
                                    Protos.TransactionConfidence.Builder confidenceBuilder) {
    synchronized (confidence) {
        confidenceBuilder.setType(Protos.TransactionConfidence.Type.valueOf(confidence.getConfidenceType().getValue()));
        if (confidence.getConfidenceType() == ConfidenceType.BUILDING) {
            confidenceBuilder.setAppearedAtHeight(confidence.getAppearedAtChainHeight());
            confidenceBuilder.setDepth(confidence.getDepthInBlocks());
        }
        if (confidence.getConfidenceType() == ConfidenceType.DEAD) {
            // Copy in the overriding transaction, if available.
            // (A dead coinbase transaction has no overriding transaction).
            if (confidence.getOverridingTransaction() != null) {
                Sha256Hash overridingHash = confidence.getOverridingTransaction().getHash();
                confidenceBuilder.setOverridingTransaction(hashToByteString(overridingHash));
            }
        }
        TransactionConfidence.Source source = confidence.getSource();
        switch (source) {
            case SELF: confidenceBuilder.setSource(Protos.TransactionConfidence.Source.SOURCE_SELF); break;
            case NETWORK: confidenceBuilder.setSource(Protos.TransactionConfidence.Source.SOURCE_NETWORK); break;
            case UNKNOWN:
                // Fall through.
            default:
                confidenceBuilder.setSource(Protos.TransactionConfidence.Source.SOURCE_UNKNOWN); break;
        }
    }

    for (ListIterator<PeerAddress> it = confidence.getBroadcastBy(); it.hasNext();) {
        PeerAddress address = it.next();
        Protos.PeerAddress proto = Protos.PeerAddress.newBuilder()
                .setIpAddress(ByteString.copyFrom(address.getAddr().getAddress()))
                .setPort(address.getPort())
                .setServices(address.getServices().longValue())
                .build();
        confidenceBuilder.addBroadcastBy(proto);
    }
    txBuilder.setConfidence(confidenceBuilder);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:39,代码来源:WalletProtobufSerializer.java

示例6: writeConfidence

private static void writeConfidence(Protos.Transaction.Builder txBuilder,
                                    TransactionConfidence confidence,
                                    Protos.TransactionConfidence.Builder confidenceBuilder) {
    synchronized (confidence) {
        confidenceBuilder.setType(Protos.TransactionConfidence.Type.valueOf(confidence.getConfidenceType().getValue()));
        if (confidence.getConfidenceType() == ConfidenceType.BUILDING) {
            confidenceBuilder.setAppearedAtHeight(confidence.getAppearedAtChainHeight());
            confidenceBuilder.setDepth(confidence.getDepthInBlocks());
        }
        if (confidence.getConfidenceType() == ConfidenceType.DEAD) {
            // Copy in the overriding transaction, if available.
            // (A dead coinbase transaction has no overriding transaction).
            if (confidence.getOverridingTransaction() != null) {
                Sha256Hash overridingHash = confidence.getOverridingTransaction().getHash();
                confidenceBuilder.setOverridingTransaction(hashToByteString(overridingHash));
            }
        }
        TransactionConfidence.Source source = confidence.getSource();
        switch (source) {
            case SELF: confidenceBuilder.setSource(Protos.TransactionConfidence.Source.SOURCE_SELF); break;
            case NETWORK: confidenceBuilder.setSource(Protos.TransactionConfidence.Source.SOURCE_NETWORK); break;
            case UNKNOWN:
                // Fall through.
            default:
                confidenceBuilder.setSource(Protos.TransactionConfidence.Source.SOURCE_UNKNOWN); break;
        }
    }

    for (PeerAddress address : confidence.getBroadcastBy()) {
        Protos.PeerAddress proto = Protos.PeerAddress.newBuilder()
                .setIpAddress(ByteString.copyFrom(address.getAddr().getAddress()))
                .setPort(address.getPort())
                .setServices(address.getServices().longValue())
                .build();
        confidenceBuilder.addBroadcastBy(proto);
    }
    txBuilder.setConfidence(confidenceBuilder);
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:38,代码来源:WalletProtobufSerializer.java

示例7: writeConfidence

private static void writeConfidence(Protos.Transaction.Builder txBuilder,
                                    TransactionConfidence confidence,
                                    Protos.TransactionConfidence.Builder confidenceBuilder) {
    synchronized (confidence) {
        confidenceBuilder.setType(Protos.TransactionConfidence.Type.valueOf(confidence.getConfidenceType().getValue()));
        if (confidence.getConfidenceType() == ConfidenceType.BUILDING) {
            confidenceBuilder.setAppearedAtHeight(confidence.getAppearedAtChainHeight());
            confidenceBuilder.setDepth(confidence.getDepthInBlocks());
        }
        if (confidence.getConfidenceType() == ConfidenceType.DEAD) {
            // Copy in the overriding transaction, if available.
            // (A dead coinbase transaction has no overriding transaction).
            if (confidence.getOverridingTransaction() != null) {
                Sha256Hash overridingHash = confidence.getOverridingTransaction().getHash();
                confidenceBuilder.setOverridingTransaction(hashToByteString(overridingHash));
            }
        }
        TransactionConfidence.Source source = confidence.getSource();
        switch (source) {
            case SELF: confidenceBuilder.setSource(Protos.TransactionConfidence.Source.SOURCE_SELF); break;
            case NETWORK: confidenceBuilder.setSource(Protos.TransactionConfidence.Source.SOURCE_NETWORK); break;
            case UNKNOWN:
                // Fall through.
            default:
                confidenceBuilder.setSource(Protos.TransactionConfidence.Source.SOURCE_UNKNOWN); break;
        }
    }

    for (PeerAddress address : confidence.getBroadcastBy()) {
        Protos.PeerAddress proto = Protos.PeerAddress.newBuilder()
                .setIpAddress(ByteString.copyFrom(address.getAddr().getAddress()))
                .setPort(address.getPort())
                .setServices(address.getServices().longValue())
                .build();
        confidenceBuilder.addBroadcastBy(proto);
    }
    Date lastBroadcastedAt = confidence.getLastBroadcastedAt();
    if (lastBroadcastedAt != null)
        confidenceBuilder.setLastBroadcastedAt(lastBroadcastedAt.getTime());
    txBuilder.setConfidence(confidenceBuilder);
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:41,代码来源:WalletProtobufSerializer.java

示例8: readConfidence

private void readConfidence(final NetworkParameters params, final Transaction tx,
                            final Protos.TransactionConfidence confidenceProto,
                            final 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 IN_CONFLICT: confidenceType = ConfidenceType.IN_CONFLICT; 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.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();
        int protocolVersion = params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT);
        BigInteger services = BigInteger.valueOf(proto.getServices());
        PeerAddress address = new PeerAddress(params, ip, port, protocolVersion, services);
        confidence.markBroadcastBy(address);
    }
    if (confidenceProto.hasLastBroadcastedAt())
        confidence.setLastBroadcastedAt(new Date(confidenceProto.getLastBroadcastedAt()));
    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:guodroid,项目名称:okwallet,代码行数:73,代码来源:WalletProtobufSerializer.java

示例9: readConfidence

private void readConfidence(final NetworkParameters params, final Transaction tx,
                            final Protos.TransactionConfidence confidenceProto,
                            final 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 IN_CONFLICT: confidenceType = ConfidenceType.IN_CONFLICT; 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.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(params, ip, port);
        address.setServices(BigInteger.valueOf(proto.getServices()));
        confidence.markBroadcastBy(address);
    }
    if (confidenceProto.hasLastBroadcastedAt())
        confidence.setLastBroadcastedAt(new Date(confidenceProto.getLastBroadcastedAt()));
    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:Grant-Redmond,项目名称:cryptwallet,代码行数:72,代码来源:WalletProtobufSerializer.java

示例10: readConfidence

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;
            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());
        }
        // TODO deprecate overriding transactions
//        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:filipnyquist,项目名称:lbry-android,代码行数:67,代码来源:WalletPocketProtobufSerializer.java

示例11: readConfidence

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.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:HashEngineering,项目名称:namecoinj,代码行数:68,代码来源:WalletProtobufSerializer.java

示例12: writeConfidence

private static void writeConfidence(Protos.Transaction.Builder txBuilder,
                                    TransactionConfidence confidence,
                                    Protos.TransactionConfidence.Builder confidenceBuilder) {
    synchronized (confidence) {
        confidenceBuilder.setType(Protos.TransactionConfidence.Type.valueOf(confidence.getConfidenceType().getValue()));
        if (confidence.getConfidenceType() == ConfidenceType.BUILDING) {
            confidenceBuilder.setAppearedAtHeight(confidence.getAppearedAtChainHeight());
            confidenceBuilder.setDepth(confidence.getDepthInBlocks());
        }
        if (confidence.getConfidenceType() == ConfidenceType.DEAD) {
            // Copy in the overriding transaction, if available.
            // (A dead coinbase transaction has no overriding transaction).
            if (confidence.getOverridingTransaction() != null) {
                Sha256Hash overridingHash = confidence.getOverridingTransaction().getHash();
                confidenceBuilder.setOverridingTransaction(hashToByteString(overridingHash));
            }
        }
        TransactionConfidence.Source source = confidence.getSource();
        switch (source) {
            case SELF: confidenceBuilder.setSource(Protos.TransactionConfidence.Source.SOURCE_SELF); break;
            case NETWORK: confidenceBuilder.setSource(Protos.TransactionConfidence.Source.SOURCE_NETWORK); break;
            case UNKNOWN:
                // Fall through.
            default:
                confidenceBuilder.setSource(Protos.TransactionConfidence.Source.SOURCE_UNKNOWN); break;
        }
        TransactionConfidence.IXType ixType = confidence.getIXType();
        switch(ixType)
        {
            case IX_LOCKED: confidenceBuilder.setIxType(Protos.TransactionConfidence.IXType.IX_LOCKED); break;
            case IX_REQUEST: confidenceBuilder.setIxType(Protos.TransactionConfidence.IXType.IX_REQUEST); break;
            case IX_NONE:
            default: confidenceBuilder.setIxType(Protos.TransactionConfidence.IXType.IX_NONE); break;
        }
    }

    for (PeerAddress address : confidence.getBroadcastBy()) {
        Protos.PeerAddress proto = Protos.PeerAddress.newBuilder()
                .setIpAddress(ByteString.copyFrom(address.getAddr().getAddress()))
                .setPort(address.getPort())
                .setServices(address.getServices().longValue())
                .build();
        confidenceBuilder.addBroadcastBy(proto);
    }
    Date lastBroadcastedAt = confidence.getLastBroadcastedAt();
    if (lastBroadcastedAt != null)
        confidenceBuilder.setLastBroadcastedAt(lastBroadcastedAt.getTime());
    txBuilder.setConfidence(confidenceBuilder);
}
 
开发者ID:HashEngineering,项目名称:dashj,代码行数:49,代码来源:WalletProtobufSerializer.java

示例13: readConfidence

private void readConfidence(final NetworkParameters params, final Transaction tx,
                            final Protos.TransactionConfidence confidenceProto,
                            final 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 IN_CONFLICT: confidenceType = ConfidenceType.IN_CONFLICT; 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.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(params, ip, port);
        address.setServices(BigInteger.valueOf(proto.getServices()));
        confidence.markBroadcastBy(address);
    }
    if (confidenceProto.hasLastBroadcastedAt())
        confidence.setLastBroadcastedAt(new Date(confidenceProto.getLastBroadcastedAt()));
    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;
    }
    switch(confidenceProto.getIxType())
    {
        case IX_LOCKED: confidence.setIXType(TransactionConfidence.IXType.IX_LOCKED); break;
        case IX_REQUEST: confidence.setIXType(TransactionConfidence.IXType.IX_REQUEST); break;
        case IX_NONE:
        default:
            confidence.setIXType(TransactionConfidence.IXType.IX_NONE); break;

    }
}
 
开发者ID:HashEngineering,项目名称:dashj,代码行数:81,代码来源:WalletProtobufSerializer.java


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