Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<Payment> getPayments(String address) {
- List<Payment> payments = new ArrayList<>();
- try {
- long lastBlockHeight = blockExplorer.getLatestBlock().getHeight();
- Address addressResponse = blockExplorer.getAddress(address);
- List<info.blockchain.api.blockexplorer.entity.Transaction> transactions = addressResponse.getTransactions();
- if (transactions == null) {
- return payments;
- }
- for (info.blockchain.api.blockexplorer.entity.Transaction transaction : transactions) {
- String txId = transaction.getHash();
- long txBlockHeight = transaction.getBlockHeight();
- for (Output output : transaction.getOutputs()) {
- if (output.getAddress().equals(address)) {
- Date txTime = Date.from(Instant.ofEpochSecond(transaction.getTime()));
- BigDecimal btcAmount = satoshiToBtc(output.getValue());
- long confirmations = txBlockHeight > 0 ? (lastBlockHeight - (txBlockHeight - 1L)) : 0;
- Payment payment = new Payment();
- payment.setId(txId);
- payment.setTime(txTime);
- payment.setAmount(btcAmount);
- payment.setStatus(confirmations >= MIN_CONFIRMATIONS ? Payment.Status.COMPLETED : Payment.Status.PENDING);
- payments.add(payment);
- }
- }
- }
- } catch (Exception e) {
- log.error("An error occurred", e);
- }
- return payments;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement