diff --git a/p2p/src/main/java/bisq/network/p2p/storage/persistence/PersistableNetworkPayloadStore.java b/p2p/src/main/java/bisq/network/p2p/storage/persistence/PersistableNetworkPayloadStore.java index b4c409fdd1..802761a188 100644 --- a/p2p/src/main/java/bisq/network/p2p/storage/persistence/PersistableNetworkPayloadStore.java +++ b/p2p/src/main/java/bisq/network/p2p/storage/persistence/PersistableNetworkPayloadStore.java @@ -22,16 +22,30 @@ import bisq.network.p2p.storage.payload.PersistableNetworkPayload; import bisq.common.proto.persistable.PersistableEnvelope; +import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import lombok.Getter; +import lombok.extern.slf4j.Slf4j; + /** - * Base class for store implementations using a map with a PersistableNetworkPayload - * as the type of the map value. + * Store for PersistableNetworkPayload map entries with it's data hash as key. */ -public abstract class PersistableNetworkPayloadStore implements PersistableEnvelope { +@Slf4j +public abstract class PersistableNetworkPayloadStore implements PersistableEnvelope { @Getter - public Map map = new ConcurrentHashMap<>(); + protected final Map map = new ConcurrentHashMap<>(); + + protected PersistableNetworkPayloadStore() { + } + + protected PersistableNetworkPayloadStore(Collection collection) { + collection.forEach(item -> map.put(new P2PDataStorage.ByteArray(item.getHash()), item)); + } + + public boolean containsKey(P2PDataStorage.ByteArray hash) { + return map.containsKey(hash); + } }