Fix TradableList, impl. missing fromProto methods

This commit is contained in:
Manfred Karrer 2017-05-31 01:36:12 +02:00
parent 1efe4e8828
commit 2a7f851936
22 changed files with 307 additions and 172 deletions

View File

@ -19,11 +19,11 @@ package io.bisq.core.arbitration;
import com.google.protobuf.ByteString;
import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.proto.ProtoResolver;
import io.bisq.common.proto.network.NetworkPayload;
import io.bisq.common.storage.Storage;
import io.bisq.common.util.Utilities;
import io.bisq.core.arbitration.messages.DisputeCommunicationMessage;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.core.trade.Contract;
import io.bisq.generated.protobuffer.PB;
import javafx.beans.property.*;
@ -206,14 +206,14 @@ public final class Dispute implements NetworkPayload {
return builder.build();
}
public static Dispute fromProto(PB.Dispute proto, ProtoResolver protoResolver) {
public static Dispute fromProto(PB.Dispute proto, CoreProtoResolver coreProtoResolver) {
final Dispute dispute = new Dispute(proto.getTradeId(),
proto.getTraderId(),
proto.getDisputeOpenerIsBuyer(),
proto.getDisputeOpenerIsMaker(),
PubKeyRing.fromProto(proto.getTraderPubKeyRing()),
proto.getTradeDate(),
Contract.fromProto(proto.getContract(), protoResolver),
Contract.fromProto(proto.getContract(), coreProtoResolver),
proto.getContractHash().toByteArray(),
proto.getDepositTxSerialized().toByteArray(),
proto.getPayoutTxSerialized().toByteArray(),

View File

@ -17,9 +17,9 @@
package io.bisq.core.arbitration.messages;
import io.bisq.common.proto.ProtoResolver;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.core.arbitration.Dispute;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
import lombok.EqualsAndHashCode;
@ -49,8 +49,8 @@ public final class OpenNewDisputeMessage extends DisputeMessage {
.build();
}
public static OpenNewDisputeMessage fromProto(PB.OpenNewDisputeMessage proto, ProtoResolver protoResolver) {
return new OpenNewDisputeMessage(Dispute.fromProto(proto.getDispute(), protoResolver),
public static OpenNewDisputeMessage fromProto(PB.OpenNewDisputeMessage proto, CoreProtoResolver coreProtoResolver) {
return new OpenNewDisputeMessage(Dispute.fromProto(proto.getDispute(), coreProtoResolver),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());
}

View File

@ -17,9 +17,9 @@
package io.bisq.core.arbitration.messages;
import io.bisq.common.proto.ProtoResolver;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.core.arbitration.Dispute;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
import lombok.EqualsAndHashCode;
@ -49,8 +49,8 @@ public final class PeerOpenedDisputeMessage extends DisputeMessage {
.build();
}
public static PeerOpenedDisputeMessage fromProto(PB.PeerOpenedDisputeMessage proto, ProtoResolver protoResolver) {
return new PeerOpenedDisputeMessage(Dispute.fromProto(proto.getDispute(), protoResolver),
public static PeerOpenedDisputeMessage fromProto(PB.PeerOpenedDisputeMessage proto, CoreProtoResolver coreProtoResolver) {
return new PeerOpenedDisputeMessage(Dispute.fromProto(proto.getDispute(), coreProtoResolver),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getUid());
}

View File

@ -40,6 +40,18 @@ public final class RawTransactionInput implements NetworkPayload, PersistablePay
this.value = value;
}
@Override
public PB.RawTransactionInput toProtoMessage() {
return PB.RawTransactionInput.newBuilder()
.setIndex(index)
.setParentTransaction(ByteString.copyFrom(parentTransaction))
.setValue(value).build();
}
public static RawTransactionInput fromProto(PB.RawTransactionInput proto) {
return new RawTransactionInput(proto.getIndex(), proto.getParentTransaction().toByteArray(), proto.getValue());
}
// byes not printed...
@Override
public String toString() {
@ -49,12 +61,4 @@ public final class RawTransactionInput implements NetworkPayload, PersistablePay
", value=" + value +
'}';
}
@Override
public PB.RawTransactionInput toProtoMessage() {
return PB.RawTransactionInput.newBuilder()
.setIndex(index)
.setParentTransaction(ByteString.copyFrom(parentTransaction))
.setValue(value).build();
}
}

View File

@ -452,7 +452,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
private void republishOffers() {
int size = openOfferTradableList.size();
final ArrayList<OpenOffer> openOffersList = new ArrayList<>(openOfferTradableList.getTradableList());
final ArrayList<OpenOffer> openOffersList = new ArrayList<>(openOfferTradableList.getList());
Log.traceCall("Number of offer for republish: " + size);
if (!stopped) {
stopPeriodicRefreshOffersTimer();
@ -538,7 +538,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
Log.traceCall("Number of offer for refresh: " + size);
//we clone our list as openOffers might change during our delayed call
final ArrayList<OpenOffer> openOffersList = new ArrayList<>(openOfferTradableList.getTradableList());
final ArrayList<OpenOffer> openOffersList = new ArrayList<>(openOfferTradableList.getList());
for (int i = 0; i < size; i++) {
// we delay to avoid reaching throttle limits
// roughly 4 offers per second

View File

@ -18,11 +18,11 @@
package io.bisq.core.payment;
import io.bisq.common.locale.TradeCurrency;
import io.bisq.common.proto.ProtoResolver;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.proto.persistable.PersistablePayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.payment.payload.PaymentMethod;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.generated.protobuffer.PB;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@ -88,14 +88,14 @@ public abstract class PaymentAccount implements PersistablePayload {
return builder.build();
}
public static PaymentAccount fromProto(PB.PaymentAccount proto, ProtoResolver protoResolver) {
public static PaymentAccount fromProto(PB.PaymentAccount proto, CoreProtoResolver coreProtoResolver) {
PaymentAccount paymentAccount = PaymentAccountFactory.getPaymentAccount(PaymentMethod.getPaymentMethodById(proto.getPaymentMethod().getId()));
paymentAccount.setId(proto.getId());
paymentAccount.setCreationDate(proto.getCreationDate());
paymentAccount.setAccountName(proto.getAccountName());
paymentAccount.getTradeCurrencies().addAll(proto.getTradeCurrenciesList().stream().map(TradeCurrency::fromProto).collect(Collectors.toList()));
paymentAccount.setSelectedTradeCurrency(paymentAccount.getSelectedTradeCurrency());
paymentAccount.setPaymentAccountPayload((PaymentAccountPayload) protoResolver.fromProto(proto.getPaymentAccountPayload()));
paymentAccount.setPaymentAccountPayload(coreProtoResolver.fromProto(proto.getPaymentAccountPayload()));
return paymentAccount;
}

View File

@ -97,13 +97,13 @@ public class CorePersistenceProtoResolver extends CoreProtoResolver implements P
case OPEN_OFFER:
return OpenOffer.fromProto(proto.getOpenOffer());
case BUYER_AS_MAKER_TRADE:
return BuyerAsMakerTrade.fromProto(proto.getBuyerAsMakerTrade(), storage, btcWalletService.get());
return BuyerAsMakerTrade.fromProto(proto.getBuyerAsMakerTrade(), storage, btcWalletService.get(), this);
case BUYER_AS_TAKER_TRADE:
return BuyerAsTakerTrade.fromProto(proto.getBuyerAsTakerTrade(), storage, btcWalletService.get());
return BuyerAsTakerTrade.fromProto(proto.getBuyerAsTakerTrade(), storage, btcWalletService.get(), this);
case SELLER_AS_MAKER_TRADE:
return SellerAsMakerTrade.fromProto(proto.getSellerAsMakerTrade(), storage, btcWalletService.get());
return SellerAsMakerTrade.fromProto(proto.getSellerAsMakerTrade(), storage, btcWalletService.get(), this);
case SELLER_AS_TAKER_TRADE:
return SellerAsTakerTrade.fromProto(proto.getSellerAsTakerTrade(), storage, btcWalletService.get());
return SellerAsTakerTrade.fromProto(proto.getSellerAsTakerTrade(), storage, btcWalletService.get(), this);
default:
throw new ProtobufferException("Unknown proto message case. messageCase=" + proto.getMessageCase());
}

View File

@ -20,6 +20,7 @@ package io.bisq.core.trade;
import io.bisq.common.storage.Storage;
import io.bisq.core.btc.wallet.BtcWalletService;
import io.bisq.core.offer.Offer;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.core.trade.messages.TradeMessage;
import io.bisq.core.trade.protocol.BuyerAsMakerProtocol;
import io.bisq.core.trade.protocol.MakerProtocol;
@ -61,12 +62,25 @@ public final class BuyerAsMakerTrade extends BuyerTrade implements MakerTrade {
.setBuyerAsMakerTrade(PB.BuyerAsMakerTrade.newBuilder().setTrade((PB.Trade) super.toProtoMessage())).build();
}
public static Tradable fromProto(PB.BuyerAsMakerTrade proto, Storage<? extends TradableList> storage,
BtcWalletService btcWalletService) {
return new BuyerAsMakerTrade(Offer.fromProto(proto.getTrade().getOffer()),
Coin.valueOf(proto.getTrade().getTxFeeAsLong()),
Coin.valueOf(proto.getTrade().getTakerFeeAsLong()),
proto.getTrade().getIsCurrencyForTakerFeeBtc(), storage, btcWalletService);
public static Tradable fromProto(PB.BuyerAsMakerTrade buyerAsMakerTradeProto,
Storage<? extends TradableList> storage,
BtcWalletService btcWalletService,
CoreProtoResolver coreProtoResolver) {
PB.Trade proto = buyerAsMakerTradeProto.getTrade();
final BuyerAsMakerTrade trade = new BuyerAsMakerTrade(Offer.fromProto(proto.getOffer()),
Coin.valueOf(proto.getTxFeeAsLong()),
Coin.valueOf(proto.getTakerFeeAsLong()),
proto.getIsCurrencyForTakerFeeBtc(),
storage,
btcWalletService);
trade.setTradeAmountAsLong(proto.getTradeAmountAsLong());
trade.setTradePrice(proto.getTradePrice());
trade.setTradingPeerNodeAddress(NodeAddress.fromProto(proto.getTradingPeerNodeAddress()));
return Trade.fromProto(trade,
proto,
coreProtoResolver);
}

View File

@ -20,6 +20,7 @@ package io.bisq.core.trade;
import io.bisq.common.storage.Storage;
import io.bisq.core.btc.wallet.BtcWalletService;
import io.bisq.core.offer.Offer;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.core.trade.protocol.BuyerAsTakerProtocol;
import io.bisq.core.trade.protocol.TakerProtocol;
import io.bisq.generated.protobuffer.PB;
@ -65,15 +66,22 @@ public final class BuyerAsTakerTrade extends BuyerTrade implements TakerTrade {
.setBuyerAsTakerTrade(PB.BuyerAsTakerTrade.newBuilder().setTrade((PB.Trade) super.toProtoMessage())).build();
}
public static Tradable fromProto(PB.BuyerAsTakerTrade proto, Storage<? extends TradableList> storage,
BtcWalletService btcWalletService) {
PB.Trade trade = proto.getTrade();
return new BuyerAsTakerTrade(Offer.fromProto(trade.getOffer()),
Coin.valueOf(trade.getTxFeeAsLong()), Coin.valueOf(trade.getTakerFeeAsLong()),
Coin.valueOf(trade.getTakerFeeAsLong()),
trade.getIsCurrencyForTakerFeeBtc(), trade.getTradePrice(),
NodeAddress.fromProto(trade.getTradingPeerNodeAddress()), storage,
btcWalletService);
public static Tradable fromProto(PB.BuyerAsTakerTrade buyerAsTakerTradeProto,
Storage<? extends TradableList> storage,
BtcWalletService btcWalletService,
CoreProtoResolver coreProtoResolver) {
PB.Trade proto = buyerAsTakerTradeProto.getTrade();
return Trade.fromProto(new BuyerAsTakerTrade(Offer.fromProto(proto.getOffer()),
Coin.valueOf(proto.getTradeAmountAsLong()),
Coin.valueOf(proto.getTxFeeAsLong()),
Coin.valueOf(proto.getTakerFeeAsLong()),
proto.getIsCurrencyForTakerFeeBtc(),
proto.getTradePrice(),
NodeAddress.fromProto(proto.getTradingPeerNodeAddress()),
storage,
btcWalletService),
proto,
coreProtoResolver);
}

View File

@ -20,11 +20,11 @@ package io.bisq.core.trade;
import com.google.protobuf.ByteString;
import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.monetary.Price;
import io.bisq.common.proto.ProtoResolver;
import io.bisq.common.proto.network.NetworkPayload;
import io.bisq.common.util.JsonExclude;
import io.bisq.core.offer.OfferPayload;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
import lombok.Value;
@ -111,7 +111,7 @@ public final class Contract implements NetworkPayload {
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
public static Contract fromProto(PB.Contract contract, ProtoResolver protoResolver) {
public static Contract fromProto(PB.Contract contract, CoreProtoResolver coreProtoResolver) {
return new Contract(OfferPayload.fromProto(contract.getOfferPayload()),
contract.getTradeAmount(),
contract.getTradePrice(),
@ -123,8 +123,8 @@ public final class Contract implements NetworkPayload {
contract.getIsBuyerMakerAndSellerTaker(),
contract.getMakerAccountId(),
contract.getTakerAccountId(),
(PaymentAccountPayload) protoResolver.fromProto(contract.getMakerPaymentAccountPayload()),
(PaymentAccountPayload) protoResolver.fromProto(contract.getTakerPaymentAccountPayload()),
coreProtoResolver.fromProto(contract.getMakerPaymentAccountPayload()),
coreProtoResolver.fromProto(contract.getTakerPaymentAccountPayload()),
PubKeyRing.fromProto(contract.getMakerPubKeyRing()),
PubKeyRing.fromProto(contract.getTakerPubKeyRing()),
contract.getMakerPayoutAddressString(),

View File

@ -20,6 +20,7 @@ package io.bisq.core.trade;
import io.bisq.common.storage.Storage;
import io.bisq.core.btc.wallet.BtcWalletService;
import io.bisq.core.offer.Offer;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.core.trade.messages.TradeMessage;
import io.bisq.core.trade.protocol.MakerProtocol;
import io.bisq.core.trade.protocol.SellerAsMakerProtocol;
@ -60,12 +61,25 @@ public final class SellerAsMakerTrade extends SellerTrade implements MakerTrade
.setSellerAsMakerTrade(PB.SellerAsMakerTrade.newBuilder().setTrade((PB.Trade) super.toProtoMessage())).build();
}
public static Tradable fromProto(PB.SellerAsMakerTrade proto, Storage<? extends TradableList> storage,
BtcWalletService btcWalletService) {
PB.Trade trade = proto.getTrade();
return new SellerAsMakerTrade(Offer.fromProto(trade.getOffer()),
Coin.valueOf(trade.getTxFeeAsLong()), Coin.valueOf(trade.getTakerFeeAsLong()),
trade.getIsCurrencyForTakerFeeBtc(), storage, btcWalletService);
public static Tradable fromProto(PB.SellerAsMakerTrade sellerAsMakerTradeProto,
Storage<? extends TradableList> storage,
BtcWalletService btcWalletService,
CoreProtoResolver coreProtoResolver) {
PB.Trade proto = sellerAsMakerTradeProto.getTrade();
final SellerAsMakerTrade trade = new SellerAsMakerTrade(Offer.fromProto(proto.getOffer()),
Coin.valueOf(proto.getTxFeeAsLong()),
Coin.valueOf(proto.getTakerFeeAsLong()),
proto.getIsCurrencyForTakerFeeBtc(),
storage,
btcWalletService);
trade.setTradeAmountAsLong(proto.getTradeAmountAsLong());
trade.setTradePrice(proto.getTradePrice());
trade.setTradingPeerNodeAddress(NodeAddress.fromProto(proto.getTradingPeerNodeAddress()));
return Trade.fromProto(trade,
proto,
coreProtoResolver);
}

View File

@ -20,6 +20,7 @@ package io.bisq.core.trade;
import io.bisq.common.storage.Storage;
import io.bisq.core.btc.wallet.BtcWalletService;
import io.bisq.core.offer.Offer;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.core.trade.protocol.SellerAsTakerProtocol;
import io.bisq.core.trade.protocol.TakerProtocol;
import io.bisq.generated.protobuffer.PB;
@ -65,13 +66,22 @@ public final class SellerAsTakerTrade extends SellerTrade implements TakerTrade
.setSellerAsTakerTrade(PB.SellerAsTakerTrade.newBuilder().setTrade((PB.Trade) super.toProtoMessage())).build();
}
public static Tradable fromProto(PB.SellerAsTakerTrade proto, Storage<? extends TradableList> storage,
BtcWalletService btcWalletService) {
PB.Trade trade = proto.getTrade();
return new SellerAsTakerTrade(Offer.fromProto(trade.getOffer()), Coin.valueOf(trade.getTradeAmountAsLong()),
Coin.valueOf(trade.getTxFeeAsLong()), Coin.valueOf(trade.getTakerFeeAsLong()),
trade.getIsCurrencyForTakerFeeBtc(), trade.getTradePrice(),
NodeAddress.fromProto(trade.getTradingPeerNodeAddress()), storage, btcWalletService);
public static Tradable fromProto(PB.SellerAsTakerTrade sellerAsTakerTradeProto,
Storage<? extends TradableList> storage,
BtcWalletService btcWalletService,
CoreProtoResolver coreProtoResolver) {
PB.Trade proto = sellerAsTakerTradeProto.getTrade();
return Trade.fromProto(new SellerAsTakerTrade(Offer.fromProto(proto.getOffer()),
Coin.valueOf(proto.getTradeAmountAsLong()),
Coin.valueOf(proto.getTxFeeAsLong()),
Coin.valueOf(proto.getTakerFeeAsLong()),
proto.getIsCurrencyForTakerFeeBtc(),
proto.getTradePrice(),
NodeAddress.fromProto(proto.getTradingPeerNodeAddress()),
storage,
btcWalletService),
proto,
coreProtoResolver);
}

View File

@ -23,7 +23,7 @@ import io.bisq.common.proto.persistable.PersistableEnvelope;
import io.bisq.common.storage.Storage;
import io.bisq.core.btc.wallet.BtcWalletService;
import io.bisq.core.offer.OpenOffer;
import io.bisq.core.proto.persistable.CorePersistenceProtoResolver;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.generated.protobuffer.PB;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
@ -40,10 +40,10 @@ import java.util.stream.Stream;
@Slf4j
public final class TradableList<T extends Tradable> implements PersistableEnvelope {
@Getter
private List<T> tradableList = new ArrayList<>();
private List<T> list = new ArrayList<>();
transient final private Storage<TradableList<T>> storage;
transient private ObservableList<T> observableList = FXCollections.observableArrayList(tradableList);
transient private ObservableList<T> observableList;
///////////////////////////////////////////////////////////////////////////////////////////
@ -55,7 +55,7 @@ public final class TradableList<T extends Tradable> implements PersistableEnvelo
TradableList<T> persisted = storage.initAndGetPersisted(this, fileName);
if (persisted != null)
tradableList = persisted.getTradableList();
list = persisted.getList();
}
@ -63,20 +63,20 @@ public final class TradableList<T extends Tradable> implements PersistableEnvelo
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
public TradableList(Storage<TradableList<T>> storage, List<T> tradableList) {
public TradableList(Storage<TradableList<T>> storage, List<T> list) {
this.storage = storage;
this.tradableList.addAll(tradableList);
this.list.addAll(list);
}
@Override
public Message toProtoMessage() {
return PB.PersistableEnvelope.newBuilder().setTradableList(PB.TradableList.newBuilder()
.addAllTradable(ProtoUtil.collectionToProto(tradableList))).build();
.addAllTradable(ProtoUtil.collectionToProto(list))).build();
}
@Nullable
public static TradableList fromProto(PB.TradableList proto,
CorePersistenceProtoResolver corePersistenceProtoResolver,
CoreProtoResolver coreProtoResolver,
Storage<TradableList<OpenOffer>> openOfferStorage,
Storage<TradableList<BuyerAsMakerTrade>> buyerAsMakerTradeStorage,
Storage<TradableList<BuyerAsTakerTrade>> buyerAsTakerTradeStorage,
@ -85,7 +85,7 @@ public final class TradableList<T extends Tradable> implements PersistableEnvelo
BtcWalletService btcWalletService) {
log.debug("TradableList fromProto of {} ", proto);
if (proto.getTradableList().size() == 0) {
return null;
return new TradableList<>(openOfferStorage, new ArrayList<>());
}
List list = proto.getTradableList().stream()
@ -96,85 +96,43 @@ public final class TradableList<T extends Tradable> implements PersistableEnvelo
case OPEN_OFFER:
return OpenOffer.fromProto(tradable.getOpenOffer());
case BUYER_AS_MAKER_TRADE:
return BuyerAsMakerTrade.fromProto(tradable.getBuyerAsMakerTrade(), buyerAsMakerTradeStorage, btcWalletService);
return BuyerAsMakerTrade.fromProto(tradable.getBuyerAsMakerTrade(), buyerAsMakerTradeStorage, btcWalletService, coreProtoResolver);
case BUYER_AS_TAKER_TRADE:
Tradable tradable1 = BuyerAsTakerTrade.fromProto(tradable.getBuyerAsTakerTrade(), buyerAsTakerTradeStorage, btcWalletService);
return tradable1;
return BuyerAsTakerTrade.fromProto(tradable.getBuyerAsTakerTrade(), buyerAsTakerTradeStorage, btcWalletService, coreProtoResolver);
case SELLER_AS_MAKER_TRADE:
return SellerAsMakerTrade.fromProto(tradable.getSellerAsMakerTrade(), sellerAsMakerTradeStorage, btcWalletService);
return SellerAsMakerTrade.fromProto(tradable.getSellerAsMakerTrade(), sellerAsMakerTradeStorage, btcWalletService, coreProtoResolver);
case SELLER_AS_TAKER_TRADE:
return SellerAsTakerTrade.fromProto(tradable.getSellerAsTakerTrade(), sellerAsTakerTradeStorage, btcWalletService);
return SellerAsTakerTrade.fromProto(tradable.getSellerAsTakerTrade(), sellerAsTakerTradeStorage, btcWalletService, coreProtoResolver);
}
return null;
})
.filter(e -> e != null)
.collect(Collectors.toList());
//TODO list.get(0) only works for offer/trade
switch (list.get(0).getClass().getSimpleName()) {
case "OpenOffer":
return new TradableList<OpenOffer>(openOfferStorage, list);
return new TradableList<>(openOfferStorage, list);
case "BuyerAsMakerTrade":
return new TradableList<BuyerAsMakerTrade>(buyerAsMakerTradeStorage, list);
return new TradableList<>(buyerAsMakerTradeStorage, list);
case "BuyerAsTakerTrade":
return new TradableList<BuyerAsTakerTrade>(buyerAsTakerTradeStorage, list);
return new TradableList<>(buyerAsTakerTradeStorage, list);
case "SellerAsMakerTrade":
return new TradableList<SellerAsMakerTrade>(sellerAsMakerTradeStorage, list);
return new TradableList<>(sellerAsMakerTradeStorage, list);
case "SellerAsTakerTrade":
return new TradableList<SellerAsTakerTrade>(sellerAsTakerTradeStorage, list);
return new TradableList<>(sellerAsTakerTradeStorage, list);
}
return null;
}
/* public static TradableList fromProto(PB.TradeList proto,
CorePersistenceProtoResolver corePersistenceProtoResolver,
Storage<TradableList<BuyerAsMakerTrade>> buyerAsMakerTradeStorage,
Storage<TradableList<BuyerAsTakerTrade>> buyerAsTakerTradeStorage,
Storage<TradableList<SellerAsMakerTrade>> sellerAsMakerTradeStorage,
Storage<TradableList<SellerAsTakerTrade>> sellerAsTakerTradeStorage,
BtcWalletService btcWalletService) {
log.error("fromProto " + proto);
List tradableList = proto.getTradeList().stream().map(trade -> {
// corePersistenceProtoResolver.fromProto(trade, st)
switch (trade.getMessageCase()) {
case OPEN_OFFER:
return OpenOffer.fromProto(trade.getOpenOffer());
case BUYER_AS_MAKER_TRADE:
return BuyerAsMakerTrade.fromProto(trade.getBuyerAsMakerTrade(), buyerAsMakerTradeStorage, btcWalletService);
case BUYER_AS_TAKER_TRADE:
return BuyerAsTakerTrade.fromProto(trade.getBuyerAsTakerTrade(), buyerAsTakerTradeStorage, btcWalletService);
case SELLER_AS_MAKER_TRADE:
return SellerAsMakerTrade.fromProto(trade.getSellerAsMakerTrade(), sellerAsMakerTradeStorage, btcWalletService);
case SELLER_AS_TAKER_TRADE:
return SellerAsTakerTrade.fromProto(trade.getSellerAsTakerTrade(), sellerAsTakerTradeStorage, btcWalletService);
}
return null;
}).collect(Collectors.toList());
switch (tradableList.get(0).getClass().getSimpleName()) {
case "OpenOffer":
return new TradableList<OpenOffer>(openOfferStorage, tradableList);
case "BuyerAsMakerTrade":
return new TradableList<BuyerAsMakerTrade>(buyerAsMakerTradeStorage, tradableList);
case "BuyerAsTakerTrade":
return new TradableList<BuyerAsTakerTrade>(buyerAsTakerTradeStorage, tradableList);
case "SellerAsMakerTrade":
return new TradableList<SellerAsMakerTrade>(sellerAsMakerTradeStorage, tradableList);
case "SellerAsTakerTrade":
return new TradableList<SellerAsTakerTrade>(sellerAsTakerTradeStorage, tradableList);
}
return null;
}*/
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
public boolean add(T tradable) {
boolean changed = tradableList.add(tradable);
boolean changed = list.add(tradable);
getObservableList().add(tradable);
if (changed)
storage.queueUpForSave();
@ -182,7 +140,7 @@ public final class TradableList<T extends Tradable> implements PersistableEnvelo
}
public boolean remove(T tradable) {
boolean changed = this.tradableList.remove(tradable);
boolean changed = this.list.remove(tradable);
getObservableList().remove(tradable);
if (changed)
storage.queueUpForSave();
@ -190,25 +148,25 @@ public final class TradableList<T extends Tradable> implements PersistableEnvelo
}
public Stream<T> stream() {
return this.tradableList.stream();
return this.list.stream();
}
public void forEach(Consumer<? super T> action) {
this.tradableList.forEach(action);
this.list.forEach(action);
}
public ObservableList<T> getObservableList() {
if (observableList == null)
observableList = FXCollections.observableArrayList(this.tradableList);
observableList = FXCollections.observableArrayList(this.list);
return observableList;
}
public int size() {
return tradableList.size();
return list.size();
}
public boolean contains(T thing) {
return tradableList.contains(thing);
return list.contains(thing);
}
}

View File

@ -28,6 +28,7 @@ import io.bisq.common.app.Log;
import io.bisq.common.crypto.KeyRing;
import io.bisq.common.monetary.Price;
import io.bisq.common.monetary.Volume;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.storage.Storage;
import io.bisq.common.taskrunner.Model;
import io.bisq.core.arbitration.Arbitrator;
@ -38,6 +39,7 @@ import io.bisq.core.btc.wallet.TradeWalletService;
import io.bisq.core.filter.FilterManager;
import io.bisq.core.offer.Offer;
import io.bisq.core.offer.OpenOfferManager;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.core.trade.protocol.ProcessModel;
import io.bisq.core.trade.protocol.TradeProtocol;
import io.bisq.core.user.User;
@ -158,6 +160,14 @@ public abstract class Trade implements Tradable, Model {
State(@NotNull Phase phase) {
this.phase = phase;
}
public static Trade.State fromProto(PB.Trade.State state) {
return ProtoUtil.enumFromProto(Trade.State.class, state.name());
}
public static PB.Trade.State toProtoMessage(Trade.State state) {
return PB.Trade.State.valueOf(state.name());
}
}
public enum Phase {
@ -168,20 +178,44 @@ public abstract class Trade implements Tradable, Model {
FIAT_SENT,
FIAT_RECEIVED,
PAYOUT_PUBLISHED,
WITHDRAWN
WITHDRAWN;
public static Trade.Phase fromProto(PB.Trade.Phase phase) {
return ProtoUtil.enumFromProto(Trade.Phase.class, phase.name());
}
public static PB.Trade.Phase toProtoMessage(Trade.Phase phase) {
return PB.Trade.Phase.valueOf(phase.name());
}
}
public enum DisputeState {
NO_DISPUTE,
DISPUTE_REQUESTED,
DISPUTE_STARTED_BY_PEER,
DISPUTE_CLOSED
DISPUTE_CLOSED;
public static Trade.DisputeState fromProto(PB.Trade.DisputeState disputeState) {
return ProtoUtil.enumFromProto(Trade.DisputeState.class, disputeState.name());
}
public static PB.Trade.DisputeState toProtoMessage(Trade.DisputeState disputeState) {
return PB.Trade.DisputeState.valueOf(disputeState.name());
}
}
public enum TradePeriodState {
FIRST_HALF,
SECOND_HALF,
TRADE_PERIOD_OVER
TRADE_PERIOD_OVER;
public static Trade.TradePeriodState fromProto(PB.Trade.TradePeriodState tradePeriodState) {
return ProtoUtil.enumFromProto(Trade.TradePeriodState.class, tradePeriodState.name());
}
public static PB.Trade.TradePeriodState toProtoMessage(Trade.TradePeriodState tradePeriodState) {
return PB.Trade.TradePeriodState.valueOf(tradePeriodState.name());
}
}
@ -199,9 +233,10 @@ public abstract class Trade implements Tradable, Model {
private final long txFeeAsLong;
@Getter
private final long takerFeeAsLong;
private final long takeOfferDate;
@Getter
private final ProcessModel processModel;
@Setter
private long takeOfferDate;
@Getter @Setter
private ProcessModel processModel;
// Mutable
@Nullable @Getter @Setter
@ -358,6 +393,30 @@ public abstract class Trade implements Tradable, Model {
return builder.build();
}
public static Trade fromProto(Trade trade, PB.Trade proto, CoreProtoResolver coreProtoResolver) {
trade.setTakeOfferDate(proto.getTakeOfferDate());
trade.setProcessModel(ProcessModel.fromProto(proto.getProcessModel(), coreProtoResolver));
trade.setState(State.fromProto(proto.getState()));
trade.setDisputeState(DisputeState.fromProto(proto.getDisputeState()));
trade.setTradePeriodState(TradePeriodState.fromProto(proto.getTradePeriodState()));
trade.setTakerFeeTxId(proto.getTakerFeeTxId().isEmpty() ? null : proto.getTakerFeeTxId());
trade.setDepositTxId(proto.getDepositTxId().isEmpty() ? null : proto.getDepositTxId());
trade.setPayoutTxId(proto.getPayoutTxId().isEmpty() ? null : proto.getPayoutTxId());
trade.setTradingPeerNodeAddress(NodeAddress.fromProto(proto.getTradingPeerNodeAddress()));
trade.setContract(Contract.fromProto(proto.getContract(), coreProtoResolver));
trade.setContractAsJson(proto.getContractAsJson().isEmpty() ? null : proto.getContractAsJson());
trade.setTakerContractSignature(proto.getTakerContractSignature().isEmpty() ? null : proto.getTakerContractSignature());
trade.setMakerContractSignature(proto.getMakerContractSignature().isEmpty() ? null : proto.getMakerContractSignature());
trade.setArbitratorNodeAddress(NodeAddress.fromProto(proto.getArbitratorNodeAddress()));
trade.setMediatorNodeAddress(NodeAddress.fromProto(proto.getMediatorNodeAddress()));
trade.setArbitratorBtcPubKey(proto.getArbitratorBtcPubKey().toByteArray());
trade.setTakerPaymentAccountId(proto.getTakerPaymentAccountId().isEmpty() ? null : proto.getTakerPaymentAccountId());
trade.setErrorMessage(proto.getErrorMessage().isEmpty() ? null : proto.getErrorMessage());
return trade;
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
@ -547,17 +606,19 @@ public abstract class Trade implements Tradable, Model {
public void setArbitratorNodeAddress(NodeAddress arbitratorNodeAddress) {
this.arbitratorNodeAddress = arbitratorNodeAddress;
Arbitrator arbitrator = processModel.getUser().getAcceptedArbitratorByAddress(arbitratorNodeAddress);
checkNotNull(arbitrator, "arbitrator must not be null");
arbitratorBtcPubKey = arbitrator.getBtcPubKey();
if (processModel.getUser() != null) {
Arbitrator arbitrator = processModel.getUser().getAcceptedArbitratorByAddress(arbitratorNodeAddress);
checkNotNull(arbitrator, "arbitrator must not be null");
arbitratorBtcPubKey = arbitrator.getBtcPubKey();
}
}
public void setMediatorNodeAddress(NodeAddress mediatorNodeAddress) {
this.mediatorNodeAddress = mediatorNodeAddress;
Mediator mediator = processModel.getUser().getAcceptedMediatorByAddress(mediatorNodeAddress);
checkNotNull(mediator, "mediator must not be null");
if (processModel.getUser() != null) {
Mediator mediator = processModel.getUser().getAcceptedMediatorByAddress(mediatorNodeAddress);
checkNotNull(mediator, "mediator must not be null");
}
}

View File

@ -19,10 +19,10 @@ package io.bisq.core.trade.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.proto.ProtoResolver;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.core.btc.data.RawTransactionInput;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
import lombok.EqualsAndHashCode;
@ -129,7 +129,7 @@ public final class PayDepositRequest extends TradeMessage {
return NetworkEnvelope.getDefaultBuilder().setPayDepositRequest(builder).build();
}
public static PayDepositRequest fromProto(PB.PayDepositRequest proto, ProtoResolver protoResolver) {
public static PayDepositRequest fromProto(PB.PayDepositRequest proto, CoreProtoResolver coreProtoResolver) {
List<RawTransactionInput> rawTransactionInputs = proto.getRawTransactionInputsList().stream()
.map(rawTransactionInput -> new RawTransactionInput(rawTransactionInput.getIndex(),
rawTransactionInput.getParentTransaction().toByteArray(), rawTransactionInput.getValue()))
@ -152,7 +152,7 @@ public final class PayDepositRequest extends TradeMessage {
proto.getTakerMultiSigPubKey().toByteArray(),
proto.getTakerPayoutAddressString(),
PubKeyRing.fromProto(proto.getTakerPubKeyRing()),
(PaymentAccountPayload) protoResolver.fromProto(proto.getTakerPaymentAccountPayload()),
coreProtoResolver.fromProto(proto.getTakerPaymentAccountPayload()),
proto.getTakerAccountId(),
proto.getTakerFeeTxId(),
arbitratorNodeAddresses,

View File

@ -18,10 +18,10 @@
package io.bisq.core.trade.messages;
import com.google.protobuf.ByteString;
import io.bisq.common.proto.ProtoResolver;
import io.bisq.common.proto.network.NetworkEnvelope;
import io.bisq.core.btc.data.RawTransactionInput;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.MailboxMessage;
import io.bisq.network.p2p.NodeAddress;
@ -91,7 +91,7 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
.build();
}
public static PublishDepositTxRequest fromProto(PB.PublishDepositTxRequest proto, ProtoResolver protoResolver) {
public static PublishDepositTxRequest fromProto(PB.PublishDepositTxRequest proto, CoreProtoResolver coreProtoResolver) {
List<RawTransactionInput> makerInputs = proto.getMakerInputsList().stream()
.map(rawTransactionInput -> new RawTransactionInput(rawTransactionInput.getIndex(),
rawTransactionInput.getParentTransaction().toByteArray(),
@ -99,7 +99,7 @@ public final class PublishDepositTxRequest extends TradeMessage implements Mailb
.collect(Collectors.toList());
return new PublishDepositTxRequest(proto.getTradeId(),
(PaymentAccountPayload) protoResolver.fromProto(proto.getMakerPaymentAccountPayload()),
coreProtoResolver.fromProto(proto.getMakerPaymentAccountPayload()),
proto.getMakerAccountId(),
proto.getMakerMultiSigPubKey().toByteArray(),
proto.getMakerContractAsJson(),

View File

@ -23,7 +23,6 @@ import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.proto.persistable.PersistablePayload;
import io.bisq.common.taskrunner.Model;
import io.bisq.common.util.Utilities;
import io.bisq.core.btc.data.RawTransactionInput;
import io.bisq.core.btc.wallet.BsqWalletService;
import io.bisq.core.btc.wallet.BtcWalletService;
@ -34,6 +33,7 @@ import io.bisq.core.offer.Offer;
import io.bisq.core.offer.OpenOfferManager;
import io.bisq.core.payment.PaymentAccount;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.core.trade.MakerTrade;
import io.bisq.core.trade.Trade;
import io.bisq.core.trade.TradeManager;
@ -54,9 +54,9 @@ import org.bitcoinj.core.Transaction;
import javax.annotation.Nullable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Getter
@Slf4j
@ -81,14 +81,18 @@ public class ProcessModel implements Model, PersistablePayload {
transient private DecryptedMessageWithPubKey decryptedMessageWithPubKey;
// Persistable Immutable
private final TradingPeer tradingPeer = new TradingPeer();
// Persistable Immutable (only set by PB)
@Setter
private TradingPeer tradingPeer = new TradingPeer();
@Setter
private String offerId;
@Setter
private String accountId;
@Setter
private PubKeyRing pubKeyRing;
// Persistable Mutable
@Nullable
@Nullable @Setter
private String takeOfferFeeTxId;
@Nullable @Setter
private byte[] payoutTxSignature;
@ -99,7 +103,7 @@ public class ProcessModel implements Model, PersistablePayload {
@Nullable @Setter
private byte[] preparedDepositTx;
@Nullable @Setter
private ArrayList<RawTransactionInput> rawTransactionInputs;
private List<RawTransactionInput> rawTransactionInputs;
@Setter
private long changeOutputValue;
@Nullable @Setter
@ -133,6 +137,7 @@ public class ProcessModel implements Model, PersistablePayload {
.setChangeOutputValue(changeOutputValue)
.setFundsNeededForTradeAsLong(fundsNeededForTradeAsLong)
.setUseSavingsWallet(useSavingsWallet);
Optional.ofNullable(takeOfferFeeTxId).ifPresent(builder::setTakeOfferFeeTxId);
Optional.ofNullable(payoutTxSignature).ifPresent(e -> builder.setPayoutTxSignature(ByteString.copyFrom(payoutTxSignature)));
Optional.ofNullable(takerAcceptedArbitratorNodeAddresses).ifPresent(e -> builder.addAllTakerAcceptedArbitratorNodeAddresses(ProtoUtil.collectionToProto(takerAcceptedArbitratorNodeAddresses)));
@ -146,6 +151,39 @@ public class ProcessModel implements Model, PersistablePayload {
}
public static ProcessModel fromProto(PB.ProcessModel proto, CoreProtoResolver coreProtoResolver) {
ProcessModel processModel = new ProcessModel();
processModel.setTradingPeer(TradingPeer.fromProto(proto.getTradingPeer(), coreProtoResolver));
processModel.setOfferId(proto.getOfferId());
processModel.setAccountId(proto.getAccountId());
processModel.setPubKeyRing(PubKeyRing.fromProto(proto.getPubKeyRing()));
processModel.setChangeOutputValue(proto.getChangeOutputValue());
processModel.setFundsNeededForTradeAsLong(proto.getFundsNeededForTradeAsLong());
processModel.setUseSavingsWallet(proto.getUseSavingsWallet());
// nullable
processModel.setTakeOfferFeeTxId(proto.getTakeOfferFeeTxId().isEmpty() ? null : proto.getTakeOfferFeeTxId());
processModel.setPayoutTxSignature(proto.getPayoutTxSignature().isEmpty() ? null : proto.getPayoutTxSignature().toByteArray());
List<NodeAddress> takerAcceptedArbitratorNodeAddresses = proto.getTakerAcceptedArbitratorNodeAddressesList().isEmpty() ?
null : proto.getTakerAcceptedArbitratorNodeAddressesList().stream()
.map(NodeAddress::fromProto).collect(Collectors.toList());
List<NodeAddress> takerAcceptedMediatorNodeAddresses = proto.getTakerAcceptedMediatorNodeAddressesList().isEmpty() ?
null : proto.getTakerAcceptedMediatorNodeAddressesList().stream()
.map(NodeAddress::fromProto).collect(Collectors.toList());
processModel.setTakerAcceptedArbitratorNodeAddresses(takerAcceptedArbitratorNodeAddresses);
processModel.setTakerAcceptedMediatorNodeAddresses(takerAcceptedMediatorNodeAddresses);
processModel.setPreparedDepositTx(proto.getPreparedDepositTx().isEmpty() ? null : proto.getPreparedDepositTx().toByteArray());
List<RawTransactionInput> rawTransactionInputs = proto.getRawTransactionInputsList().isEmpty() ?
null : proto.getRawTransactionInputsList().stream()
.map(RawTransactionInput::fromProto).collect(Collectors.toList());
processModel.setRawTransactionInputs(rawTransactionInputs);
processModel.setChangeOutputAddress(proto.getChangeOutputAddress().isEmpty() ? null : proto.getChangeOutputAddress());
processModel.setMyMultiSigPubKey(proto.getMyMultiSigPubKey().isEmpty() ? null : proto.getMyMultiSigPubKey().toByteArray());
processModel.setTempTradingPeerNodeAddress(NodeAddress.fromProto(proto.getTempTradingPeerNodeAddress()));
return processModel;
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -24,6 +24,7 @@ import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.proto.persistable.PersistablePayload;
import io.bisq.core.btc.data.RawTransactionInput;
import io.bisq.core.payment.payload.PaymentAccountPayload;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.generated.protobuffer.PB;
import lombok.Getter;
import lombok.Setter;
@ -32,6 +33,7 @@ import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Slf4j
@Getter
@ -78,4 +80,23 @@ public final class TradingPeer implements PersistablePayload {
Optional.ofNullable(changeOutputAddress).ifPresent(builder::setChangeOutputAddress);
return builder.build();
}
public static TradingPeer fromProto(PB.TradingPeer proto, CoreProtoResolver coreProtoResolver) {
TradingPeer tradingPeer = new TradingPeer();
tradingPeer.setChangeOutputValue(proto.getChangeOutputValue());
tradingPeer.setAccountId(proto.getAccountId().isEmpty() ? null : proto.getAccountId());
tradingPeer.setPaymentAccountPayload(coreProtoResolver.fromProto(proto.getPaymentAccountPayload()));
tradingPeer.setPayoutAddressString(proto.getPayoutAddressString().isEmpty() ? null : proto.getPayoutAddressString());
tradingPeer.setContractAsJson(proto.getContractAsJson().isEmpty() ? null : proto.getContractAsJson());
tradingPeer.setContractSignature(proto.getContractSignature().isEmpty() ? null : proto.getContractSignature());
tradingPeer.setSignature(proto.getSignature().isEmpty() ? null : proto.getSignature().toByteArray());
tradingPeer.setPubKeyRing(PubKeyRing.fromProto(proto.getPubKeyRing()));
tradingPeer.setMultiSigPubKey(proto.getMultiSigPubKey().isEmpty() ? null : proto.getMultiSigPubKey().toByteArray());
List<RawTransactionInput> rawTransactionInputs = proto.getRawTransactionInputsList().isEmpty() ?
null : proto.getRawTransactionInputsList().stream()
.map(RawTransactionInput::fromProto).collect(Collectors.toList());
tradingPeer.setRawTransactionInputs(rawTransactionInputs);
tradingPeer.setChangeOutputAddress(proto.getChangeOutputAddress().isEmpty() ? null : proto.getChangeOutputAddress());
return tradingPeer;
}
}

View File

@ -31,11 +31,12 @@ import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@Slf4j
public class BuyerAsTakerSignAndPublishDepositTx extends TradeTask {
@ -57,7 +58,7 @@ public class BuyerAsTakerSignAndPublishDepositTx extends TradeTask {
byte[] contractHash = Hash.getHash(trade.getContractAsJson());
trade.setContractHash(contractHash);
ArrayList<RawTransactionInput> buyerInputs = processModel.getRawTransactionInputs();
List<RawTransactionInput> buyerInputs = checkNotNull(processModel.getRawTransactionInputs(), "buyerInputs must not be null");
BtcWalletService walletService = processModel.getBtcWalletService();
String id = processModel.getOffer().getId();

View File

@ -31,11 +31,12 @@ import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@Slf4j
public class SellerAsTakerSignAndPublishDepositTx extends TradeTask {
@ -56,7 +57,7 @@ public class SellerAsTakerSignAndPublishDepositTx extends TradeTask {
byte[] contractHash = Hash.getHash(trade.getContractAsJson());
trade.setContractHash(contractHash);
ArrayList<RawTransactionInput> sellerInputs = processModel.getRawTransactionInputs();
List<RawTransactionInput> sellerInputs = checkNotNull(processModel.getRawTransactionInputs(), "sellerInputs must not be null");
BtcWalletService walletService = processModel.getBtcWalletService();
String id = processModel.getOffer().getId();

View File

@ -2,17 +2,15 @@ package io.bisq.core.user;
import com.google.common.collect.Maps;
import com.google.protobuf.Message;
import io.bisq.common.app.DevEnv;
import io.bisq.common.locale.*;
import io.bisq.common.proto.ProtoResolver;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.proto.persistable.PersistableEnvelope;
import io.bisq.core.btc.Restrictions;
import io.bisq.core.payment.PaymentAccount;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.generated.protobuffer.PB;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable;
@ -118,18 +116,26 @@ public final class PreferencesPayload implements PersistableEnvelope {
return PB.PersistableEnvelope.newBuilder().setPreferencesPayload(builder).build();
}
public static PersistableEnvelope fromProto(PB.PreferencesPayload proto, ProtoResolver protoResolver) {
PreferencesPayload preferences = new PreferencesPayload(
public static PersistableEnvelope fromProto(PB.PreferencesPayload proto, CoreProtoResolver coreProtoResolver) {
return new PreferencesPayload(
proto.getUserLanguage(),
new Country(proto.getUserCountry().getCode(), proto.getUserCountry().getName(), new Region(proto.getUserCountry().getRegion().getCode(), proto.getUserCountry().getRegion().getName())),
new Country(proto.getUserCountry().getCode(),
proto.getUserCountry().getName(),
new Region(proto.getUserCountry().getRegion().getCode(), proto.getUserCountry().getRegion().getName())),
proto.getBtcDenomination(),
proto.getUseAnimations(),
new BlockChainExplorer(proto.getBlockChainExplorerMainNet().getName(), proto.getBlockChainExplorerMainNet().getTxUrl(), proto.getBlockChainExplorerMainNet().getAddressUrl()),
new BlockChainExplorer(proto.getBlockChainExplorerTestNet().getName(), proto.getBlockChainExplorerTestNet().getTxUrl(), proto.getBlockChainExplorerTestNet().getAddressUrl()),
new BlockChainExplorer(proto.getBsqBlockChainExplorer().getName(), proto.getBsqBlockChainExplorer().getTxUrl(), proto.getBsqBlockChainExplorer().getAddressUrl()),
new BlockChainExplorer(proto.getBlockChainExplorerMainNet().getName(),
proto.getBlockChainExplorerMainNet().getTxUrl(),
proto.getBlockChainExplorerMainNet().getAddressUrl()),
new BlockChainExplorer(proto.getBlockChainExplorerTestNet().getName(),
proto.getBlockChainExplorerTestNet().getTxUrl(),
proto.getBlockChainExplorerTestNet().getAddressUrl()),
new BlockChainExplorer(proto.getBsqBlockChainExplorer().getName(),
proto.getBsqBlockChainExplorer().getTxUrl(),
proto.getBsqBlockChainExplorer().getAddressUrl()),
ProtoUtil.emptyStringToNull(proto.getBackupDirectory()),
proto.getAutoSelectArbitrators(),
Maps.newHashMap(proto.getDontShowAgainMapMap()), // proto returs an unmodifiable map by default
Maps.newHashMap(proto.getDontShowAgainMapMap()), // proto returns an unmodifiable map by default
proto.getTacAccepted(),
proto.getUseTorForBitcoinJ(),
proto.getShowOwnOffersInOfferBook(),
@ -150,10 +156,9 @@ public final class PreferencesPayload implements PersistableEnvelope {
proto.getDirectoryChooserPath(),
proto.getBuyerSecurityDepositAsLong(),
proto.getSelectedPaymentAccountForCreateOffer().hasPaymentMethod() ?
PaymentAccount.fromProto(proto.getSelectedPaymentAccountForCreateOffer(), protoResolver) :
PaymentAccount.fromProto(proto.getSelectedPaymentAccountForCreateOffer(), coreProtoResolver) :
null,
proto.getPayFeeInBtc(),
proto.getResyncSpvRequested());
return preferences;
}
}

View File

@ -17,7 +17,6 @@
package io.bisq.core.user;
import io.bisq.common.proto.ProtoResolver;
import io.bisq.common.proto.ProtoUtil;
import io.bisq.common.proto.persistable.PersistableEnvelope;
import io.bisq.core.alert.Alert;
@ -25,6 +24,7 @@ import io.bisq.core.arbitration.Arbitrator;
import io.bisq.core.arbitration.Mediator;
import io.bisq.core.filter.Filter;
import io.bisq.core.payment.PaymentAccount;
import io.bisq.core.proto.CoreProtoResolver;
import io.bisq.generated.protobuffer.PB;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -93,13 +93,13 @@ public class UserPayload implements PersistableEnvelope {
return PB.PersistableEnvelope.newBuilder().setUserPayload(builder).build();
}
public static UserPayload fromProto(PB.UserPayload proto, ProtoResolver resolver) {
public static UserPayload fromProto(PB.UserPayload proto, CoreProtoResolver coreProtoResolver) {
return new UserPayload(
proto.getAccountId().isEmpty() ? null : proto.getAccountId(),
proto.getPaymentAccountsList().isEmpty() ? null : proto.getPaymentAccountsList().stream()
.map(e -> PaymentAccount.fromProto(e, resolver))
.map(e -> PaymentAccount.fromProto(e, coreProtoResolver))
.collect(Collectors.toSet()),
proto.hasCurrentPaymentAccount() ? PaymentAccount.fromProto(proto.getCurrentPaymentAccount(), resolver) : null,
proto.hasCurrentPaymentAccount() ? PaymentAccount.fromProto(proto.getCurrentPaymentAccount(), coreProtoResolver) : null,
proto.getAcceptedLanguageLocaleCodesList().isEmpty() ? new ArrayList<>() : new ArrayList<>(proto.getAcceptedLanguageLocaleCodesList()),
proto.hasDevelopersAlert() ? Alert.fromProto(proto.getDevelopersAlert()) : null,
proto.hasDisplayedAlert() ? Alert.fromProto(proto.getDisplayedAlert()) : null,