Refactoring: move generic stuff to ProtoUtil (reuse for persist.)

This commit is contained in:
Manfred Karrer 2017-04-14 00:29:13 -05:00
parent c14a07abd4
commit 25337c3b7c
35 changed files with 529 additions and 593 deletions

View File

@ -22,8 +22,8 @@ import io.bisq.common.Clock;
import io.bisq.common.app.AppModule;
import io.bisq.common.crypto.KeyRing;
import io.bisq.common.crypto.KeyStorage;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import io.bisq.core.alert.AlertModule;
import io.bisq.core.app.BisqEnvironment;
@ -31,9 +31,9 @@ import io.bisq.core.arbitration.ArbitratorModule;
import io.bisq.core.btc.BitcoinModule;
import io.bisq.core.dao.DaoModule;
import io.bisq.core.filter.FilterModule;
import io.bisq.core.network.CoreNetworkProtoResolver;
import io.bisq.core.offer.OfferModule;
import io.bisq.core.persistence.CorePersistenceProtoResolver;
import io.bisq.core.proto.CoreNetworkProtoResolver;
import io.bisq.core.proto.CorePersistenceProtoResolver;
import io.bisq.core.trade.TradeModule;
import io.bisq.core.user.Preferences;
import io.bisq.core.user.User;

View File

@ -15,8 +15,9 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bisq.common.network;
package io.bisq.common.proto;
import io.bisq.common.network.Msg;
import io.bisq.generated.protobuffer.PB;
import java.util.Optional;

View File

@ -15,8 +15,9 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bisq.common.persistence;
package io.bisq.common.proto;
import io.bisq.common.persistence.Persistable;
import io.bisq.generated.protobuffer.PB;
import java.util.Optional;

View File

@ -20,7 +20,7 @@ package io.bisq.common.storage;
import io.bisq.common.UserThread;
import io.bisq.common.io.LookAheadObjectInputStream;
import io.bisq.common.persistence.Persistable;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.util.Utilities;
import io.bisq.generated.protobuffer.PB;
import org.slf4j.Logger;

View File

@ -19,7 +19,7 @@ package io.bisq.common.storage;
import com.google.inject.Inject;
import io.bisq.common.persistence.Persistable;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -28,7 +28,7 @@ import io.bisq.common.handlers.FaultHandler;
import io.bisq.common.handlers.ResultHandler;
import io.bisq.common.locale.Res;
import io.bisq.common.network.Msg;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import io.bisq.core.arbitration.messages.*;
import io.bisq.core.btc.AddressEntry;

View File

@ -28,7 +28,7 @@ import io.bisq.common.app.Log;
import io.bisq.common.handlers.ExceptionHandler;
import io.bisq.common.handlers.ResultHandler;
import io.bisq.common.persistence.LongPersistable;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.FileUtil;
import io.bisq.common.storage.Storage;
import io.bisq.core.app.BisqEnvironment;

View File

@ -19,7 +19,7 @@ package io.bisq.core.dao.blockchain;
import com.google.inject.Inject;
import io.bisq.common.handlers.ErrorMessageHandler;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import io.bisq.core.btc.wallet.WalletUtils;
import io.bisq.core.dao.RpcOptionKeys;

View File

@ -18,7 +18,7 @@
package io.bisq.core.dao.blockchain;
import io.bisq.common.persistence.Persistable;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import javafx.collections.FXCollections;
import javafx.collections.MapChangeListener;

View File

@ -26,7 +26,7 @@ import io.bisq.common.crypto.KeyRing;
import io.bisq.common.handlers.ErrorMessageHandler;
import io.bisq.common.handlers.ResultHandler;
import io.bisq.common.network.Msg;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import io.bisq.core.btc.AddressEntry;
import io.bisq.core.btc.wallet.BsqWalletService;

View File

@ -1,9 +1,9 @@
package io.bisq.core.persistence;
package io.bisq.core.proto;
import com.google.inject.Provider;
import io.bisq.common.locale.*;
import io.bisq.common.persistence.Persistable;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.core.btc.AddressEntry;
import io.bisq.core.btc.AddressEntryList;
import io.bisq.core.payment.PaymentAccount;

View File

