diff --git a/common/src/main/java/bisq/common/proto/ProtoResolver.java b/common/src/main/java/bisq/common/proto/ProtoResolver.java index 61244239a11..679c1b3e5a7 100644 --- a/common/src/main/java/bisq/common/proto/ProtoResolver.java +++ b/common/src/main/java/bisq/common/proto/ProtoResolver.java @@ -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); } diff --git a/common/src/main/java/bisq/common/proto/persistable/PersistableHashMap.java b/common/src/main/java/bisq/common/proto/persistable/PersistableHashMap.java deleted file mode 100644 index a5f6cbbf328..00000000000 --- a/common/src/main/java/bisq/common/proto/persistable/PersistableHashMap.java +++ /dev/null @@ -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 . - */ - -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 implements PersistableEnvelope { - @Delegate - @Getter - private Map map = new HashMap<>(); - @Setter - private Function, Message> toProto; - - public PersistableHashMap(Map map) { - this.map = map; - } - - public PersistableHashMap(Map map, Function, Message> toProto) { - this(map); - this.toProto = toProto; - } - - @Override - public Message toProtoMessage() { - return toProto.apply(map); - } -} diff --git a/common/src/main/java/bisq/common/proto/persistable/PersistableList.java b/common/src/main/java/bisq/common/proto/persistable/PersistableList.java index 8c9b26fc5aa..f184a32c296 100644 --- a/common/src/main/java/bisq/common/proto/persistable/PersistableList.java +++ b/common/src/main/java/bisq/common/proto/persistable/PersistableList.java @@ -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.experimental.Delegate; @EqualsAndHashCode -public class PersistableList implements PersistableEnvelope, Iterable { +public abstract class PersistableList implements PersistableEnvelope, Iterable { @Delegate(excludes = ExcludesDelegateMethods.class) @Getter @Setter private List list; - @Setter - private Function, Message> toProto; public PersistableList() { list = new ArrayList<>(); @@ -47,30 +41,11 @@ public PersistableList(List list) { this.list = list; } - public PersistableList(List list, Function, Message> toProto) { - this(list); - this.toProto = toProto; - } - - public PersistableList(HashSet set) { - this(new ArrayList<>(set)); - } - - public PersistableList(HashSet set, Function, Message> toProto) { - this(set); - this.toProto = toProto; - } - // this.stream() does not compile for unknown reasons, so add that manual delegate method public Stream stream() { return list.stream(); } - @Override - public Message toProtoMessage() { - return toProto.apply(list); - } - private interface ExcludesDelegateMethods { Stream stream(); } diff --git a/common/src/main/java/bisq/common/proto/persistable/UserThreadMappedPersistableList.java b/common/src/main/java/bisq/common/proto/persistable/UserThreadMappedPersistableList.java index 5337af5efe1..d9829910b5c 100644 --- a/common/src/main/java/bisq/common/proto/persistable/UserThreadMappedPersistableList.java +++ b/common/src/main/java/bisq/common/proto/persistable/UserThreadMappedPersistableList.java @@ -19,7 +19,7 @@ import java.util.List; -public class UserThreadMappedPersistableList extends PersistableList +public abstract class UserThreadMappedPersistableList extends PersistableList implements UserThreadMappedPersistableEnvelope { public UserThreadMappedPersistableList(List list) { diff --git a/core/src/main/java/bisq/core/account/sign/SignedWitness.java b/core/src/main/java/bisq/core/account/sign/SignedWitness.java index f699b8015e2..975563623a5 100644 --- a/core/src/main/java/bisq/core/account/sign/SignedWitness.java +++ b/core/src/main/java/bisq/core/account/sign/SignedWitness.java @@ -27,7 +27,6 @@ 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 @@ // 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 { diff --git a/core/src/main/java/bisq/core/account/witness/AccountAgeWitness.java b/core/src/main/java/bisq/core/account/witness/AccountAgeWitness.java index 969665d35fe..131567da3f2 100644 --- a/core/src/main/java/bisq/core/account/witness/AccountAgeWitness.java +++ b/core/src/main/java/bisq/core/account/witness/AccountAgeWitness.java @@ -22,7 +22,6 @@ 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 @@ // 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 diff --git a/core/src/main/java/bisq/core/dao/governance/blindvote/VoteWithProposalTxIdList.java b/core/src/main/java/bisq/core/dao/governance/blindvote/VoteWithProposalTxIdList.java index 8759f1574ff..4556e882211 100644 --- a/core/src/main/java/bisq/core/dao/governance/blindvote/VoteWithProposalTxIdList.java +++ b/core/src/main/java/bisq/core/dao/governance/blindvote/VoteWithProposalTxIdList.java @@ -19,7 +19,7 @@ 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.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 implements ConsensusCritical { - - VoteWithProposalTxIdList(List list) { - super(list); - } - +@Value +public class VoteWithProposalTxIdList implements Proto, ConsensusCritical { + private final List list; /////////////////////////////////////////////////////////////////////////////////////////// // PROTO BUFFER diff --git a/core/src/main/java/bisq/core/dao/governance/blindvote/storage/BlindVotePayload.java b/core/src/main/java/bisq/core/dao/governance/blindvote/storage/BlindVotePayload.java index 923bd4e043c..1a077562211 100644 --- a/core/src/main/java/bisq/core/dao/governance/blindvote/storage/BlindVotePayload.java +++ b/core/src/main/java/bisq/core/dao/governance/blindvote/storage/BlindVotePayload.java @@ -23,7 +23,6 @@ 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 @@ @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 diff --git a/core/src/main/java/bisq/core/dao/governance/proposal/storage/appendonly/ProposalPayload.java b/core/src/main/java/bisq/core/dao/governance/proposal/storage/appendonly/ProposalPayload.java index 04a4eaa71f5..33386f82a9e 100644 --- a/core/src/main/java/bisq/core/dao/governance/proposal/storage/appendonly/ProposalPayload.java +++ b/core/src/main/java/bisq/core/dao/governance/proposal/storage/appendonly/ProposalPayload.java @@ -23,7 +23,6 @@ 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 @@ @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 diff --git a/core/src/main/java/bisq/core/dao/governance/voteresult/VoteResultService.java b/core/src/main/java/bisq/core/dao/governance/voteresult/VoteResultService.java index 795e3faeca2..3bbdd0cffb7 100644 --- a/core/src/main/java/bisq/core/dao/governance/voteresult/VoteResultService.java +++ b/core/src/main/java/bisq/core/dao/governance/voteresult/VoteResultService.java @@ -362,7 +362,7 @@ private BallotList createBallotList(VoteWithProposalTxIdList voteWithProposalTxI // 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> voteByTxIdMap = voteWithProposalTxIdList.stream() + Map> 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 @@ private BallotList createBallotList(VoteWithProposalTxIdList voteWithProposalTxI // 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 @@ private boolean isInVoteResultPhase(int chainHeight) { /////////////////////////////////////////////////////////////////////////////////////////// @Value - public class HashWithStake { + public static class HashWithStake { private final byte[] hash; private final long stake; diff --git a/core/src/main/java/bisq/core/dao/state/model/governance/MeritList.java b/core/src/main/java/bisq/core/dao/state/model/governance/MeritList.java index d70507e46fb..334ac988720 100644 --- a/core/src/main/java/bisq/core/dao/state/model/governance/MeritList.java +++ b/core/src/main/java/bisq/core/dao/state/model/governance/MeritList.java @@ -20,7 +20,7 @@ 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.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 implements ConsensusCritical, ImmutableDaoStateModel { - - public MeritList(List list) { - super(list); - } +import lombok.Value; +@Value +public class MeritList implements Proto, ConsensusCritical, ImmutableDaoStateModel { + private final List list; /////////////////////////////////////////////////////////////////////////////////////////// // PROTO BUFFER diff --git a/core/src/main/java/bisq/core/proto/CoreProtoResolver.java b/core/src/main/java/bisq/core/proto/CoreProtoResolver.java index b0ce384192b..999f4e8e5f1 100644 --- a/core/src/main/java/bisq/core/proto/CoreProtoResolver.java +++ b/core/src/main/java/bisq/core/proto/CoreProtoResolver.java @@ -33,7 +33,7 @@ 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.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 PaymentAccountPayload fromProto(protobuf.PaymentAccountPayload proto) { } @Override - public PersistableEnvelope fromProto(protobuf.PersistableNetworkPayload proto) { + public PersistablePayload fromProto(protobuf.PersistableNetworkPayload proto) { if (proto != null) { switch (proto.getMessageCase()) { case ACCOUNT_AGE_WITNESS: diff --git a/core/src/main/java/bisq/core/proto/persistable/CorePersistenceProtoResolver.java b/core/src/main/java/bisq/core/proto/persistable/CorePersistenceProtoResolver.java index 6d4d387ad0a..2e16d005e02 100644 --- a/core/src/main/java/bisq/core/proto/persistable/CorePersistenceProtoResolver.java +++ b/core/src/main/java/bisq/core/proto/persistable/CorePersistenceProtoResolver.java @@ -31,7 +31,6 @@ 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 PersistableEnvelope fromProto(protobuf.PersistableEnvelope proto) { 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: diff --git a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics2.java b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics2.java index 1983ec52be8..bb31911d2bd 100644 --- a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics2.java +++ b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics2.java @@ -32,7 +32,6 @@ 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 @@ @Slf4j @Value -public final class TradeStatistics2 implements ProcessOncePersistableNetworkPayload, PersistableNetworkPayload, PersistableEnvelope, CapabilityRequiringPayload, Comparable { +public final class TradeStatistics2 implements ProcessOncePersistableNetworkPayload, PersistableNetworkPayload, + CapabilityRequiringPayload, Comparable { public static final String MEDIATOR_ADDRESS = "medAddr"; public static final String REFUND_AGENT_ADDRESS = "refAddr"; diff --git a/p2p/src/test/java/bisq/network/p2p/TestUtils.java b/p2p/src/test/java/bisq/network/p2p/TestUtils.java index 87d42b20cd2..3b5f35735e6 100644 --- a/p2p/src/test/java/bisq/network/p2p/TestUtils.java +++ b/p2p/src/test/java/bisq/network/p2p/TestUtils.java @@ -21,7 +21,7 @@ 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 Payload fromProto(protobuf.PaymentAccountPayload proto) { } @Override - public PersistableEnvelope fromProto(protobuf.PersistableNetworkPayload persistable) { + public PersistablePayload fromProto(protobuf.PersistableNetworkPayload persistable) { return null; } @@ -188,7 +188,9 @@ public NetworkPayload fromProto(protobuf.StorageEntryWrapper proto) { } @Override - public Clock getClock() { return null; } + public Clock getClock() { + return null; + } }; } } diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 62bc2003eef..e1cc8b39c4c 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -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;