Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Performance improvement on determining if transaction was internal (#373
Browse files Browse the repository at this point in the history
)
  • Loading branch information
michaelWuensch authored Oct 3, 2021
1 parent 23f578e commit 0ecfb1d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/src/main/java/zapsolutions/zap/util/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,12 @@ public boolean isInvoiceExpired(Invoice invoice) {
*/
public boolean isTransactionInternal(Transaction transaction) {

// This is faster especially for nodes with lots of channels
if (hasInternalTransactionLabel(transaction)) {
return true;
}

// ToDo: looping through all channels can be removed later. But this is still necessary for Nodes that run since LND versions prior to LND 0.11
// open channels
if (mOpenChannelsList != null) {
for (Channel c : mOpenChannelsList) {
Expand Down Expand Up @@ -1115,6 +1121,25 @@ public boolean isTransactionInternal(Transaction transaction) {
return false;
}

/**
* This function determines if according to the label this is a internal transaction.
* The labelTypes are derived from: https://github.com/lightningnetwork/lnd/blob/master/labels/labels.go
*
* @param transaction
* @return
*/
public boolean hasInternalTransactionLabel(Transaction transaction) {
String[] labelType = {":openchannel", ":closechannel", ":justicetx", ":sweep"};
if (transaction.getLabel() != null && !transaction.getLabel().isEmpty()) {
for (String label : labelType) {
if (transaction.getLabel().toLowerCase().contains(label)) {
return true;
}
}
}
return false;
}

/**
* This functions helps us to link on-chain channel transaction with the corresponding channel's public node alias.
*
Expand Down

0 comments on commit 0ecfb1d

Please sign in to comment.