From 6a5060c0c83db7489392ffd31abb29ebc3b11e99 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 15 Jan 2024 17:20:44 +0200 Subject: [PATCH] cormorant: support coinbase transactions --- .../java/com/sparrowwallet/sparrow/control/CoinCell.java | 8 +++++--- .../sparrow/net/cormorant/bitcoind/BitcoindClient.java | 2 +- .../sparrowwallet/sparrow/net/cormorant/index/Store.java | 2 +- .../sparrowwallet/sparrow/wallet/TransactionEntry.java | 4 ++++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/CoinCell.java b/src/main/java/com/sparrowwallet/sparrow/control/CoinCell.java index 250a6bfc..bd563ea5 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/CoinCell.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/CoinCell.java @@ -70,7 +70,7 @@ class CoinCell extends TreeTableCell implements ConfirmationsList setContextMenu(contextMenu); if(entry instanceof TransactionEntry transactionEntry) { - tooltip.showConfirmations(transactionEntry.confirmationsProperty()); + tooltip.showConfirmations(transactionEntry.confirmationsProperty(), transactionEntry.isCoinbase()); if(transactionEntry.isConfirming()) { ConfirmationProgressIndicator arc = new ConfirmationProgressIndicator(transactionEntry.getConfirmations()); @@ -119,6 +119,7 @@ class CoinCell extends TreeTableCell implements ConfirmationsList private static final class CoinTooltip extends Tooltip { private final IntegerProperty confirmationsProperty = new SimpleIntegerProperty(); private boolean showConfirmations; + private boolean isCoinbase; private String value; public void setValue(String value) { @@ -126,8 +127,9 @@ class CoinCell extends TreeTableCell implements ConfirmationsList setTooltipText(); } - public void showConfirmations(IntegerProperty txEntryConfirmationsProperty) { + public void showConfirmations(IntegerProperty txEntryConfirmationsProperty, boolean coinbase) { showConfirmations = true; + isCoinbase = coinbase; int confirmations = txEntryConfirmationsProperty.get(); if(confirmations < BlockTransactionHash.BLOCKS_TO_FULLY_CONFIRM) { @@ -155,7 +157,7 @@ class CoinCell extends TreeTableCell implements ConfirmationsList if(confirmations == 0) { return "Unconfirmed in mempool"; } else if(confirmations < BlockTransactionHash.BLOCKS_TO_FULLY_CONFIRM) { - return confirmations + " confirmation" + (confirmations == 1 ? "" : "s"); + return confirmations + " confirmation" + (confirmations == 1 ? "" : "s") + (isCoinbase ? ", immature coinbase" : ""); } else { return BlockTransactionHash.BLOCKS_TO_FULLY_CONFIRM + "+ confirmations"; } diff --git a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindClient.java b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindClient.java index 0cb57248..73458e22 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindClient.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindClient.java @@ -433,7 +433,7 @@ public class BitcoindClient { } try { - if(listTransaction.category() == Category.receive) { + if(listTransaction.category() == Category.receive || listTransaction.category() == Category.immature || listTransaction.category() == Category.generate) { //Transactions received to an address can be added directly Address address = Address.fromString(listTransaction.address()); String updatedScriptHash = store.addAddressTransaction(address, listTransaction); diff --git a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/index/Store.java b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/index/Store.java index ffb202ad..3f87d0b5 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/index/Store.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/index/Store.java @@ -19,7 +19,7 @@ public class Store { private final Map mempoolEntries = new HashMap<>(); public String addAddressTransaction(Address address, ListTransaction listTransaction) { - if(listTransaction.category() == Category.receive) { + if(listTransaction.category() == Category.receive || listTransaction.category() == Category.immature || listTransaction.category() == Category.generate) { fundingAddresses.put(new HashIndex(Sha256Hash.wrap(listTransaction.txid()), listTransaction.vout()), address); } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java b/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java index badc75f8..c94a0fe3 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java @@ -97,6 +97,10 @@ public class TransactionEntry extends Entry implements Comparable walletTxos) { int validEntries = 0; for(TransactionInput txInput : blockTransaction.getTransaction().getInputs()) {