@ -0,0 +1,129 @@
/*
* This file is part of bisq.
*
* bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bisq.core.proto;
import com.google.protobuf.ByteString;
import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.locale.CurrencyUtil;
import io.bisq.common.monetary.Price;
import io.bisq.core.arbitration.Dispute;
import io.bisq.core.filter.PaymentAccountFilter;
import io.bisq.core.payment.payload.BankAccountPayload;
import io.bisq.core.payment.payload.CountryBasedPaymentAccountPayload;
import io.bisq.core.trade.Contract;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.NodeAddress;
import org.bitcoinj.core.Coin;
import org.jetbrains.annotations.NotNull;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class ProtoUtil {
///////////////////////////////////////////////////////////////////////////////////////////
// Get Domain objects
///////////////////////////////////////////////////////////////////////////////////////////
static Dispute getDispute(PB.Dispute dispute) {
return new Dispute(dispute.getTradeId(), dispute.getTraderId(),
dispute.getDisputeOpenerIsBuyer(), dispute.getDisputeOpenerIsMaker(),
getPubKeyRing(dispute.getTraderPubKeyRing()), new Date(dispute.getTradeDate()), getContract(dispute.getContract()),
dispute.getContractHash().toByteArray(), dispute.getDepositTxSerialized().toByteArray(),
dispute.getPayoutTxSerialized().toByteArray(),
dispute.getDepositTxId(), dispute.getPayoutTxId(), dispute.getContractAsJson(), dispute.getMakerContractSignature(),
dispute.getTakerContractSignature(), getPubKeyRing(dispute.getArbitratorPubKeyRing()), dispute.getIsSupportTicket());
}
private static Contract getContract(PB.Contract contract) {
return new Contract(CoreNetworkProtoResolver.getOfferPayload(contract.getOfferPayload()),
Coin.valueOf(contract.getTradeAmount()),
Price.valueOf(getCurrencyCode(contract.getOfferPayload()), contract.getTradePrice()),
contract.getTakerFeeTxId(),
getNodeAddress(contract.getBuyerNodeAddress()),
getNodeAddress(contract.getSellerNodeAddress()),
getNodeAddress(contract.getArbitratorNodeAddress()),
getNodeAddress(contract.getMediatorNodeAddress()),
contract.getIsBuyerMakerAndSellerTaker(),
contract.getMakerAccountId(),
contract.getTakerAccountId(),
CoreNetworkProtoResolver.getPaymentAccountPayload(contract.getMakerPaymentAccountPayload()),
CoreNetworkProtoResolver.getPaymentAccountPayload(contract.getTakerPaymentAccountPayload()),
getPubKeyRing(contract.getMakerPubKeyRing()),
getPubKeyRing(contract.getTakerPubKeyRing()),
contract.getMakerPayoutAddressString(),
contract.getTakerPayoutAddressString(),
contract.getMakerBtcPubKey().toByteArray(),
contract.getTakerBtcPubKey().toByteArray());
}
@NotNull
static PubKeyRing getPubKeyRing(PB.PubKeyRing pubKeyRing) {
return new PubKeyRing(pubKeyRing.getSignaturePubKeyBytes().toByteArray(),
pubKeyRing.getEncryptionPubKeyBytes().toByteArray(),
pubKeyRing.getPgpPubKeyAsPem());
}
static NodeAddress getNodeAddress(PB.NodeAddress protoNode) {
return new NodeAddress(protoNode.getHostName(), protoNode.getPort());
}
static PaymentAccountFilter getPaymentAccountFilter(PB.PaymentAccountFilter accountFilter) {
return new PaymentAccountFilter(accountFilter.getPaymentMethodId(), accountFilter.getGetMethodName(),
accountFilter.getValue());
}
static Set<byte[]> getByteSet(List<ByteString> byteStringList) {
return new HashSet<>(
byteStringList
.stream()
.map(ByteString::toByteArray).collect(Collectors.toList()));
}
public static String getCurrencyCode(PB.OfferPayload pbOffer) {
String currencyCode;
if (CurrencyUtil.isCryptoCurrency(pbOffer.getBaseCurrencyCode()))
currencyCode = pbOffer.getBaseCurrencyCode();
else
currencyCode = pbOffer.getCounterCurrencyCode();
return currencyCode;
}
///////////////////////////////////////////////////////////////////////////////////////////
// PaymentAccountPayload Utils
///////////////////////////////////////////////////////////////////////////////////////////
static void fillInBankAccountPayload(PB.PaymentAccountPayload protoEntry, BankAccountPayload bankAccountPayload) {
PB.BankAccountPayload bankProto = protoEntry.getCountryBasedPaymentAccountPayload().getBankAccountPayload();
bankAccountPayload.setHolderName(bankProto.getHolderName());
bankAccountPayload.setBankName(bankProto.getBankName());
bankAccountPayload.setBankId(bankProto.getBankId());
bankAccountPayload.setBranchId(bankProto.getBranchId());
bankAccountPayload.setAccountNr(bankProto.getAccountNr());
bankAccountPayload.setAccountType(bankProto.getAccountType());
}
static void fillInCountryBasedPaymentAccountPayload(PB.PaymentAccountPayload protoEntry,
CountryBasedPaymentAccountPayload countryBasedPaymentAccountPayload) {
countryBasedPaymentAccountPayload.setCountryCode(protoEntry.getCountryBasedPaymentAccountPayload().getCountryCode());
}
}

View File

@ -25,7 +25,7 @@ import io.bisq.common.handlers.ErrorMessageHandler;
import io.bisq.common.handlers.FaultHandler;
import io.bisq.common.handlers.ResultHandler;
import io.bisq.common.network.Msg;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import io.bisq.core.btc.AddressEntry;
import io.bisq.core.btc.AddressEntryException;

View File

@ -19,7 +19,7 @@ package io.bisq.core.trade.closed;
import com.google.inject.Inject;
import io.bisq.common.crypto.KeyRing;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import io.bisq.core.offer.Offer;
import io.bisq.core.provider.price.PriceFeedService;

View File

@ -19,7 +19,7 @@ package io.bisq.core.trade.failed;
import com.google.inject.Inject;
import io.bisq.common.crypto.KeyRing;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import io.bisq.core.offer.Offer;
import io.bisq.core.provider.price.PriceFeedService;

View File

@ -22,8 +22,8 @@ import io.bisq.common.Clock;
import io.bisq.common.app.AppModule;
import io.bisq.common.crypto.KeyRing;
import io.bisq.common.crypto.KeyStorage;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import io.bisq.core.alert.AlertModule;
import io.bisq.core.app.BisqEnvironment;
@ -31,9 +31,9 @@ import io.bisq.core.arbitration.ArbitratorModule;
import io.bisq.core.btc.BitcoinModule;
import io.bisq.core.dao.DaoModule;
import io.bisq.core.filter.FilterModule;
import io.bisq.core.network.CoreNetworkProtoResolver;
import io.bisq.core.offer.OfferModule;
import io.bisq.core.persistence.CorePersistenceProtoResolver;
import io.bisq.core.proto.CoreNetworkProtoResolver;
import io.bisq.core.proto.CorePersistenceProtoResolver;
import io.bisq.core.trade.TradeModule;
import io.bisq.core.user.Preferences;
import io.bisq.core.user.User;

View File

@ -21,7 +21,7 @@ import com.google.inject.Inject;
import io.bisq.common.locale.CryptoCurrency;
import io.bisq.common.locale.FiatCurrency;
import io.bisq.common.locale.TradeCurrency;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.core.offer.OpenOfferManager;
import io.bisq.core.payment.CryptoCurrencyAccount;
import io.bisq.core.payment.PaymentAccount;

View File

@ -21,7 +21,7 @@ import com.google.inject.Inject;
import io.bisq.common.locale.CryptoCurrency;
import io.bisq.common.locale.FiatCurrency;
import io.bisq.common.locale.TradeCurrency;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.core.offer.OpenOfferManager;
import io.bisq.core.payment.CryptoCurrencyAccount;
import io.bisq.core.payment.PaymentAccount;

View File

@ -28,7 +28,7 @@ import io.bisq.common.locale.CurrencyUtil;
import io.bisq.common.locale.Res;
import io.bisq.common.locale.TradeCurrency;
import io.bisq.common.persistence.ListPersistable;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import io.bisq.common.util.Utilities;
import io.bisq.core.payment.PaymentAccount;

View File

@ -21,7 +21,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
import io.bisq.common.Marshaller;
import io.bisq.common.crypto.*;
import io.bisq.common.network.Msg;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.p2p.DecryptedMsgWithPubKey;
import lombok.extern.slf4j.Slf4j;

View File

@ -13,8 +13,8 @@ import io.bisq.common.crypto.CryptoException;
import io.bisq.common.crypto.KeyRing;
import io.bisq.common.crypto.PubKeyRing;
import io.bisq.common.network.Msg;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.FileUtil;
import io.bisq.common.storage.Storage;
import io.bisq.common.util.Utilities;

View File

@ -8,7 +8,7 @@ import io.bisq.common.app.DevEnv;
import io.bisq.common.app.Log;
import io.bisq.common.app.Version;
import io.bisq.common.network.Msg;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.common.util.Tuple2;
import io.bisq.common.util.Utilities;
import io.bisq.generated.protobuffer.PB;

View File

@ -1,6 +1,6 @@
package io.bisq.network.p2p.network;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import java.net.Socket;

View File

@ -8,7 +8,7 @@ import com.msopentech.thali.java.toronionproxy.JavaOnionProxyContext;
import com.msopentech.thali.java.toronionproxy.JavaOnionProxyManager;
import io.bisq.common.UserThread;
import io.bisq.common.app.Log;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.common.util.Utilities;
import io.bisq.network.p2p.NodeAddress;
import io.nucleo.net.HiddenServiceDescriptor;

View File

@ -5,7 +5,7 @@ import com.runjva.sourceforge.jsocks.protocol.Socks5Proxy;
import io.bisq.common.UserThread;
import io.bisq.common.app.Log;
import io.bisq.common.network.Msg;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.common.util.Utilities;
import io.bisq.network.p2p.NodeAddress;
import javafx.beans.property.ObjectProperty;

View File

@ -1,6 +1,6 @@
package io.bisq.network.p2p.network;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.network.p2p.NodeAddress;
import java.net.Socket;

View File

@ -1,7 +1,7 @@
package io.bisq.network.p2p.network;
import io.bisq.common.app.Log;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -10,7 +10,7 @@ import com.runjva.sourceforge.jsocks.protocol.Socks5Proxy;
import io.bisq.common.Timer;
import io.bisq.common.UserThread;
import io.bisq.common.app.Log;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.common.util.Utilities;
import io.bisq.network.p2p.NodeAddress;
import io.bisq.network.p2p.Utils;

View File

@ -5,7 +5,7 @@ import io.bisq.common.Timer;
import io.bisq.common.UserThread;
import io.bisq.common.app.Log;
import io.bisq.common.persistence.HashSetPersistable;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import io.bisq.network.p2p.NodeAddress;
import io.bisq.network.p2p.network.*;

View File

@ -11,7 +11,7 @@ import io.bisq.common.crypto.Sig;
import io.bisq.common.network.Msg;
import io.bisq.common.persistence.HashMapPersistable;
import io.bisq.common.persistence.Persistable;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.FileUtil;
import io.bisq.common.storage.ResourceNotFoundException;
import io.bisq.common.storage.Storage;

View File

@ -3,9 +3,9 @@ package io.bisq.network.p2p;
import io.bisq.common.Clock;
import io.bisq.common.crypto.KeyRing;
import io.bisq.common.network.Msg;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.persistence.Persistable;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.generated.protobuffer.PB;
import io.bisq.network.crypto.EncryptionService;
import io.bisq.network.p2p.seed.SeedNodesRepository;

View File

@ -3,8 +3,8 @@ package io.bisq.network.p2p.storage;
import io.bisq.common.crypto.CryptoException;
import io.bisq.common.crypto.KeyRing;
import io.bisq.common.crypto.KeyStorage;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.FileUtil;
import io.bisq.network.crypto.EncryptionService;
import io.bisq.network.p2p.NodeAddress;

View File

@ -22,8 +22,8 @@ import io.bisq.common.Clock;
import io.bisq.common.app.AppModule;
import io.bisq.common.crypto.KeyRing;
import io.bisq.common.crypto.KeyStorage;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import io.bisq.core.alert.AlertModule;
import io.bisq.core.app.BisqEnvironment;
@ -31,9 +31,9 @@ import io.bisq.core.arbitration.ArbitratorModule;
import io.bisq.core.btc.BitcoinModule;
import io.bisq.core.dao.DaoModule;
import io.bisq.core.filter.FilterModule;
import io.bisq.core.network.CoreNetworkProtoResolver;
import io.bisq.core.offer.OfferModule;
import io.bisq.core.persistence.CorePersistenceProtoResolver;
import io.bisq.core.proto.CoreNetworkProtoResolver;
import io.bisq.core.proto.CorePersistenceProtoResolver;
import io.bisq.core.trade.TradeModule;
import io.bisq.core.user.Preferences;
import io.bisq.core.user.User;

View File

@ -22,8 +22,8 @@ import io.bisq.common.Clock;
import io.bisq.common.app.AppModule;
import io.bisq.common.crypto.KeyRing;
import io.bisq.common.crypto.KeyStorage;
import io.bisq.common.network.NetworkProtoResolver;
import io.bisq.common.persistence.PersistenceProtoResolver;
import io.bisq.common.proto.NetworkProtoResolver;
import io.bisq.common.proto.PersistenceProtoResolver;
import io.bisq.common.storage.Storage;
import io.bisq.core.alert.AlertModule;
import io.bisq.core.app.BisqEnvironment;
@ -31,9 +31,9 @@ import io.bisq.core.arbitration.ArbitratorModule;
import io.bisq.core.btc.BitcoinModule;
import io.bisq.core.dao.DaoModule;
import io.bisq.core.filter.FilterModule;
import io.bisq.core.network.CoreNetworkProtoResolver;
import io.bisq.core.offer.OfferModule;
import io.bisq.core.persistence.CorePersistenceProtoResolver;
import io.bisq.core.proto.CoreNetworkProtoResolver;
import io.bisq.core.proto.CorePersistenceProtoResolver;
import io.bisq.core.trade.TradeModule;
import io.bisq.core.user.Preferences;
import io.bisq.core.user.User;