mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Merge pull request #4102 from stejbac/tidy-persistable-envelope-inheritance
Tidy PersistableEnvelope inheritance
This commit is contained in:
commit
91ce44ad96
@ -18,11 +18,10 @@
|
||||
package bisq.common.proto;
|
||||
|
||||
import bisq.common.Payload;
|
||||
import bisq.common.proto.persistable.PersistableEnvelope;
|
||||
|
||||
import bisq.common.proto.persistable.PersistablePayload;
|
||||
|
||||
public interface ProtoResolver {
|
||||
Payload fromProto(protobuf.PaymentAccountPayload proto);
|
||||
|
||||
PersistableEnvelope fromProto(protobuf.PersistableNetworkPayload proto);
|
||||
PersistablePayload fromProto(protobuf.PersistableNetworkPayload proto);
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.common.proto.persistable;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
public class PersistableHashMap<K, V extends PersistablePayload> implements PersistableEnvelope {
|
||||
@Delegate
|
||||
@Getter
|
||||
private Map<K, V> map = new HashMap<>();
|
||||
@Setter
|
||||
private Function<Map<K, V>, Message> toProto;
|
||||
|
||||
public PersistableHashMap(Map<K, V> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public PersistableHashMap(Map<K, V> map, Function<Map<K, V>, Message> toProto) {
|
||||
this(map);
|
||||
this.toProto = toProto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message toProtoMessage() {
|
||||
return toProto.apply(map);
|
||||
}
|
||||
}
|
@ -17,12 +17,8 @@
|
||||
|
||||
package bisq.common.proto.persistable;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -31,13 +27,11 @@ import lombok.Setter;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class PersistableList<T extends PersistablePayload> implements PersistableEnvelope, Iterable<T> {
|
||||
public abstract class PersistableList<T extends PersistablePayload> implements PersistableEnvelope, Iterable<T> {
|
||||
@Delegate(excludes = ExcludesDelegateMethods.class)
|
||||
@Getter
|
||||
@Setter
|
||||
private List<T> list;
|
||||
@Setter
|
||||
private Function<List<T>, Message> toProto;
|
||||
|
||||
public PersistableList() {
|
||||
list = new ArrayList<>();
|
||||
@ -47,30 +41,11 @@ public class PersistableList<T extends PersistablePayload> implements Persistabl
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public PersistableList(List<T> list, Function<List<T>, Message> toProto) {
|
||||
this(list);
|
||||
this.toProto = toProto;
|
||||
}
|
||||
|
||||
public PersistableList(HashSet<T> set) {
|
||||
this(new ArrayList<>(set));
|
||||
}
|
||||
|
||||
public PersistableList(HashSet<T> set, Function<List<T>, Message> toProto) {
|
||||
this(set);
|
||||
this.toProto = toProto;
|
||||
}
|
||||
|
||||
// this.stream() does not compile for unknown reasons, so add that manual delegate method
|
||||
public Stream<T> stream() {
|
||||
return list.stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message toProtoMessage() {
|
||||
return toProto.apply(list);
|
||||
}
|
||||
|
||||
private interface ExcludesDelegateMethods<T> {
|
||||
Stream<T> stream();
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package bisq.common.proto.persistable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UserThreadMappedPersistableList<T extends PersistablePayload> extends PersistableList<T>
|
||||
public abstract class UserThreadMappedPersistableList<T extends PersistablePayload> extends PersistableList<T>
|
||||
implements UserThreadMappedPersistableEnvelope {
|
||||
|
||||
public UserThreadMappedPersistableList(List<T> list) {
|
||||
|
@ -27,7 +27,6 @@ import bisq.common.app.Capabilities;
|
||||
import bisq.common.app.Capability;
|
||||
import bisq.common.crypto.Hash;
|
||||
import bisq.common.proto.ProtoUtil;
|
||||
import bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import bisq.common.util.Utilities;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
@ -45,7 +44,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
// Supports signatures made from EC key (arbitrators) and signature created with DSA key.
|
||||
@Slf4j
|
||||
@Value
|
||||
public class SignedWitness implements ProcessOncePersistableNetworkPayload, PersistableNetworkPayload, PersistableEnvelope,
|
||||
public class SignedWitness implements ProcessOncePersistableNetworkPayload, PersistableNetworkPayload,
|
||||
DateTolerantPayload, CapabilityRequiringPayload {
|
||||
|
||||
public enum VerificationMethod {
|
||||
|
@ -22,7 +22,6 @@ import bisq.network.p2p.storage.payload.DateTolerantPayload;
|
||||
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
|
||||
import bisq.network.p2p.storage.payload.ProcessOncePersistableNetworkPayload;
|
||||
|
||||
import bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import bisq.common.util.Utilities;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
@ -40,7 +39,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
// so only the newly added objects since the last release will be retrieved over the P2P network.
|
||||
@Slf4j
|
||||
@Value
|
||||
public class AccountAgeWitness implements ProcessOncePersistableNetworkPayload, PersistableNetworkPayload, PersistableEnvelope, DateTolerantPayload {
|
||||
public class AccountAgeWitness implements ProcessOncePersistableNetworkPayload, PersistableNetworkPayload, DateTolerantPayload {
|
||||
private static final long TOLERANCE = TimeUnit.DAYS.toMillis(1);
|
||||
|
||||
private final byte[] hash; // Ripemd160(Sha256(concatenated accountHash, signature and sigPubKey)); 20 bytes
|
||||
|
@ -19,7 +19,7 @@ package bisq.core.dao.governance.blindvote;
|
||||
|
||||
import bisq.core.dao.governance.ConsensusCritical;
|
||||
|
||||
import bisq.common.proto.persistable.PersistableList;
|
||||
import bisq.common.Proto;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
@ -27,23 +27,18 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* We don't persist that list but use it only for encoding the VoteWithProposalTxId list
|
||||
* to PB bytes in the blindVote. The bytes get encrypted and later decrypted. To use a ByteOutputStream
|
||||
* and add all list elements would work for encryption but for decrypting we don't know the length of a list entry
|
||||
* and it would make the process complicate (e.g. require a custom serialisation format).
|
||||
* We encode the VoteWithProposalTxId list to PB bytes in the blindVote. The bytes get encrypted and later decrypted.
|
||||
* To use a ByteOutputStream and add all list elements would work for encryption but for decrypting we don't know the
|
||||
* length of a list entry and it would make the process complicated (e.g. require a custom serialisation format).
|
||||
*/
|
||||
@Slf4j
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class VoteWithProposalTxIdList extends PersistableList<VoteWithProposalTxId> implements ConsensusCritical {
|
||||
|
||||
VoteWithProposalTxIdList(List<VoteWithProposalTxId> list) {
|
||||
super(list);
|
||||
}
|
||||
|
||||
@Value
|
||||
public class VoteWithProposalTxIdList implements Proto, ConsensusCritical {
|
||||
private final List<VoteWithProposalTxId> list;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
|
@ -23,7 +23,6 @@ import bisq.core.dao.governance.blindvote.BlindVote;
|
||||
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
|
||||
|
||||
import bisq.common.crypto.Hash;
|
||||
import bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import bisq.common.util.Utilities;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
@ -43,7 +42,7 @@ import javax.annotation.concurrent.Immutable;
|
||||
@Slf4j
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
public final class BlindVotePayload implements PersistableNetworkPayload, PersistableEnvelope, ConsensusCritical {
|
||||
public final class BlindVotePayload implements PersistableNetworkPayload, ConsensusCritical {
|
||||
|
||||
private final BlindVote blindVote;
|
||||
protected final byte[] hash; // 20 byte
|
||||
|
@ -23,7 +23,6 @@ import bisq.core.dao.state.model.governance.Proposal;
|
||||
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
|
||||
|
||||
import bisq.common.crypto.Hash;
|
||||
import bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import bisq.common.util.Utilities;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
@ -40,7 +39,7 @@ import javax.annotation.concurrent.Immutable;
|
||||
@Immutable
|
||||
@Slf4j
|
||||
@Value
|
||||
public class ProposalPayload implements PersistableNetworkPayload, PersistableEnvelope, ConsensusCritical {
|
||||
public class ProposalPayload implements PersistableNetworkPayload, ConsensusCritical {
|
||||
private final Proposal proposal;
|
||||
protected final byte[] hash; // 20 byte
|
||||
|
||||
|
@ -362,7 +362,7 @@ public class VoteResultService implements DaoStateListener, DaoSetupService {
|
||||
|
||||
// We convert the list to a map with proposalTxId as key and the vote as value. As the vote can be null we
|
||||
// wrap it into an optional.
|
||||
Map<String, Optional<Vote>> voteByTxIdMap = voteWithProposalTxIdList.stream()
|
||||
Map<String, Optional<Vote>> voteByTxIdMap = voteWithProposalTxIdList.getList().stream()
|
||||
.collect(Collectors.toMap(VoteWithProposalTxId::getProposalTxId, e -> Optional.ofNullable(e.getVote())));
|
||||
|
||||
// We make a map with proposalTxId as key and the ballot as value out of our stored ballot list.
|
||||
@ -414,11 +414,11 @@ public class VoteResultService implements DaoStateListener, DaoSetupService {
|
||||
// If we received a proposal after we had already voted we consider it as a proposal withhold attack and
|
||||
// treat the proposal as it was voted with a rejected vote.
|
||||
ballotByTxIdMap.entrySet().stream()
|
||||
.filter(e -> !voteByTxIdMap.keySet().contains(e.getKey()))
|
||||
.filter(e -> !voteByTxIdMap.containsKey(e.getKey()))
|
||||
.map(Map.Entry::getValue)
|
||||
.forEach(ballot -> {
|
||||
log.warn("We have a proposal which was not part of our blind vote and reject it. " +
|
||||
"Proposal ={}" + ballot.getProposal());
|
||||
"Proposal={}", ballot.getProposal());
|
||||
ballots.add(new Ballot(ballot.getProposal(), new Vote(false)));
|
||||
});
|
||||
|
||||
@ -776,7 +776,7 @@ public class VoteResultService implements DaoStateListener, DaoSetupService {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Value
|
||||
public class HashWithStake {
|
||||
public static class HashWithStake {
|
||||
private final byte[] hash;
|
||||
private final long stake;
|
||||
|
||||
|
@ -20,7 +20,7 @@ package bisq.core.dao.state.model.governance;
|
||||
import bisq.core.dao.governance.ConsensusCritical;
|
||||
import bisq.core.dao.state.model.ImmutableDaoStateModel;
|
||||
|
||||
import bisq.common.proto.persistable.PersistableList;
|
||||
import bisq.common.Proto;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
@ -28,20 +28,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
// We don't persist that list but use it only for encoding the MeritList list
|
||||
// to PB bytes in the blindVote.
|
||||
@Immutable
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MeritList extends PersistableList<Merit> implements ConsensusCritical, ImmutableDaoStateModel {
|
||||
|
||||
public MeritList(List<Merit> list) {
|
||||
super(list);
|
||||
}
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class MeritList implements Proto, ConsensusCritical, ImmutableDaoStateModel {
|
||||
private final List<Merit> list;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
|
@ -33,7 +33,7 @@ import bisq.core.payment.payload.FasterPaymentsAccountPayload;
|
||||
import bisq.core.payment.payload.HalCashAccountPayload;
|
||||
import bisq.core.payment.payload.InstantCryptoCurrencyPayload;
|
||||
import bisq.core.payment.payload.InteracETransferAccountPayload;
|
||||
import bisq.core.payment.payload.JapanBankAccountPayload;;
|
||||
import bisq.core.payment.payload.JapanBankAccountPayload;
|
||||
import bisq.core.payment.payload.MoneyBeamAccountPayload;
|
||||
import bisq.core.payment.payload.MoneyGramAccountPayload;
|
||||
import bisq.core.payment.payload.NationalBankAccountPayload;
|
||||
@ -57,7 +57,7 @@ import bisq.core.trade.statistics.TradeStatistics2;
|
||||
|
||||
import bisq.common.proto.ProtoResolver;
|
||||
import bisq.common.proto.ProtobufferRuntimeException;
|
||||
import bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import bisq.common.proto.persistable.PersistablePayload;
|
||||
|
||||
import java.time.Clock;
|
||||
|
||||
@ -165,7 +165,7 @@ public class CoreProtoResolver implements ProtoResolver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistableEnvelope fromProto(protobuf.PersistableNetworkPayload proto) {
|
||||
public PersistablePayload fromProto(protobuf.PersistableNetworkPayload proto) {
|
||||
if (proto != null) {
|
||||
switch (proto.getMessageCase()) {
|
||||
case ACCOUNT_AGE_WITNESS:
|
||||
|
@ -31,7 +31,6 @@ import bisq.core.dao.governance.proposal.storage.appendonly.ProposalStore;
|
||||
import bisq.core.dao.governance.proposal.storage.temp.TempProposalStore;
|
||||
import bisq.core.dao.state.DaoStateStore;
|
||||
import bisq.core.dao.state.model.governance.BallotList;
|
||||
import bisq.core.dao.state.model.governance.MeritList;
|
||||
import bisq.core.dao.state.unconfirmed.UnconfirmedBsqChangeOutputList;
|
||||
import bisq.core.payment.PaymentAccountList;
|
||||
import bisq.core.proto.CoreProtoResolver;
|
||||
@ -144,8 +143,6 @@ public class CorePersistenceProtoResolver extends CoreProtoResolver implements P
|
||||
return MyVoteList.fromProto(proto.getMyVoteList());
|
||||
case MY_BLIND_VOTE_LIST:
|
||||
return MyBlindVoteList.fromProto(proto.getMyBlindVoteList());
|
||||
case MERIT_LIST:
|
||||
return MeritList.fromProto(proto.getMeritList());
|
||||
case DAO_STATE_STORE:
|
||||
return DaoStateStore.fromProto(proto.getDaoStateStore());
|
||||
case MY_REPUTATION_LIST:
|
||||
|
@ -32,7 +32,6 @@ import bisq.common.app.Capabilities;
|
||||
import bisq.common.app.Capability;
|
||||
import bisq.common.crypto.Hash;
|
||||
import bisq.common.proto.ProtoUtil;
|
||||
import bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import bisq.common.util.CollectionUtils;
|
||||
import bisq.common.util.ExtraDataMapValidator;
|
||||
import bisq.common.util.JsonExclude;
|
||||
@ -65,7 +64,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@Slf4j
|
||||
@Value
|
||||
public final class TradeStatistics2 implements ProcessOncePersistableNetworkPayload, PersistableNetworkPayload, PersistableEnvelope, CapabilityRequiringPayload, Comparable<TradeStatistics2> {
|
||||
public final class TradeStatistics2 implements ProcessOncePersistableNetworkPayload, PersistableNetworkPayload,
|
||||
CapabilityRequiringPayload, Comparable<TradeStatistics2> {
|
||||
|
||||
public static final String MEDIATOR_ADDRESS = "medAddr";
|
||||
public static final String REFUND_AGENT_ADDRESS = "refAddr";
|
||||
|
@ -21,7 +21,7 @@ import bisq.common.Payload;
|
||||
import bisq.common.proto.network.NetworkEnvelope;
|
||||
import bisq.common.proto.network.NetworkPayload;
|
||||
import bisq.common.proto.network.NetworkProtoResolver;
|
||||
import bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import bisq.common.proto.persistable.PersistablePayload;
|
||||
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
@ -168,7 +168,7 @@ public class TestUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistableEnvelope fromProto(protobuf.PersistableNetworkPayload persistable) {
|
||||
public PersistablePayload fromProto(protobuf.PersistableNetworkPayload persistable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -188,7 +188,9 @@ public class TestUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Clock getClock() { return null; }
|
||||
public Clock getClock() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1140,7 +1140,7 @@ message PersistableEnvelope {
|
||||
BallotList ballot_list = 20;
|
||||
MyVoteList my_vote_list = 21;
|
||||
MyBlindVoteList my_blind_vote_list = 22;
|
||||
MeritList merit_list = 23;
|
||||
// MeritList merit_list = 23; // was not used here, but its class used to implement PersistableEnvelope via its super
|
||||
DaoStateStore dao_state_store = 24;
|
||||
MyReputationList my_reputation_list = 25;
|
||||
MyProofOfBurnList my_proof_of_burn_list = 26;
|
||||
|
Loading…
Reference in New Issue
Block a user