コード例 #1
0
  private boolean handleTx(final Transaction tx) {
    log.info("tx " + tx.getHashAsString() + " arrived via blueooth");

    try {
      if (wallet.isTransactionRelevant(tx)) {
        wallet.receivePending(tx, null);

        handler.post(
            new Runnable() {
              @Override
              public void run() {
                application.broadcastTransaction(tx);
              }
            });
      } else {
        log.info("tx " + tx.getHashAsString() + " irrelevant");
      }

      return true;
    } catch (final VerificationException x) {
      log.info("cannot verify tx " + tx.getHashAsString() + " received via bluetooth", x);
    }

    return false;
  }
コード例 #2
0
  private void doOpenDispute(boolean isSupportTicket, Transaction depositTx) {
    Log.traceCall("depositTx=" + depositTx);
    byte[] depositTxSerialized = null;
    byte[] payoutTxSerialized = null;
    String depositTxHashAsString = null;
    String payoutTxHashAsString = null;
    if (depositTx != null) {
      depositTxSerialized = depositTx.bitcoinSerialize();
      depositTxHashAsString = depositTx.getHashAsString();
    } else {
      log.warn("depositTx is null");
    }
    Transaction payoutTx = trade.getPayoutTx();
    if (payoutTx != null) {
      payoutTxSerialized = payoutTx.bitcoinSerialize();
      payoutTxHashAsString = payoutTx.getHashAsString();
    }

    Dispute dispute =
        new Dispute(
            disputeManager.getDisputeStorage(),
            trade.getId(),
            keyRing.getPubKeyRing().hashCode(), // traderId
            trade.getOffer().getDirection() == Offer.Direction.BUY ? isOfferer : !isOfferer,
            isOfferer,
            keyRing.getPubKeyRing(),
            trade.getDate(),
            trade.getContract(),
            trade.getContractHash(),
            depositTxSerialized,
            payoutTxSerialized,
            depositTxHashAsString,
            payoutTxHashAsString,
            trade.getContractAsJson(),
            trade.getOffererContractSignature(),
            trade.getTakerContractSignature(),
            user.getAcceptedArbitratorByAddress(trade.getArbitratorNodeAddress()).getPubKeyRing(),
            isSupportTicket);

    trade.setDisputeState(Trade.DisputeState.DISPUTE_REQUESTED);
    disputeManager.sendOpenNewDisputeMessage(dispute);
    navigation.navigateTo(MainView.class, DisputesView.class);
  }
コード例 #3
0
  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);
        if (spendingTx == null) {
          throw new UnreadableWalletException(
              String.format(
                  "Could not connect %s to %s",
                  tx.getHashAsString(), byteStringToHash(spentByTransactionHash)));
        }
        final int spendingIndex = transactionOutput.getSpentByTransactionIndex();
        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);
  }
コード例 #4
0
 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();
     int protocolVersion = tx.getParams().getProtocolVersion();
     PeerAddress address = new PeerAddress(ip, port, protocolVersion);
     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;
   }
 }