add payment labels to transaction tabs for received outputs where available from open wallets

This commit is contained in:
Craig Raw 2024-01-17 14:43:24 +02:00
parent c8a5c1fb86
commit 14689dd256

View file

@ -54,6 +54,7 @@ import tornadofx.control.Fieldset;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import tornadofx.control.Form; import tornadofx.control.Form;
import javax.swing.text.html.Option;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -674,7 +675,8 @@ public class HeadersController extends TransactionFormController implements Init
List<Payment> payments = new ArrayList<>(); List<Payment> payments = new ArrayList<>();
for(TransactionOutput txOutput : headersForm.getTransaction().getOutputs()) { for(TransactionOutput txOutput : headersForm.getTransaction().getOutputs()) {
try { try {
payments.add(new Payment(txOutput.getScript().getToAddresses()[0], null, txOutput.getValue(), false)); BlockTransactionHashIndex receivedTxo = getBlockTransactionOutput(txOutput);
payments.add(new Payment(txOutput.getScript().getToAddresses()[0], receivedTxo != null ? receivedTxo.getLabel() : null, txOutput.getValue(), false));
} catch(Exception e) { } catch(Exception e) {
//ignore //ignore
} }
@ -708,6 +710,17 @@ public class HeadersController extends TransactionFormController implements Init
return null; return null;
} }
private BlockTransactionHashIndex getBlockTransactionOutput(TransactionOutput txOutput) {
for(Wallet openWallet : AppServices.get().getOpenWallets().keySet()) {
Optional<BlockTransactionHashIndex> output = openWallet.getWalletTxos().keySet().stream().filter(ref -> ref.getHash().equals(txOutput.getHash()) && ref.getIndex() == txOutput.getIndex()).findFirst();
if(output.isPresent()) {
return output.get();
}
}
return null;
}
private void updateBlockchainForm(BlockTransaction blockTransaction, Integer currentHeight) { private void updateBlockchainForm(BlockTransaction blockTransaction, Integer currentHeight) {
signaturesForm.setVisible(false); signaturesForm.setVisible(false);
blockchainForm.setVisible(true); blockchainForm.setVisible(true);