mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 02:12:00 +01:00
VoteItemsList added, paymentaccount debugging
This commit is contained in:
parent
ab19521b6f
commit
cea1c0c778
@ -770,6 +770,7 @@ message DiskEnvelope {
|
||||
PersistedEntryMap persisted_entry_map = 9;
|
||||
LongPersistable bloom_filter_nonce = 10;
|
||||
TradeStatisticsList trade_statistics_list = 12;
|
||||
VoteItemsList vote_items_list = 13;
|
||||
}
|
||||
}
|
||||
|
||||
@ -789,7 +790,6 @@ message TradeStatisticsList {
|
||||
repeated TradeStatistics trade_statistics = 1;
|
||||
}
|
||||
|
||||
|
||||
message PersistedEntryMap {
|
||||
map<string, ProtectedStorageEntry> persisted_entry_map = 1;
|
||||
}
|
||||
@ -1146,7 +1146,7 @@ message VoteItem {
|
||||
string name = 2;
|
||||
int64 default_value = 3;
|
||||
bool has_voted = 4;
|
||||
bytes value = 5;
|
||||
uint32 value = 5; // https://stackoverflow.com/questions/17594881/store-a-single-byte-in-a-protobuf-message
|
||||
}
|
||||
|
||||
message VoteItemsList {
|
||||
|
@ -19,19 +19,22 @@ package io.bisq.core.dao.vote;
|
||||
|
||||
import io.bisq.common.app.Version;
|
||||
import io.bisq.common.persistence.Persistable;
|
||||
import io.bisq.generated.protobuffer.PB;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
//TODO if sent over wire make final
|
||||
@Slf4j
|
||||
public class VoteItem implements Persistable {
|
||||
// That object is saved to disc. We need to take care of changes to not break deserialization.
|
||||
private static final long serialVersionUID = Version.LOCAL_DB_VERSION;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(VoteItem.class);
|
||||
// public final String version;
|
||||
public final VotingType votingType;
|
||||
@Nullable
|
||||
@ -86,4 +89,22 @@ public class VoteItem implements Persistable {
|
||||
", value=" + value +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public PB.VoteItem toProto() {
|
||||
PB.VoteItem.Builder builder = PB.VoteItem.newBuilder()
|
||||
.setVotingType(PB.VoteItem.VotingType.valueOf(votingType.name()))
|
||||
.setDefaultValue(defaultValue)
|
||||
.setHasVoted(hasVoted)
|
||||
.setValue(value);
|
||||
Optional.ofNullable(name).ifPresent(builder::setName);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static VoteItem fromProto(PB.VoteItem voteItem) {
|
||||
VotingDefaultValues defaultValues = new VotingDefaultValues();
|
||||
VotingType votingType = VotingType.valueOf(voteItem.getVotingType().name());
|
||||
defaultValues.setValueByVotingType(votingType, voteItem.getValue());
|
||||
return new VoteItem(votingType, voteItem.getName(), (byte) voteItem.getValue(), defaultValues);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.inject.Inject;
|
||||
import io.bisq.common.app.Version;
|
||||
import io.bisq.common.persistence.ListPersistable;
|
||||
import io.bisq.common.proto.ProtoHelper;
|
||||
import io.bisq.common.storage.Storage;
|
||||
import io.bisq.common.util.Utilities;
|
||||
import io.bisq.core.btc.wallet.BsqWalletService;
|
||||
@ -30,6 +31,7 @@ import io.bisq.core.dao.compensation.CompensationRequest;
|
||||
import io.bisq.core.dao.compensation.CompensationRequestManager;
|
||||
import io.bisq.core.dao.compensation.CompensationRequestPayload;
|
||||
import io.bisq.core.provider.fee.FeeService;
|
||||
import io.bisq.generated.protobuffer.PB;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bitcoinj.core.Utils;
|
||||
import org.slf4j.Logger;
|
||||
@ -309,7 +311,11 @@ public class VotingManager {
|
||||
//TODO check equals code
|
||||
if (!voteItemsLists.contains(voteItemsList)) {
|
||||
voteItemsLists.add(voteItemsList);
|
||||
voteItemCollectionsStorage.queueUpForSave(new ListPersistable<>(voteItemsLists), 500);
|
||||
ListPersistable<VoteItemsList> serializable = new ListPersistable<>(voteItemsLists);
|
||||
serializable.setToProto((list) -> PB.DiskEnvelope.newBuilder()
|
||||
.setVoteItemsList(PB.VoteItemsList.newBuilder()
|
||||
.addAllVoteItem(ProtoHelper.collectionToProto(voteItemsList.getAllVoteItemList()))).build());
|
||||
voteItemCollectionsStorage.queueUpForSave(serializable, 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,15 +57,15 @@ public final class OKPayAccountPayload extends PaymentAccountPayload {
|
||||
|
||||
@Override
|
||||
public PB.PaymentAccountPayload toProto() {
|
||||
PB.OKPayAccountPayload.Builder builder = PB.OKPayAccountPayload.newBuilder();
|
||||
PB.OKPayAccountPayload.Builder thisClass =
|
||||
builder.setAccountNr(accountNr);
|
||||
PB.OKPayAccountPayload.Builder builder = PB.OKPayAccountPayload.newBuilder()
|
||||
.setAccountNr(accountNr);
|
||||
|
||||
PB.PaymentAccountPayload.Builder paymentAccountPayload =
|
||||
PB.PaymentAccountPayload.newBuilder()
|
||||
.setId(id)
|
||||
.setPaymentMethodId(paymentMethodId)
|
||||
.setMaxTradePeriod(maxTradePeriod)
|
||||
.setOKPayAccountPayload(thisClass);
|
||||
.setOKPayAccountPayload(builder);
|
||||
return paymentAccountPayload.build();
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ https://developers.google.com/protocol-buffers/docs/proto3#default
|
||||
|
||||
For Java -> Protobuffer, you should extract the name from the Java enum:
|
||||
|
||||
.setContext(Messages.AddressEntry.Context.valueOf(context.name()))
|
||||
.setContext(PB.AddressEntry.Context.valueOf(context.name()))
|
||||
|
||||
For Protobuffer -> Java, do the opposite:
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package io.bisq.network.p2p.storage;
|
||||
|
||||
import io.bisq.common.persistence.HashMapPersistable;
|
||||
import io.bisq.common.persistence.Persistable;
|
||||
import io.bisq.generated.protobuffer.PB;
|
||||
import lombok.Getter;
|
||||
@ -26,10 +25,18 @@ import lombok.experimental.Delegate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* This class was not generalized to HashMapPersistable (like we did with #ListPersistable) because
|
||||
* in protobuffer the map construct can't be anything, so the straightforward mapping was not possible.
|
||||
* Hence this Persistable class.
|
||||
*/
|
||||
public class SequenceNumberMap implements Persistable {
|
||||
@Delegate
|
||||
@Delegate(excludes = ExcludeFromDelegate.class)
|
||||
@Getter
|
||||
@Setter
|
||||
private HashMap<P2PDataStorage.ByteArray, P2PDataStorage.MapValue> hashMap = new HashMap<>();
|
||||
@ -64,4 +71,11 @@ public class SequenceNumberMap implements Persistable {
|
||||
}
|
||||
return new SequenceNumberMap(result);
|
||||
}
|
||||
|
||||
// avoid warnings in IDE, because of type erasure intellij thinks there are duplicate methods generated by lombok delegate
|
||||
private interface ExcludeFromDelegate<K,V> {
|
||||
public void forEach(BiConsumer<? super P2PDataStorage.ByteArray, ? super P2PDataStorage.MapValue> action);
|
||||
public void putAll(Map<? extends P2PDataStorage.ByteArray, ? extends P2PDataStorage.MapValue> all);
|
||||
public void replaceAll(BiFunction<? super P2PDataStorage.ByteArray, ? super P2PDataStorage.MapValue, ? extends P2PDataStorage.MapValue> all);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user