Reapply original code from @jmacxx in AddressEntryList

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2023-05-13 22:45:39 +07:00
parent b11511e037
commit 4262e91f1f
No known key found for this signature in database
GPG Key ID: 02AA2BAE387C8307

View File

@ -209,11 +209,26 @@ public final class AddressEntryList implements PersistableEnvelope, PersistedDat
} }
log.info("swapToAvailable addressEntry to swap={}", addressEntry); log.info("swapToAvailable addressEntry to swap={}", addressEntry);
boolean setChangedByRemove = entrySet.remove(addressEntry); if (entrySet.remove(addressEntry)) {
boolean setChangedByAdd = entrySet.add(new AddressEntry(addressEntry.getKeyPair(), requestPersistence();
}
// If we have an address entry which shared the address with another one (shared maker fee offers use case)
// then we do not swap to available as we need to protect the address of the remaining entry.
boolean entryWithSameContextStillExists = entrySet.stream().anyMatch(entry -> {
if (addressEntry.getAddressString() != null) {
return addressEntry.getAddressString().equals(entry.getAddressString()) &&
addressEntry.getContext() == entry.getContext();
}
return false;
});
if (entryWithSameContextStillExists) {
return;
}
// no other uses of the address context remain, so make it available
if (entrySet.add(
new AddressEntry(addressEntry.getKeyPair(),
AddressEntry.Context.AVAILABLE, AddressEntry.Context.AVAILABLE,
addressEntry.isSegwit())); addressEntry.isSegwit()))) {
if (setChangedByRemove || setChangedByAdd) {
requestPersistence(); requestPersistence();
} }
} }