Advertisement
Guest User

Untitled

a guest
Oct 30th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. public List<Payment> getPayments(String address) {
  2.         List<Payment> payments = new ArrayList<>();
  3.         try {
  4.             long lastBlockHeight = blockExplorer.getLatestBlock().getHeight();
  5.             Address addressResponse = blockExplorer.getAddress(address);
  6.             List<info.blockchain.api.blockexplorer.entity.Transaction> transactions = addressResponse.getTransactions();
  7.             if (transactions == null) {
  8.                 return payments;
  9.             }
  10.             for (info.blockchain.api.blockexplorer.entity.Transaction transaction : transactions) {
  11.                 String txId = transaction.getHash();
  12.                 long txBlockHeight = transaction.getBlockHeight();
  13.                 for (Output output : transaction.getOutputs()) {
  14.                     if (output.getAddress().equals(address)) {
  15.                         Date txTime = Date.from(Instant.ofEpochSecond(transaction.getTime()));
  16.                         BigDecimal btcAmount = satoshiToBtc(output.getValue());
  17.                         long confirmations = txBlockHeight > 0 ? (lastBlockHeight - (txBlockHeight - 1L)) : 0;
  18.                         Payment payment = new Payment();
  19.                         payment.setId(txId);
  20.                         payment.setTime(txTime);
  21.                         payment.setAmount(btcAmount);
  22.                         payment.setStatus(confirmations >= MIN_CONFIRMATIONS ? Payment.Status.COMPLETED : Payment.Status.PENDING);
  23.                         payments.add(payment);
  24.                     }
  25.                 }
  26.             }
  27.         } catch (Exception e) {
  28.             log.error("An error occurred", e);
  29.         }
  30.         return payments;
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement