Пример #1
0
  public static List<TransactionOutput> getMyOutputs(Transaction tx, DeterministicKey key) {
    List<TransactionOutput> mines = new ArrayList<>();
    for (TransactionOutput curr : tx.getOutputs()) {
      boolean isMine = false;

      String to = null;
      Address add = curr.getAddressFromP2PKHScript(BitcoinNetwork.getInstance().get().getParams());
      if (add != null) to = add.toString();
      else {
        add = curr.getAddressFromP2SH(BitcoinNetwork.getInstance().get().getParams());
        if (add != null) to = add.toString();
      }
      if (to != null) { // VERIFICATION BY ADDRESS
        isMine = to.equals(keyToStringAddress(key));
      } else { // VERIFICATION BY PUBKEY
        final byte[] pubKeyCurr = curr.getScriptPubKey().getPubKey();
        isMine = Arrays.equals(key.getPubKey(), pubKeyCurr);
      }

      if (isMine) {
        mines.add(curr);
        break;
      }
    }
    return mines;
  }
 @CheckForNull
 private static List<Address> getToAddresses(
     @Nonnull final Transaction tx, @Nonnull final AbstractWallet pocket, boolean toMe) {
   List<Address> addresses = new ArrayList<Address>();
   for (final TransactionOutput output : tx.getOutputs()) {
     try {
       if (output.isMine(pocket) == toMe) {
         addresses.add(output.getScriptPubKey().getToAddress(pocket.getCoinType()));
       }
     } catch (final ScriptException x) {
       /* ignore this output */
     }
   }
   return addresses;
 }
  public static boolean isInternal(@Nonnull final Transaction tx) {
    if (tx.isCoinBase()) return false;

    final List<TransactionOutput> outputs = tx.getOutputs();
    if (outputs.size() != 1) return false;

    try {
      final TransactionOutput output = outputs.get(0);
      final Script scriptPubKey = output.getScriptPubKey();
      if (!scriptPubKey.isSentToRawPubKey()) return false;

      return true;
    } catch (final ScriptException x) {
      return false;
    }
  }
Пример #4
0
  private void tryOpenDispute(boolean isSupportTicket) {
    if (trade != null) {
      Transaction depositTx = trade.getDepositTx();
      if (depositTx != null) {
        doOpenDispute(isSupportTicket, trade.getDepositTx());
      } else {
        log.warn("Trade.depositTx is null. We try to find the tx in our wallet.");
        List<Transaction> candidates = new ArrayList<>();
        List<Transaction> transactions = walletService.getWallet().getRecentTransactions(100, true);
        transactions
            .stream()
            .forEach(
                transaction -> {
                  Coin valueSentFromMe = transaction.getValueSentFromMe(walletService.getWallet());
                  if (!valueSentFromMe.isZero()) {
                    // spending tx
                    for (TransactionOutput transactionOutput : transaction.getOutputs()) {
                      if (!transactionOutput.isMine(walletService.getWallet())) {
                        if (transactionOutput.getScriptPubKey().isPayToScriptHash()) {
                          // MS tx
                          candidates.add(transaction);
                        }
                      }
                    }
                  }
                });

        if (candidates.size() == 1) doOpenDispute(isSupportTicket, candidates.get(0));
        else if (candidates.size() > 1)
          new SelectDepositTxPopup()
              .transactions(candidates)
              .onSelect(
                  transaction -> {
                    doOpenDispute(isSupportTicket, transaction);
                  })
              .closeButtonText("Cancel")
              .show();
        else log.error("Trade.depositTx is null and we did not find any MultiSig transaction.");
      }
    } else {
      log.error("Trade is null");
    }
  }