Update AccountAgeWitnessStorage classes

This commit is contained in:
chimp1984 2020-10-01 17:40:38 -05:00
parent d9a7aacf98
commit 8781c80fb0
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3
2 changed files with 11 additions and 21 deletions

View File

@ -22,10 +22,10 @@ import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
import bisq.network.p2p.storage.persistence.MapStoreService;
import bisq.common.config.Config;
import bisq.common.storage.Storage;
import bisq.common.persistence.PersistenceManager;
import javax.inject.Named;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.File;
@ -33,8 +33,6 @@ import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import static com.google.common.base.Preconditions.checkArgument;
@Slf4j
public class AccountAgeWitnessStorageService extends MapStoreService<AccountAgeWitnessStore, PersistableNetworkPayload> {
private static final String FILE_NAME = "AccountAgeWitnessStore";
@ -46,14 +44,19 @@ public class AccountAgeWitnessStorageService extends MapStoreService<AccountAgeW
@Inject
public AccountAgeWitnessStorageService(@Named(Config.STORAGE_DIR) File storageDir,
Storage<AccountAgeWitnessStore> persistableNetworkPayloadMapStorage) {
super(storageDir, persistableNetworkPayloadMapStorage);
PersistenceManager<AccountAgeWitnessStore> persistenceManager) {
super(storageDir, persistenceManager);
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected void initializePersistenceManager() {
persistenceManager.initialize(store, PersistenceManager.Priority.LOW);
}
@Override
public String getFileName() {
return FILE_NAME;
@ -78,12 +81,4 @@ public class AccountAgeWitnessStorageService extends MapStoreService<AccountAgeW
protected AccountAgeWitnessStore createStore() {
return new AccountAgeWitnessStore();
}
@Override
protected void readStore() {
super.readStore();
checkArgument(store instanceof AccountAgeWitnessStore,
"Store is not instance of AccountAgeWitnessStore. That can happen if the ProtoBuffer " +
"file got changed. We cleared the data store and recreated it again.");
}
}

View File

@ -17,7 +17,6 @@
package bisq.core.account.witness;
import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.persistence.PersistableNetworkPayloadStore;
import com.google.protobuf.Message;
@ -34,7 +33,7 @@ import lombok.extern.slf4j.Slf4j;
* definition and provide a hashMap for the domain access.
*/
@Slf4j
public class AccountAgeWitnessStore extends PersistableNetworkPayloadStore {
public class AccountAgeWitnessStore extends PersistableNetworkPayloadStore<AccountAgeWitness> {
AccountAgeWitnessStore() {
}
@ -45,7 +44,7 @@ public class AccountAgeWitnessStore extends PersistableNetworkPayloadStore {
///////////////////////////////////////////////////////////////////////////////////////////
private AccountAgeWitnessStore(List<AccountAgeWitness> list) {
list.forEach(item -> map.put(new P2PDataStorage.ByteArray(item.getHash()), item));
super(list);
}
public Message toProtoMessage() {
@ -67,8 +66,4 @@ public class AccountAgeWitnessStore extends PersistableNetworkPayloadStore {
.map(AccountAgeWitness::fromProto).collect(Collectors.toList());
return new AccountAgeWitnessStore(list);
}
public boolean containsKey(P2PDataStorage.ByteArray hash) {
return map.containsKey(hash);
}
}