Skip to content

Commit

Permalink
Add uid to Filter
Browse files Browse the repository at this point in the history
Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
  • Loading branch information
HenrikJannsen authored and alejandrogarcia83 committed Jun 12, 2024
1 parent 1a75e36 commit b0b54d3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
27 changes: 20 additions & 7 deletions core/src/main/java/bisq/core/filter/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ public final class Filter implements ProtectedStoragePayload, ExpirablePayload,
private final List<String> addedBtcNodes;
@ExcludeForHash
private final List<String> addedSeedNodes;
// As we might add more ExcludeForHash we want to ensure to have a unique identifier.
// The hash of the data is not unique anymore if the only change have been at
// the ExcludeForHash annotated fields.
private final String uid;

// After we have created the signature from the filter data we clone it and apply the signature
static Filter cloneWithSig(Filter filter, String signatureAsBase64) {
Expand Down Expand Up @@ -172,7 +176,8 @@ static Filter cloneWithSig(Filter filter, String signatureAsBase64) {
filter.getTakerFeeBsq(),
filter.getDelayedPayoutPaymentAccounts(),
filter.getAddedBtcNodes(),
filter.getAddedSeedNodes());
filter.getAddedSeedNodes(),
filter.getUid());
}

// Used for signature verification as we created the sig without the signatureAsBase64 field we set it to null again
Expand Down Expand Up @@ -214,7 +219,8 @@ static Filter cloneWithoutSig(Filter filter) {
filter.getTakerFeeBsq(),
filter.getDelayedPayoutPaymentAccounts(),
filter.getAddedBtcNodes(),
filter.getAddedSeedNodes());
filter.getAddedSeedNodes(),
filter.getUid());
}

