From b8cc6d4c0d2769198bcf5429350dc82075f60318 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Tue, 20 Jun 2023 20:47:48 +0200 Subject: [PATCH 1/6] Remove unnecessary lock object and synchronized clause --- common/src/main/java/bisq/common/fsm/Fsm.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/bisq/common/fsm/Fsm.java b/common/src/main/java/bisq/common/fsm/Fsm.java index 420ccc5276..7c51eecadd 100755 --- a/common/src/main/java/bisq/common/fsm/Fsm.java +++ b/common/src/main/java/bisq/common/fsm/Fsm.java @@ -32,7 +32,6 @@ public class Fsm { private final Map>, Transition> transitionMap = new HashMap<>(); - private final Object lock = new Object(); @Getter private final FsmModel model; @@ -52,7 +51,7 @@ protected void configTransitions() { public void handle(Event event) throws FsmException { try { checkNotNull(event, "event must not be null"); - synchronized (lock) { + synchronized (this) { State currentState = model.getState(); checkNotNull(currentState, "currentState must not be null"); if (currentState.isFinalState()) { @@ -87,9 +86,7 @@ private void addTransition(Transition transition) throws FsmException { Pair> pair = new Pair<>(transition.getSourceState(), transition.getEventClass()); checkArgument(!transitionMap.containsKey(pair), "A transition exists already with the state/event pair. pair=%s", pair); - synchronized (lock) { - transitionMap.put(pair, transition); - } + transitionMap.put(pair, transition); } catch (Exception e) { throw new FsmException(e); } From d5a294bfea90235c24e75a8e9a97e9ef8aa04e04 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Tue, 20 Jun 2023 21:10:50 +0200 Subject: [PATCH 2/6] Remove model field from Protocol. Add generics support FsmModel. Enable commented out tests --- common/src/main/java/bisq/common/fsm/Fsm.java | 26 +++++------ .../test/java/bisq/common/fsm/FsmTest.java | 44 +++++++++---------- .../java/bisq/trade/protocol/Protocol.java | 5 +-- 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/common/src/main/java/bisq/common/fsm/Fsm.java b/common/src/main/java/bisq/common/fsm/Fsm.java index 7c51eecadd..9794c66639 100755 --- a/common/src/main/java/bisq/common/fsm/Fsm.java +++ b/common/src/main/java/bisq/common/fsm/Fsm.java @@ -30,16 +30,12 @@ @Slf4j -public class Fsm { +public class Fsm { private final Map>, Transition> transitionMap = new HashMap<>(); @Getter - private final FsmModel model; + protected final M model; - public Fsm(State initialState) { - this(new FsmModel(initialState)); - } - - public Fsm(FsmModel model) { + public Fsm(M model) { this.model = model; configTransitions(); } @@ -92,30 +88,30 @@ private void addTransition(Transition transition) throws FsmException { } } - public TransitionBuilder addTransition() { - return new TransitionBuilder(this); + public TransitionBuilder addTransition() { + return new TransitionBuilder<>(this); } - public static class TransitionBuilder { + public static class TransitionBuilder { private final Transition transition; - private final Fsm fsm; + private final Fsm fsm; - private TransitionBuilder(Fsm fsm) { + private TransitionBuilder(Fsm fsm) { this.fsm = fsm; transition = new Transition(); } - public TransitionBuilder from(State sourceState) { + public TransitionBuilder from(State sourceState) { transition.setSourceState(sourceState); return this; } - public TransitionBuilder on(Class eventClass) { + public TransitionBuilder on(Class eventClass) { transition.setEventClass(eventClass); return this; } - public TransitionBuilder run(Class eventHandlerClass) { + public TransitionBuilder run(Class eventHandlerClass) { try { transition.setEventHandlerClass(Optional.of(eventHandlerClass)); } catch (Exception e) { diff --git a/common/src/test/java/bisq/common/fsm/FsmTest.java b/common/src/test/java/bisq/common/fsm/FsmTest.java index d8e22d8992..bd9c7e2899 100644 --- a/common/src/test/java/bisq/common/fsm/FsmTest.java +++ b/common/src/test/java/bisq/common/fsm/FsmTest.java @@ -25,10 +25,10 @@ import static org.junit.jupiter.api.Assertions.assertNull; public class FsmTest { - // @Test + @Test void testValidStateTransitions() throws FsmException { MockModel model = new MockModel(MockState.INIT); - Fsm fsm = new Fsm(model); + Fsm fsm = new Fsm<>(model); // No change in data as no handler was defined fsm.addTransition() @@ -66,7 +66,7 @@ void testValidStateTransitions() throws FsmException { @Test void testTransitions() throws FsmException { MockModel model = new MockModel(MockState.INIT); - Fsm fsm = new Fsm(model); + Fsm fsm = new Fsm<>(model); // No change in data as no handler was defined fsm.addTransition() @@ -107,11 +107,11 @@ void testTransitions() throws FsmException { assertEquals("test4", model.data); } - // @Test + @Test void testNoStateTransition() throws FsmException { // No such event defined: No state change, no handler call MockModel model1 = new MockModel(MockState.INIT); - Fsm fsm1 = new Fsm(model1); + Fsm fsm1 = new Fsm<>(model1); fsm1.addTransition() .from(MockState.INIT) .on(MockEvent1.class) @@ -124,7 +124,7 @@ void testNoStateTransition() throws FsmException { // If no target state is set we do not create the transition, so no exception is thrown but no transition if // found at handle. MockModel model2 = new MockModel(MockState.INIT); - Fsm fsm2 = new Fsm(model2); + Fsm fsm2 = new Fsm<>(model2); fsm2.addTransition() .from(MockState.INIT) .on(MockEvent1.class) @@ -135,7 +135,7 @@ void testNoStateTransition() throws FsmException { // If source state is already final we do not transit MockModel model3 = new MockModel(MockState.COMPLETED); - Fsm fsm3 = new Fsm(model3); + Fsm fsm3 = new Fsm<>(model3); fsm3.addTransition() .from(MockState.COMPLETED) .on(MockEvent1.class) @@ -147,7 +147,7 @@ void testNoStateTransition() throws FsmException { // Same event and state combination: No state change, no handler call MockModel model4 = new MockModel(MockState.INIT); - Fsm fsm4 = new Fsm(model4); + Fsm fsm4 = new Fsm<>(model4); fsm4.addTransition() .from(MockState.INIT) .on(MockEvent1.class) @@ -162,7 +162,7 @@ void testNoStateTransition() throws FsmException { // No state change as wrong event fired MockModel model5 = new MockModel(MockState.INIT); - Fsm fsm5 = new Fsm(model5); + Fsm fsm5 = new Fsm<>(model5); fsm5.addTransition() .from(MockState.INIT) .on(MockEvent1.class) @@ -173,11 +173,11 @@ void testNoStateTransition() throws FsmException { assertNull(((MockModel) fsm5.getModel()).data); } - // @Test + @Test void testEventHandlerNotCalled() throws FsmException { // No EventHandlerClass defined MockModel model1 = new MockModel(MockState.INIT); - Fsm fsm1 = new Fsm(model1); + Fsm fsm1 = new Fsm<>(model1); fsm1.addTransition() .from(MockState.INIT) .on(MockEvent1.class) @@ -187,11 +187,11 @@ void testEventHandlerNotCalled() throws FsmException { assertNull(((MockModel) fsm1.getModel()).data); } - // @Test + @Test void testFsmExceptions() throws FsmException { Assertions.assertThrows(FsmException.class, () -> { MockModel model = new MockModel(MockState.INIT); - Fsm fsm = new Fsm(model); + Fsm fsm = new Fsm<>(model); fsm.addTransition() .from(null) .on(MockEvent1.class) @@ -201,7 +201,7 @@ void testFsmExceptions() throws FsmException { }); Assertions.assertThrows(FsmException.class, () -> { MockModel model = new MockModel(MockState.INIT); - Fsm fsm = new Fsm(model); + Fsm fsm = new Fsm<>(model); fsm.addTransition() .on(MockEvent1.class) .run(MockEventHandler.class) @@ -210,7 +210,7 @@ void testFsmExceptions() throws FsmException { }); Assertions.assertThrows(FsmException.class, () -> { MockModel model = new MockModel(MockState.INIT); - Fsm fsm = new Fsm(model); + Fsm fsm = new Fsm<>(model); fsm.addTransition() .from(MockState.INIT) .on(null) @@ -220,7 +220,7 @@ void testFsmExceptions() throws FsmException { }); Assertions.assertThrows(FsmException.class, () -> { MockModel model = new MockModel(MockState.INIT); - Fsm fsm = new Fsm(model); + Fsm fsm = new Fsm<>(model); fsm.addTransition() .from(MockState.INIT) .run(MockEventHandler.class) @@ -229,7 +229,7 @@ void testFsmExceptions() throws FsmException { }); Assertions.assertThrows(FsmException.class, () -> { MockModel model = new MockModel(MockState.INIT); - Fsm fsm = new Fsm(model); + Fsm fsm = new Fsm<>(model); fsm.addTransition() .from(MockState.INIT) .on(MockEvent1.class) @@ -239,7 +239,7 @@ void testFsmExceptions() throws FsmException { }); Assertions.assertThrows(FsmException.class, () -> { MockModel model = new MockModel(MockState.INIT); - Fsm fsm = new Fsm(model); + Fsm fsm = new Fsm<>(model); fsm.addTransition() .from(MockState.INIT) .on(MockEvent1.class) @@ -250,7 +250,7 @@ void testFsmExceptions() throws FsmException { // Initial state is null Assertions.assertThrows(FsmException.class, () -> { MockModel model = new MockModel(null); - Fsm fsm = new Fsm(model); + Fsm fsm = new Fsm<>(model); fsm.addTransition() .from(MockState.INIT) .on(MockEvent1.class) @@ -261,7 +261,7 @@ void testFsmExceptions() throws FsmException { // Same source and target state Assertions.assertThrows(FsmException.class, () -> { MockModel model = new MockModel(MockState.INIT); - Fsm fsm = new Fsm(model); + Fsm fsm = new Fsm<>(model); fsm.addTransition() .from(MockState.INIT) .on(MockEvent1.class) @@ -273,7 +273,7 @@ void testFsmExceptions() throws FsmException { // MockEventHandler2 constructor not matching defined constructor signature in newEventHandlerFromClass Assertions.assertThrows(FsmException.class, () -> { MockModel model = new MockModel(MockState.INIT); - Fsm fsm = new Fsm(model); + Fsm fsm = new Fsm<>(model); fsm.addTransition() .from(MockState.INIT) .on(MockEvent1.class) @@ -285,7 +285,7 @@ void testFsmExceptions() throws FsmException { // same pair sourceState/event added Assertions.assertThrows(FsmException.class, () -> { MockModel model = new MockModel(MockState.INIT); - Fsm fsm = new Fsm(model); + Fsm fsm = new Fsm<>(model); fsm.addTransition() .from(MockState.INIT) .on(MockEvent1.class) diff --git a/trade/src/main/java/bisq/trade/protocol/Protocol.java b/trade/src/main/java/bisq/trade/protocol/Protocol.java index b92cecd275..0e0e274250 100644 --- a/trade/src/main/java/bisq/trade/protocol/Protocol.java +++ b/trade/src/main/java/bisq/trade/protocol/Protocol.java @@ -30,20 +30,17 @@ @Slf4j @Getter @EqualsAndHashCode(callSuper = true) -public abstract class Protocol> extends Fsm { +public abstract class Protocol> extends Fsm { protected final ServiceProvider serviceProvider; - protected final M model; public Protocol(ServiceProvider serviceProvider, M model) { super(model); this.serviceProvider = serviceProvider; - this.model = model; } public void handle(Event event) throws TradeException { try { - log.error("event={}", event); super.handle(event); } catch (FsmException e) { throw new TradeException(e); From b075088e1e6d7040cbc50a81650731c2d69e97a6 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Tue, 20 Jun 2023 21:11:41 +0200 Subject: [PATCH 3/6] Remove unused persistenceService argument --- trade/src/main/java/bisq/trade/ServiceProvider.java | 2 -- .../main/java/bisq/trade/bisq_easy/BisqEasyTradeService.java | 1 - .../src/main/java/bisq/trade/multisig/MultisigTradeService.java | 1 - .../main/java/bisq/trade/submarine/SubmarineTradeService.java | 1 - 4 files changed, 5 deletions(-) diff --git a/trade/src/main/java/bisq/trade/ServiceProvider.java b/trade/src/main/java/bisq/trade/ServiceProvider.java index cf7aa55308..96c0cb617a 100644 --- a/trade/src/main/java/bisq/trade/ServiceProvider.java +++ b/trade/src/main/java/bisq/trade/ServiceProvider.java @@ -21,7 +21,6 @@ import bisq.identity.IdentityService; import bisq.network.NetworkService; import bisq.offer.OfferService; -import bisq.persistence.PersistenceService; import bisq.support.MediationService; import bisq.support.SupportService; import lombok.Getter; @@ -38,7 +37,6 @@ public class ServiceProvider { public ServiceProvider(NetworkService networkService, IdentityService identityService, - PersistenceService persistenceService, OfferService offerService, ContractService contractService, SupportService supportService) { diff --git a/trade/src/main/java/bisq/trade/bisq_easy/BisqEasyTradeService.java b/trade/src/main/java/bisq/trade/bisq_easy/BisqEasyTradeService.java index 826a2e7f9d..923b16f433 100644 --- a/trade/src/main/java/bisq/trade/bisq_easy/BisqEasyTradeService.java +++ b/trade/src/main/java/bisq/trade/bisq_easy/BisqEasyTradeService.java @@ -86,7 +86,6 @@ public BisqEasyTradeService(NetworkService networkService, this.mediationService = supportService.getMediationService(); serviceProvider = new ServiceProvider(networkService, identityService, - persistenceService, offerService, contractService, supportService); diff --git a/trade/src/main/java/bisq/trade/multisig/MultisigTradeService.java b/trade/src/main/java/bisq/trade/multisig/MultisigTradeService.java index ff45f01d93..27353dec4e 100644 --- a/trade/src/main/java/bisq/trade/multisig/MultisigTradeService.java +++ b/trade/src/main/java/bisq/trade/multisig/MultisigTradeService.java @@ -77,7 +77,6 @@ public MultisigTradeService(NetworkService networkService, this.mediationService = supportService.getMediationService(); serviceProvider = new ServiceProvider(networkService, identityService, - persistenceService, offerService, contractService, supportService); diff --git a/trade/src/main/java/bisq/trade/submarine/SubmarineTradeService.java b/trade/src/main/java/bisq/trade/submarine/SubmarineTradeService.java index 579ab6c8d7..32d04938e5 100644 --- a/trade/src/main/java/bisq/trade/submarine/SubmarineTradeService.java +++ b/trade/src/main/java/bisq/trade/submarine/SubmarineTradeService.java @@ -77,7 +77,6 @@ public SubmarineTradeService(NetworkService networkService, this.mediationService = supportService.getMediationService(); serviceProvider = new ServiceProvider(networkService, identityService, - persistenceService, offerService, contractService, supportService); From 268c19e9e9d94d3ed78705176dd086859f429bb3 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Tue, 20 Jun 2023 21:12:45 +0200 Subject: [PATCH 4/6] Remove toString annotation --- network/network/src/main/java/bisq/network/NetworkId.java | 1 - 1 file changed, 1 deletion(-) diff --git a/network/network/src/main/java/bisq/network/NetworkId.java b/network/network/src/main/java/bisq/network/NetworkId.java index 1b3dd38b27..c55ebf0e2a 100644 --- a/network/network/src/main/java/bisq/network/NetworkId.java +++ b/network/network/src/main/java/bisq/network/NetworkId.java @@ -33,7 +33,6 @@ import static com.google.common.base.Preconditions.checkArgument; -@ToString @EqualsAndHashCode @Getter public final class NetworkId implements Proto { From 9f23892ab9a4629b7bd4bb9ab326a389bff05d93 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Tue, 20 Jun 2023 21:30:42 +0200 Subject: [PATCH 5/6] Replace isBuyer and isTaker boolean with TradeRole enum --- trade/src/main/java/bisq/trade/Trade.java | 89 +++++++------------ trade/src/main/java/bisq/trade/TradeRole.java | 56 ++++++++++++ .../bisq/trade/bisq_easy/BisqEasyTrade.java | 9 +- .../bisq/trade/multisig/MultisigTrade.java | 9 +- .../bisq/trade/submarine/SubmarineTrade.java | 9 +- trade/src/main/proto/protocol.proto | 13 ++- 6 files changed, 108 insertions(+), 77 deletions(-) create mode 100644 trade/src/main/java/bisq/trade/TradeRole.java diff --git a/trade/src/main/java/bisq/trade/Trade.java b/trade/src/main/java/bisq/trade/Trade.java index 09aa503b09..7f775a81c2 100644 --- a/trade/src/main/java/bisq/trade/Trade.java +++ b/trade/src/main/java/bisq/trade/Trade.java @@ -36,38 +36,22 @@ @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) public abstract class Trade, C extends Contract, P extends TradeParty> extends FsmModel implements Proto { - @Getter - public enum Role { - BUYER_AS_TAKER(true, true), - BUYER_AS_MAKER(true, false), - SELLER_AS_TAKER(false, true), - SELLER_AS_MAKER(false, false); - - private final boolean isBuyer; - private final boolean isTaker; - - Role(boolean isBuyer, boolean isTaker) { - this.isBuyer = isBuyer; - this.isTaker = isTaker; - } - - public boolean isMaker() { - return !isTaker; - } - - public boolean isSeller() { - return !isBuyer; - } - } - public static String createId(String offerId, String takerPubKeyHash) { return offerId + "." + takerPubKeyHash; } + private static TradeRole createRole(boolean isBuyer, boolean isTaker) { + return isBuyer ? + (isTaker ? + TradeRole.BUYER_AS_TAKER : + TradeRole.BUYER_AS_MAKER) : + (isTaker ? + TradeRole.SELLER_AS_TAKER : + TradeRole.SELLER_AS_MAKER); + } + @Getter private final String id; - private final boolean isBuyer; - private final boolean isTaker; @Getter private final Identity myIdentity; @Getter @@ -77,45 +61,33 @@ public static String createId(String offerId, String takerPubKeyHash) { @Getter private final P maker; @Getter - private transient final Role role; + private transient final TradeRole tradeRole; public Trade(State state, boolean isBuyer, boolean isTaker, Identity myIdentity, C contract, P taker, P maker) { this(state, createId(contract.getOffer().getId(), taker.getNetworkId().getId()), - isBuyer, - isTaker, + createRole(isBuyer, isTaker), myIdentity, contract, taker, maker); - } - protected Trade(State state, String id, boolean isBuyer, boolean isTaker, Identity myIdentity, C contract, P taker, P maker) { + protected Trade(State state, String id, TradeRole tradeRole, Identity myIdentity, C contract, P taker, P maker) { super(state); this.id = id; - this.isBuyer = isBuyer; - this.isTaker = isTaker; + this.tradeRole = tradeRole; this.myIdentity = myIdentity; this.contract = contract; this.taker = taker; this.maker = maker; - - role = isBuyer ? - (isTaker ? - Role.BUYER_AS_TAKER : - Role.BUYER_AS_MAKER) : - (isTaker ? - Role.SELLER_AS_TAKER : - Role.SELLER_AS_MAKER); } protected bisq.trade.protobuf.Trade.Builder getTradeBuilder() { return bisq.trade.protobuf.Trade.newBuilder() .setId(id) - .setIsBuyer(isBuyer) - .setIsTaker(isTaker) + .setTradeRole(tradeRole.toProto()) .setMyIdentity(myIdentity.toProto()) .setContract(contract.toProto()) .setTaker(taker.toProto()) @@ -162,8 +134,9 @@ public static SubmarineTrade protoToSubmarineTrade(bisq.trade.protobuf.Trade pro throw new UnresolvableProtobufMessageException(proto); } + /////////////////////////////////////////////////////////////////////////////////////////////////// - // Convenience Getters + // Delegates /////////////////////////////////////////////////////////////////////////////////////////////////// public T getOffer() { @@ -171,51 +144,51 @@ public T getOffer() { } public boolean isBuyer() { - return isBuyer; + return tradeRole.isBuyer(); } public boolean isSeller() { - return !isBuyer; + return tradeRole.isSeller(); } public boolean isTaker() { - return isTaker; + return tradeRole.isTaker(); } public boolean isMaker() { - return !isTaker; + return tradeRole.isMaker(); } public P getPeer() { - return isTaker ? maker : taker; + return tradeRole.isTaker() ? maker : taker; } public P getMyself() { - return isTaker ? taker : maker; + return tradeRole.isTaker() ? taker : maker; } public P getBuyer() { - if (role == Role.BUYER_AS_TAKER) { + if (tradeRole == TradeRole.BUYER_AS_TAKER) { return taker; - } else if (role == Role.BUYER_AS_MAKER) { + } else if (tradeRole == TradeRole.BUYER_AS_MAKER) { return maker; - } else if (role == Role.SELLER_AS_TAKER) { + } else if (tradeRole == TradeRole.SELLER_AS_TAKER) { return maker; } else { - // role == Role.SELLER_AS_MAKER + // tradeRole == TradeRole.SELLER_AS_MAKER return taker; } } public P getSeller() { - if (role == Role.BUYER_AS_TAKER) { + if (tradeRole == TradeRole.BUYER_AS_TAKER) { return maker; - } else if (role == Role.BUYER_AS_MAKER) { + } else if (tradeRole == TradeRole.BUYER_AS_MAKER) { return taker; - } else if (role == Role.SELLER_AS_TAKER) { + } else if (tradeRole == TradeRole.SELLER_AS_TAKER) { return taker; } else { - // role == Role.SELLER_AS_MAKER + // tradeRole == TradeRole.SELLER_AS_MAKER return maker; } } diff --git a/trade/src/main/java/bisq/trade/TradeRole.java b/trade/src/main/java/bisq/trade/TradeRole.java new file mode 100644 index 0000000000..4d59ccbdc7 --- /dev/null +++ b/trade/src/main/java/bisq/trade/TradeRole.java @@ -0,0 +1,56 @@ +/* + * 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.trade; + +import bisq.common.proto.ProtoEnum; +import bisq.common.util.ProtobufUtils; +import lombok.Getter; + +@Getter +public enum TradeRole implements ProtoEnum { + BUYER_AS_TAKER(true, true), + BUYER_AS_MAKER(true, false), + SELLER_AS_TAKER(false, true), + SELLER_AS_MAKER(false, false); + + private final boolean isBuyer; + private final boolean isTaker; + + TradeRole(boolean isBuyer, boolean isTaker) { + this.isBuyer = isBuyer; + this.isTaker = isTaker; + } + + @Override + public bisq.trade.protobuf.TradeRole toProto() { + return bisq.trade.protobuf.TradeRole.valueOf(name()); + } + + public static TradeRole fromProto(bisq.trade.protobuf.TradeRole proto) { + return ProtobufUtils.enumFromProto(TradeRole.class, proto.name()); + } + + public boolean isMaker() { + return !isTaker; + } + + public boolean isSeller() { + return !isBuyer; + } + +} \ No newline at end of file diff --git a/trade/src/main/java/bisq/trade/bisq_easy/BisqEasyTrade.java b/trade/src/main/java/bisq/trade/bisq_easy/BisqEasyTrade.java index 01dc2cba6c..fb2cb60d52 100644 --- a/trade/src/main/java/bisq/trade/bisq_easy/BisqEasyTrade.java +++ b/trade/src/main/java/bisq/trade/bisq_easy/BisqEasyTrade.java @@ -26,6 +26,7 @@ import bisq.offer.bisq_easy.BisqEasyOffer; import bisq.trade.Trade; import bisq.trade.TradeParty; +import bisq.trade.TradeRole; import bisq.trade.bisq_easy.protocol.BisqEasyTradeState; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -66,13 +67,12 @@ public BisqEasyTrade(boolean isBuyer, private BisqEasyTrade(BisqEasyTradeState state, String id, - boolean isBuyer, - boolean isTaker, + TradeRole tradeRole, Identity myIdentity, BisqEasyContract contract, BisqEasyTradeParty taker, BisqEasyTradeParty maker) { - super(state, id, isBuyer, isTaker, myIdentity, contract, taker, maker); + super(state, id, tradeRole, myIdentity, contract, taker, maker); stateObservable().addObserver(s -> tradeState.set((BisqEasyTradeState) s)); } @@ -90,8 +90,7 @@ public bisq.trade.protobuf.Trade toProto() { public static BisqEasyTrade fromProto(bisq.trade.protobuf.Trade proto) { BisqEasyTrade bisqEasyTrade = new BisqEasyTrade(ProtobufUtils.enumFromProto(BisqEasyTradeState.class, proto.getState()), proto.getId(), - proto.getIsBuyer(), - proto.getIsTaker(), + TradeRole.fromProto(proto.getTradeRole()), Identity.fromProto(proto.getMyIdentity()), BisqEasyContract.fromProto(proto.getContract()), TradeParty.protoToBisqEasyTradeParty(proto.getTaker()), diff --git a/trade/src/main/java/bisq/trade/multisig/MultisigTrade.java b/trade/src/main/java/bisq/trade/multisig/MultisigTrade.java index d3849084ed..192aa1db8a 100644 --- a/trade/src/main/java/bisq/trade/multisig/MultisigTrade.java +++ b/trade/src/main/java/bisq/trade/multisig/MultisigTrade.java @@ -26,6 +26,7 @@ import bisq.offer.multisig.MultisigOffer; import bisq.trade.Trade; import bisq.trade.TradeParty; +import bisq.trade.TradeRole; import bisq.trade.multisig.protocol.MultisigTradeState; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -55,13 +56,12 @@ public MultisigTrade(boolean isBuyer, private MultisigTrade(MultisigTradeState state, String id, - boolean isBuyer, - boolean isTaker, + TradeRole tradeRole, Identity myIdentity, MultisigContract contract, MultisigTradeParty taker, MultisigTradeParty maker) { - super(state, id, isBuyer, isTaker, myIdentity, contract, taker, maker); + super(state, id, tradeRole, myIdentity, contract, taker, maker); stateObservable().addObserver(s -> tradeState.set((MultisigTradeState) s)); } @@ -75,8 +75,7 @@ public bisq.trade.protobuf.Trade toProto() { public static MultisigTrade fromProto(bisq.trade.protobuf.Trade proto) { return new MultisigTrade(ProtobufUtils.enumFromProto(MultisigTradeState.class, proto.getState()), proto.getId(), - proto.getIsBuyer(), - proto.getIsTaker(), + TradeRole.fromProto(proto.getTradeRole()), Identity.fromProto(proto.getMyIdentity()), MultisigContract.fromProto(proto.getContract()), TradeParty.protoToMultisigTradeParty(proto.getTaker()), diff --git a/trade/src/main/java/bisq/trade/submarine/SubmarineTrade.java b/trade/src/main/java/bisq/trade/submarine/SubmarineTrade.java index 6da1b771bd..a52a525e5d 100644 --- a/trade/src/main/java/bisq/trade/submarine/SubmarineTrade.java +++ b/trade/src/main/java/bisq/trade/submarine/SubmarineTrade.java @@ -26,6 +26,7 @@ import bisq.offer.submarine.SubmarineOffer; import bisq.trade.Trade; import bisq.trade.TradeParty; +import bisq.trade.TradeRole; import bisq.trade.submarine.protocol.SubmarineTradeState; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -55,13 +56,12 @@ public SubmarineTrade(boolean isBuyer, private SubmarineTrade(SubmarineTradeState state, String id, - boolean isBuyer, - boolean isTaker, + TradeRole tradeRole, Identity myIdentity, SubmarineContract contract, SubmarineTradeParty taker, SubmarineTradeParty maker) { - super(state, id, isBuyer, isTaker, myIdentity, contract, taker, maker); + super(state, id, tradeRole, myIdentity, contract, taker, maker); stateObservable().addObserver(s -> tradeState.set((SubmarineTradeState) s)); } @@ -75,8 +75,7 @@ public bisq.trade.protobuf.Trade toProto() { public static SubmarineTrade fromProto(bisq.trade.protobuf.Trade proto) { return new SubmarineTrade(ProtobufUtils.enumFromProto(SubmarineTradeState.class, proto.getState()), proto.getId(), - proto.getIsBuyer(), - proto.getIsTaker(), + TradeRole.fromProto(proto.getTradeRole()), Identity.fromProto(proto.getMyIdentity()), SubmarineContract.fromProto(proto.getContract()), TradeParty.protoToSubmarineTradeParty(proto.getTaker()), diff --git a/trade/src/main/proto/protocol.proto b/trade/src/main/proto/protocol.proto index 4125f3e074..9891526d70 100644 --- a/trade/src/main/proto/protocol.proto +++ b/trade/src/main/proto/protocol.proto @@ -36,15 +36,20 @@ message TradeParty { } } +enum TradeRole{ + BUYER_AS_TAKER = 0; + BUYER_AS_MAKER = 1; + SELLER_AS_TAKER = 2; + SELLER_AS_MAKER = 3; +} message Trade { - string id = 1; - bool isBuyer = 2; - bool isTaker = 3; + string state = 1; + string id = 2; + TradeRole tradeRole = 3; identity.Identity myIdentity = 4; contract.Contract contract = 5; TradeParty taker = 6; TradeParty maker = 7; - string state = 8; oneof message { BisqEasyTrade bisqEasyTrade = 20; From ab8456dfbd2131fb1af1d430423db9f7280015df Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Tue, 20 Jun 2023 22:01:13 +0200 Subject: [PATCH 6/6] Remove jeasy dependency --- gradle/libs.versions.toml | 2 -- trade/build.gradle | 1 - 2 files changed, 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ec6b9fc5d1..1bd42f1656 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -33,7 +33,6 @@ google-guava-lib = { strictly = '31.1-jre' } i2p-lib = { strictly = '1.8.0' } jackson-lib = { strictly = '2.13.3' } -jeasy-easy-states-lib = { strictly = '2.0.0' } jeromq-lib = { strictly = '0.5.2' } jpackage-plugin = { strictly = '1.3.1' } junit-jupiter-lib = { strictly = '5.8.2' } @@ -100,7 +99,6 @@ jackson-core = { module = 'com.fasterxml.jackson.core:jackson-core', version.ref jackson-annotations = { module = 'com.fasterxml.jackson.core:jackson-annotations', version.ref = 'jackson-lib' } jackson-databind = { module = 'com.fasterxml.jackson.core:jackson-databind', version.ref = 'jackson-lib' } -jeasy-easy-states = { module = 'org.jeasy:easy-states', version.ref = 'jeasy-easy-states-lib' } jeromq = { module = 'org.zeromq:jeromq', version.ref = 'jeromq-lib' } junit-jupiter = { module = 'org.junit.jupiter:junit-jupiter', version.ref = 'junit-jupiter-lib' } diff --git a/trade/build.gradle b/trade/build.gradle index 66c57fb4c5..afc84a1d02 100644 --- a/trade/build.gradle +++ b/trade/build.gradle @@ -18,5 +18,4 @@ dependencies { implementation libs.google.guava implementation libs.typesafe.config - implementation libs.jeasy.easy.states }