fix(hardcoded): extract hardcoded node aliases to "hardcoded" module (and make it configurable)

This commit is contained in:
danielbroll
2022-04-21 16:20:16 +02:00
committed by Carsten Otto
parent 96e21ae89b
commit c396bc351d
4 changed files with 23 additions and 8 deletions

View File

@@ -2,6 +2,7 @@ package de.cotto.lndmanagej.hardcoded;
import com.google.common.base.Splitter;
import de.cotto.lndmanagej.model.ChannelId;
import de.cotto.lndmanagej.model.Pubkey;
import de.cotto.lndmanagej.model.Resolution;
import de.cotto.lndmanagej.model.TransactionHash;
import org.springframework.stereotype.Component;
@@ -19,6 +20,7 @@ public class HardcodedService {
private static final int EXPECTED_NUMBER_OF_COMPONENTS = 3;
private static final String RESOLUTIONS_SECTION = "resolutions";
private static final Splitter SPLITTER = Splitter.on(":");
private static final String ALIASES_SECTION = "aliases";
private final IniFileReader iniFileReader;
@@ -26,6 +28,12 @@ public class HardcodedService {
this.iniFileReader = iniFileReader;
}
public String getAliasOrDefault(Pubkey pubkey, String defaultAlias) {
Map<String, Set<String>> values = iniFileReader.getValues(ALIASES_SECTION);
Set<String> alias = values.getOrDefault(pubkey.toString(), Set.of());
return alias.stream().findFirst().orElse(defaultAlias);
}
public Set<Resolution> getResolutions(ChannelId channelId) {
Map<String, Set<String>> values = iniFileReader.getValues(RESOLUTIONS_SECTION);
Set<String> forShortChannelId = values.getOrDefault(String.valueOf(channelId.getShortChannelId()), Set.of());