public Filter(List<String> bannedOfferIds,
Expand Down Expand Up @@ -251,7 +257,8 @@ public Filter(List<String> bannedOfferIds,
long takerFeeBsq,
List<PaymentAccountFilter> delayedPayoutPaymentAccounts,
List<String> addedBtcNodes,
List<String> addedSeedNodes) {
List<String> addedSeedNodes,
String uid) {
this(bannedOfferIds,
nodeAddressesBannedFromTrading,
bannedPaymentAccounts,
Expand Down Expand Up @@ -289,7 +296,8 @@ public Filter(List<String> bannedOfferIds,
takerFeeBsq,
delayedPayoutPaymentAccounts,
addedBtcNodes,
addedSeedNodes);
addedSeedNodes,
uid);
}


Expand Down Expand Up @@ -335,7 +343,8 @@ public Filter(List<String> bannedOfferIds,
long takerFeeBsq,
List<PaymentAccountFilter> delayedPayoutPaymentAccounts,
List<String> addedBtcNodes,
List<String> addedSeedNodes) {
List<String> addedSeedNodes,
String uid) {
this.bannedOfferIds = bannedOfferIds;
this.nodeAddressesBannedFromTrading = nodeAddressesBannedFromTrading;
this.bannedPaymentAccounts = bannedPaymentAccounts;
Expand Down Expand Up @@ -374,6 +383,7 @@ public Filter(List<String> bannedOfferIds,
this.delayedPayoutPaymentAccounts = delayedPayoutPaymentAccounts;
this.addedBtcNodes = addedBtcNodes;
this.addedSeedNodes = addedSeedNodes;
this.uid = uid;

// ownerPubKeyBytes can be null when called from tests
if (ownerPubKeyBytes != null) {
Expand Down Expand Up @@ -445,7 +455,8 @@ private protobuf.Filter.Builder getFilterBuilder(boolean serializeForHash) {
.setTakerFeeBsq(takerFeeBsq)
.addAllDelayedPayoutPaymentAccounts(delayedPayoutPaymentAccountList)
.addAllAddedBtcNodes(addedBtcNodes)
.addAllAddedSeedNodes(addedSeedNodes);
.addAllAddedSeedNodes(addedSeedNodes)
.setUid(uid);

Optional.ofNullable(signatureAsBase64).ifPresent(builder::setSignatureAsBase64);
Optional.ofNullable(extraDataMap).ifPresent(builder::putAllExtraData);
Expand Down Expand Up @@ -498,7 +509,8 @@ public static Filter fromProto(protobuf.Filter proto) {
proto.getTakerFeeBsq(),
delayedPayoutPaymentAccounts,
ProtoUtil.protocolStringListToList(proto.getAddedBtcNodesList()),
ProtoUtil.protocolStringListToList(proto.getAddedSeedNodesList())
ProtoUtil.protocolStringListToList(proto.getAddedSeedNodesList()),
proto.getUid()
);
}

Expand Down Expand Up @@ -558,6 +570,7 @@ public String toString() {
",\n takerFeeBsq=" + takerFeeBsq +
",\n addedBtcNodes=" + addedBtcNodes +
",\n addedSeedNodes=" + addedSeedNodes +
",\n uid=" + uid +
"\n}";
}
}
4 changes: 3 additions & 1 deletion core/src/test/java/bisq/core/filter/TestFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.Collections;
import java.util.List;
import java.util.UUID;

import static org.bitcoinj.core.Utils.HEX;

Expand Down Expand Up @@ -104,7 +105,8 @@ public static Filter createFilter(PublicKey ownerPublicKey, String signerPubKeyA
1,
Collections.emptyList(),
List.of("test1.onion:1221"),
List.of("test2.onion:1221")
List.of("test2.onion:1221"),
UUID.randomUUID().toString()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.common.collect.Lists;

import java.util.HashSet;
import java.util.UUID;

import org.junit.jupiter.api.Disabled;

Expand Down Expand Up @@ -79,7 +80,8 @@ public void testRoundtripFull() {
0,
Lists.newArrayList(),
Lists.newArrayList(),
Lists.newArrayList()));
Lists.newArrayList(),
UUID.randomUUID().toString()));

vo.setRegisteredArbitrator(ArbitratorTest.getArbitratorMock());
vo.setRegisteredMediator(MediatorTest.getMediatorMock());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import static bisq.desktop.util.FormBuilder.addInputTextField;
Expand Down Expand Up @@ -129,6 +130,8 @@ private void addContent() {

InputTextField keyTF = addInputTextField(gridPane, ++rowIndex,
Res.get("shared.unlock"), 10);
InputTextField uidTF = addInputTextField(gridPane, ++rowIndex,
"UID", 10);
if (useDevPrivilegeKeys) {
keyTF.setText(DevEnv.getDEV_PRIVILEGE_PRIV_KEY());
}
Expand Down Expand Up @@ -212,6 +215,7 @@ private void addContent() {

Filter filter = filterManager.getDevFilter();
if (filter != null) {
uidTF.setText(filter.getUid());
setupFieldFromList(offerIdsTF, filter.getBannedOfferIds());
setupFieldFromList(bannedFromTradingTF, filter.getNodeAddressesBannedFromTrading());
setupFieldFromList(bannedFromNetworkTF, filter.getNodeAddressesBannedFromNetwork());
Expand Down Expand Up @@ -247,6 +251,8 @@ private void addContent() {
makerFeeBsqTF.setText(bsqFormatter.formatBSQSatoshis(filter.getMakerFeeBsq()));
takerFeeBsqTF.setText(bsqFormatter.formatBSQSatoshis(filter.getTakerFeeBsq()));
setupFieldFromPaymentAccountFiltersList(delayedPayoutTF, filter.getDelayedPayoutPaymentAccounts());
} else {
uidTF.setText(UUID.randomUUID().toString());
}

Button removeFilterMessageButton = new AutoTooltipButton(Res.get("filterWindow.remove"));
Expand Down Expand Up @@ -292,7 +298,8 @@ private void addContent() {
ParsingUtils.parseToCoin(takerFeeBsqTF.getText(), bsqFormatter).value,
readAsPaymentAccountFiltersList(delayedPayoutTF),
readAsList(addedBtcNodesTF),
readAsList(addedSeedNodesTF)
readAsList(addedSeedNodesTF),
uidTF.getText()
);

// We remove first the old filter
Expand Down
1 change: 1 addition & 0 deletions proto/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ message Filter {
repeated PaymentAccountFilter delayedPayoutPaymentAccounts = 36;
repeated string addedBtcNodes = 37;
repeated string addedSeedNodes = 38;
string uid = 39;
}

/* Deprecated */
Expand Down

0 comments on commit b0b54d3

Please sign in to comment.