mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 02:12:00 +01:00
Rename openOffers to openOfferList in OpenOffer. Fix comments. Remove unused stuff,...
This commit is contained in:
parent
53494b08b8
commit
e8d2b54d3e
@ -18,14 +18,9 @@
|
||||
package io.bisq.common;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface Marshaller extends Serializable {
|
||||
default Message toProto() {
|
||||
throw new NotImplementedException("toProtobuf not yet implemented.");
|
||||
}
|
||||
//Object fromProto();
|
||||
|
||||
Message toProto();
|
||||
}
|
||||
|
@ -1,14 +1,9 @@
|
||||
package io.bisq.common.persistence;
|
||||
|
||||
import com.google.protobuf.Parser;
|
||||
import io.bisq.common.Marshaller;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
|
||||
/**
|
||||
* Marker interface for data which is used for local data persistence
|
||||
*/
|
||||
public interface Persistable extends Marshaller {
|
||||
default Parser getParser() {
|
||||
throw new NotImplementedException("Protobuf getParser not yet implemented.");
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class ProtoHelper {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static Iterable collectionToProto(Collection<? extends Marshaller> collection) {
|
||||
return collection.stream().map(o -> o.toProto()).collect(Collectors.toList());
|
||||
return collection.stream().map(Marshaller::toProto).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static <T> Iterable<T> collectionToProto(Collection<? extends Marshaller> collection, Function<? super Message, T> extra) {
|
||||
|
@ -113,7 +113,7 @@ public class FileManager<T extends Persistable> {
|
||||
try (final FileInputStream fileInputStream = new FileInputStream(file)) {
|
||||
persistable = persistenceProtoResolver.fromProto(PB.DiskEnvelope.parseDelimitedFrom(fileInputStream));
|
||||
} catch (Throwable t) {
|
||||
log.warn("Exception at proto read: " + t.getMessage() + " " + file.getName());
|
||||
log.error("Exception at proto read: " + t.getMessage() + " " + file.getName());
|
||||
}
|
||||
|
||||
if (persistable.isPresent()) {
|
||||
|
@ -177,7 +177,7 @@ public class Storage<T extends Persistable> {
|
||||
|
||||
return persistedObject;
|
||||
} catch (Throwable t) {
|
||||
log.error("Version of persisted class has changed. We cannot read the persisted data anymore. " +
|
||||
log.error("We cannot read the persisted data. " +
|
||||
"We make a backup and remove the inconsistent file. fileName=" + fileName);
|
||||
log.error(t.getMessage());
|
||||
try {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.bisq.core.offer;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import io.bisq.common.crypto.KeyRing;
|
||||
import io.bisq.common.crypto.PubKeyRing;
|
||||
import io.bisq.common.handlers.ErrorMessageHandler;
|
||||
@ -29,7 +28,6 @@ import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.utils.Fiat;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Date;
|
||||
|
@ -48,18 +48,8 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
public final class OfferPayload implements StoragePayload, RequiresOwnerIsOnlinePayload {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Static
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//TODO remove once PB work is completed
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
@JsonExclude
|
||||
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
|
||||
|
||||
public static final long TTL = TimeUnit.MINUTES.toMillis(DevEnv.STRESS_TEST_MODE ? 6 : 6);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Enums
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -264,6 +254,10 @@ public final class OfferPayload implements StoragePayload, RequiresOwnerIsOnline
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public PB.StoragePayload toProto() {
|
||||
List<PB.NodeAddress> arbitratorNodeAddresses = this.arbitratorNodeAddresses.stream()
|
||||
|
@ -20,7 +20,6 @@ package io.bisq.core.offer;
|
||||
import com.google.protobuf.Message;
|
||||
import io.bisq.common.Timer;
|
||||
import io.bisq.common.UserThread;
|
||||
import io.bisq.common.app.Version;
|
||||
import io.bisq.common.storage.Storage;
|
||||
import io.bisq.core.trade.Tradable;
|
||||
import io.bisq.core.trade.TradableList;
|
||||
@ -29,15 +28,11 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
@EqualsAndHashCode
|
||||
@Slf4j
|
||||
public final class OpenOffer implements Tradable {
|
||||
// That object is saved to disc. We need to take care of changes to not break deserialization.
|
||||
private static final long serialVersionUID = Version.LOCAL_DB_VERSION;
|
||||
|
||||
// Timeout for offer reservation during takeoffer process. If deposit tx is not completed in that time we reset the offer to AVAILABLE state.
|
||||
private static final long TIMEOUT_SEC = 30;
|
||||
transient private Timer timeoutTimer;
|
||||
@ -61,6 +56,32 @@ public final class OpenOffer implements Tradable {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public Message toProto() {
|
||||
final PB.OpenOffer build = PB.OpenOffer.newBuilder()
|
||||
.setOffer(offer.toProto())
|
||||
.setState(PB.OpenOffer.State.valueOf(state.name()))
|
||||
.build();
|
||||
return build;
|
||||
}
|
||||
|
||||
public static Tradable fromProto(PB.OpenOffer proto, Storage<TradableList<OpenOffer>> storage) {
|
||||
OpenOffer openOffer = new OpenOffer(Offer.fromProto(proto.getOffer()), storage);
|
||||
// If we have a reserved state from the local db we reset it
|
||||
if (openOffer.getState() == State.RESERVED)
|
||||
openOffer.setState(State.AVAILABLE);
|
||||
return openOffer;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public Date getDate() {
|
||||
return offer.getDate();
|
||||
}
|
||||
@ -117,20 +138,5 @@ public final class OpenOffer implements Tradable {
|
||||
"\n\tstate=" + state +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message toProto() {
|
||||
return PB.OpenOffer.newBuilder().setOffer(offer.toProto())
|
||||
.setState(PB.OpenOffer.State.valueOf(state.name())).build();
|
||||
}
|
||||
|
||||
// TODO set storage
|
||||
public static Tradable fromProto(PB.OpenOffer proto, Storage<TradableList<OpenOffer>> storage) {
|
||||
OpenOffer openOffer = new OpenOffer(Offer.fromProto(proto.getOffer()), storage);
|
||||
// If we have a reserved state from the local db we reset it
|
||||
if (openOffer.getState() == State.RESERVED)
|
||||
openOffer.setState(State.AVAILABLE);
|
||||
return openOffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
private final ClosedTradableManager closedTradableManager;
|
||||
private final Preferences preferences;
|
||||
|
||||
private final TradableList<OpenOffer> openOffers;
|
||||
private final TradableList<OpenOffer> openOfferList;
|
||||
private final Storage<TradableList<OpenOffer>> openOffersStorage;
|
||||
private boolean stopped;
|
||||
private Timer periodicRepublishOffersTimer, periodicRefreshOffersTimer, retryRepublishOffersTimer;
|
||||
@ -114,8 +114,8 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
this.preferences = preferences;
|
||||
|
||||
openOffersStorage = new Storage<>(storageDir, persistenceProtoResolver);
|
||||
openOffers = new TradableList<>(openOffersStorage, "OpenOffers");
|
||||
openOffers.forEach(e -> e.getOffer().setPriceFeedService(priceFeedService));
|
||||
openOfferList = new TradableList<>(openOffersStorage, "OpenOffers");
|
||||
openOfferList.forEach(e -> e.getOffer().setPriceFeedService(priceFeedService));
|
||||
|
||||
// In case the app did get killed the shutDown from the modules is not called, so we use a shutdown hook
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
@ -155,9 +155,9 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
// we remove own offers from offerbook when we go offline
|
||||
// Normally we use a delay for broadcasting to the peers, but at shut down we want to get it fast out
|
||||
|
||||
final int size = openOffers.size();
|
||||
final int size = openOfferList.size();
|
||||
if (offerBookService.isBootstrapped()) {
|
||||
openOffers.forEach(openOffer -> offerBookService.removeOfferAtShutDown(openOffer.getOffer().getOfferPayload()));
|
||||
openOfferList.forEach(openOffer -> offerBookService.removeOfferAtShutDown(openOffer.getOffer().getOfferPayload()));
|
||||
if (completeHandler != null)
|
||||
UserThread.runAfter(completeHandler::run, size * 200 + 500, TimeUnit.MILLISECONDS);
|
||||
} else {
|
||||
@ -167,7 +167,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
}
|
||||
|
||||
public void removeAllOpenOffers(@Nullable Runnable completeHandler) {
|
||||
removeOpenOffers(getOpenOffers(), completeHandler);
|
||||
removeOpenOffers(getOpenOfferList(), completeHandler);
|
||||
}
|
||||
|
||||
public void removeOpenOffers(List<OpenOffer> openOffers, @Nullable Runnable completeHandler) {
|
||||
@ -276,7 +276,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
model,
|
||||
transaction -> {
|
||||
OpenOffer openOffer = new OpenOffer(offer, openOffersStorage);
|
||||
openOffers.add(openOffer);
|
||||
openOfferList.add(openOffer);
|
||||
openOffersStorage.queueUpForSave();
|
||||
resultHandler.handleResult(transaction);
|
||||
if (!stopped) {
|
||||
@ -312,7 +312,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
() -> {
|
||||
offer.setState(Offer.State.REMOVED);
|
||||
openOffer.setState(OpenOffer.State.CANCELED);
|
||||
openOffers.remove(openOffer);
|
||||
openOfferList.remove(openOffer);
|
||||
closedTradableManager.add(openOffer);
|
||||
walletService.swapTradeEntryToAvailableEntry(offer.getId(), AddressEntry.Context.OFFER_FUNDING);
|
||||
walletService.swapTradeEntryToAvailableEntry(offer.getId(), AddressEntry.Context.RESERVED_FOR_TRADE);
|
||||
@ -324,7 +324,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
// Close openOffer after deposit published
|
||||
public void closeOpenOffer(Offer offer) {
|
||||
findOpenOffer(offer.getId()).ifPresent(openOffer -> {
|
||||
openOffers.remove(openOffer);
|
||||
openOfferList.remove(openOffer);
|
||||
openOffer.setState(OpenOffer.State.CLOSED);
|
||||
offerBookService.removeOffer(openOffer.getOffer().getOfferPayload(),
|
||||
() -> log.trace("Successful removed offer"),
|
||||
@ -345,16 +345,16 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
return offer.isMyOffer(keyRing);
|
||||
}
|
||||
|
||||
public ObservableList<OpenOffer> getOpenOffers() {
|
||||
return openOffers.getObservableList();
|
||||
public ObservableList<OpenOffer> getOpenOfferList() {
|
||||
return openOfferList.getObservableList();
|
||||
}
|
||||
|
||||
public Optional<OpenOffer> findOpenOffer(String offerId) {
|
||||
return openOffers.stream().filter(openOffer -> openOffer.getId().equals(offerId)).findAny();
|
||||
return openOfferList.stream().filter(openOffer -> openOffer.getId().equals(offerId)).findAny();
|
||||
}
|
||||
|
||||
public Optional<OpenOffer> getOpenOfferById(String offerId) {
|
||||
return openOffers.stream().filter(e -> e.getId().equals(offerId)).findFirst();
|
||||
return openOfferList.stream().filter(e -> e.getId().equals(offerId)).findFirst();
|
||||
}
|
||||
|
||||
|
||||
@ -444,8 +444,8 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void republishOffers() {
|
||||
int size = openOffers.size();
|
||||
final ArrayList<OpenOffer> openOffersList = new ArrayList<>(openOffers.getList());
|
||||
int size = openOfferList.size();
|
||||
final ArrayList<OpenOffer> openOffersList = new ArrayList<>(openOfferList.getList());
|
||||
Log.traceCall("Number of offer for republish: " + size);
|
||||
if (!stopped) {
|
||||
stopPeriodicRefreshOffersTimer();
|
||||
@ -457,7 +457,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
final long maxDelay = (i + 2) * delay;
|
||||
final OpenOffer openOffer = openOffersList.get(i);
|
||||
UserThread.runAfterRandomDelay(() -> {
|
||||
if (openOffers.contains(openOffer)) {
|
||||
if (openOfferList.contains(openOffer)) {
|
||||
// The openOffer.getId().contains("_") check is because there was once a version
|
||||
// where we encoded the version nr in the offer id with a "_" as separator.
|
||||
// That caused several issues and was reverted. So if there are still old offers out with that
|
||||
@ -527,11 +527,11 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
if (periodicRefreshOffersTimer == null)
|
||||
periodicRefreshOffersTimer = UserThread.runPeriodically(() -> {
|
||||
if (!stopped) {
|
||||
int size = openOffers.size();
|
||||
int size = openOfferList.size();
|
||||
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<>(openOffers.getList());
|
||||
final ArrayList<OpenOffer> openOffersList = new ArrayList<>(openOfferList.getList());
|
||||
for (int i = 0; i < size; i++) {
|
||||
// we delay to avoid reaching throttle limits
|
||||
// roughly 4 offers per second
|
||||
@ -542,7 +542,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||
final OpenOffer openOffer = openOffersList.get(i);
|
||||
UserThread.runAfterRandomDelay(() -> {
|
||||
// we need to check if in the meantime the offer has been removed
|
||||
if (openOffers.contains(openOffer))
|
||||
if (openOfferList.contains(openOffer))
|
||||
refreshOffer(openOffer);
|
||||
}, minDelay, maxDelay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
@ -58,21 +60,18 @@ public class CoreDiskProtoResolver implements PersistenceProtoResolver {
|
||||
@Inject
|
||||
public CoreDiskProtoResolver(Provider<Preferences> preferencesProvider,
|
||||
Provider<AddressEntryList> addressEntryListProvider,
|
||||
Storage<TradableList<OpenOffer>> openOfferStorage,
|
||||
Storage<TradableList<BuyerAsMakerTrade>> buyerAsMakerTradeStorage,
|
||||
Storage<TradableList<BuyerAsTakerTrade>> buyerAsTakerTradeStorage,
|
||||
Storage<TradableList<SellerAsMakerTrade>> sellerAsMakerTradeStorage,
|
||||
Storage<TradableList<SellerAsTakerTrade>> sellerAsTakerTradeStorage,
|
||||
Provider<BtcWalletService> btcWalletService
|
||||
Provider<BtcWalletService> btcWalletService,
|
||||
@Named(Storage.STORAGE_DIR) File storageDir
|
||||
) {
|
||||
this.preferencesProvider = preferencesProvider;
|
||||
this.addressEntryListProvider = addressEntryListProvider;
|
||||
this.openOfferStorage = openOfferStorage;
|
||||
this.buyerAsMakerTradeStorage = buyerAsMakerTradeStorage;
|
||||
this.buyerAsTakerTradeStorage = buyerAsTakerTradeStorage;
|
||||
this.sellerAsMakerTradeStorage = sellerAsMakerTradeStorage;
|
||||
this.sellerAsTakerTradeStorage = sellerAsTakerTradeStorage;
|
||||
this.btcWalletService = btcWalletService;
|
||||
|
||||
openOfferStorage = new Storage<>(storageDir, this);
|
||||
buyerAsMakerTradeStorage = new Storage<>(storageDir, this);
|
||||
buyerAsTakerTradeStorage = new Storage<>(storageDir, this);
|
||||
sellerAsMakerTradeStorage = new Storage<>(storageDir, this);
|
||||
sellerAsTakerTradeStorage = new Storage<>(storageDir, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -124,11 +123,11 @@ public class CoreDiskProtoResolver implements PersistenceProtoResolver {
|
||||
|
||||
private Persistable getTradeStatisticsList(PB.TradeStatisticsList tradeStatisticsList) {
|
||||
return new ListPersistable<>(tradeStatisticsList.getTradeStatisticsList().stream()
|
||||
.map(tradeStatistics -> TradeStatistics.fromProto(tradeStatistics)).collect(Collectors.toList()));
|
||||
.map(TradeStatistics::fromProto).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
private Persistable getPeersList(PB.PeersList envelope) {
|
||||
return new ListPersistable<>(envelope.getPeersList().stream().map(peer -> Peer.fromProto(peer))
|
||||
return new ListPersistable<>(envelope.getPeersList().stream().map(Peer::fromProto)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
package io.bisq.core.trade;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import io.bisq.common.app.Version;
|
||||
import io.bisq.common.persistence.Persistable;
|
||||
import io.bisq.common.proto.ProtoHelper;
|
||||
import io.bisq.common.storage.Storage;
|
||||
@ -28,8 +27,7 @@ import io.bisq.generated.protobuffer.PB;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import lombok.Getter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -37,20 +35,14 @@ import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Slf4j
|
||||
public final class TradableList<T extends Tradable> implements Persistable {
|
||||
// That object is saved to disc. We need to take care of changes to not break deserialization.
|
||||
private static final long serialVersionUID = Version.LOCAL_DB_VERSION;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TradableList.class);
|
||||
|
||||
transient final private Storage<TradableList<T>> storage;
|
||||
// Use getObservableList() also class locally, to be sure that object exists in case we use the object as deserialized form
|
||||
transient private ObservableList<T> observableList;
|
||||
|
||||
@Getter
|
||||
private List<T> list = new ArrayList<>();
|
||||
|
||||
// Superclass is ArrayList, which will be persisted
|
||||
transient final private Storage<TradableList<T>> storage;
|
||||
transient private ObservableList<T> observableList = FXCollections.observableArrayList(list);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
@ -59,19 +51,72 @@ public final class TradableList<T extends Tradable> implements Persistable {
|
||||
public TradableList(Storage<TradableList<T>> storage, String fileName) {
|
||||
this.storage = storage;
|
||||
|
||||
TradableList<T> persisted = storage.initAndGetPersisted(this, fileName);
|
||||
if (persisted != null) {
|
||||
// TradableList<T> persisted = storage.initAndGetPersisted(this, fileName);
|
||||
TradableList<T> persisted = storage.initAndGetPersistedWithFileName(fileName);
|
||||
if (persisted != null)
|
||||
list.addAll(persisted.getList());
|
||||
}
|
||||
observableList = FXCollections.observableArrayList(list);
|
||||
}
|
||||
|
||||
public TradableList(Storage<TradableList<T>> storage, List<T> list) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private TradableList(Storage<TradableList<T>> storage, List<T> list) {
|
||||
this.storage = storage;
|
||||
list.addAll(list);
|
||||
observableList = FXCollections.observableArrayList(list);
|
||||
this.list.addAll(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message toProto() {
|
||||
return PB.DiskEnvelope.newBuilder().setTradableList(PB.TradableList.newBuilder()
|
||||
.addAllTradable(ProtoHelper.collectionToProto(list))).build();
|
||||
}
|
||||
|
||||
public static TradableList fromProto(PB.TradableList proto,
|
||||
Storage<TradableList<OpenOffer>> openOfferStorage,
|
||||
Storage<TradableList<BuyerAsMakerTrade>> buyerAsMakerTradeStorage,
|
||||
Storage<TradableList<BuyerAsTakerTrade>> buyerAsTakerTradeStorage,
|
||||
Storage<TradableList<SellerAsMakerTrade>> sellerAsMakerTradeStorage,
|
||||
Storage<TradableList<SellerAsTakerTrade>> sellerAsTakerTradeStorage,
|
||||
BtcWalletService btcWalletService) {
|
||||
List list = proto.getTradableList().stream().map(tradable -> {
|
||||
switch (tradable.getMessageCase()) {
|
||||
case OPEN_OFFER:
|
||||
return OpenOffer.fromProto(tradable.getOpenOffer(), openOfferStorage);
|
||||
case BUYER_AS_MAKER_TRADE:
|
||||
return BuyerAsMakerTrade.fromProto(tradable.getBuyerAsMakerTrade(), buyerAsMakerTradeStorage, btcWalletService);
|
||||
case BUYER_AS_TAKER_TRADE:
|
||||
return BuyerAsTakerTrade.fromProto(tradable.getBuyerAsTakerTrade(), buyerAsTakerTradeStorage, btcWalletService);
|
||||
case SELLER_AS_MAKER_TRADE:
|
||||
return SellerAsMakerTrade.fromProto(tradable.getSellerAsMakerTrade(), sellerAsMakerTradeStorage, btcWalletService);
|
||||
case SELLER_AS_TAKER_TRADE:
|
||||
return SellerAsTakerTrade.fromProto(tradable.getSellerAsTakerTrade(), sellerAsTakerTradeStorage, btcWalletService);
|
||||
}
|
||||
return null;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
switch (list.get(0).getClass().getSimpleName()) {
|
||||
case "OpenOffer":
|
||||
return new TradableList<OpenOffer>(openOfferStorage, list);
|
||||
case "BuyerAsMakerTrade":
|
||||
return new TradableList<BuyerAsMakerTrade>(buyerAsMakerTradeStorage, list);
|
||||
case "BuyerAsTakerTrade":
|
||||
return new TradableList<BuyerAsTakerTrade>(buyerAsTakerTradeStorage, list);
|
||||
case "SellerAsMakerTrade":
|
||||
return new TradableList<SellerAsMakerTrade>(sellerAsMakerTradeStorage, list);
|
||||
case "SellerAsTakerTrade":
|
||||
return new TradableList<SellerAsTakerTrade>(sellerAsTakerTradeStorage, list);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public boolean add(T tradable) {
|
||||
boolean changed = list.add(tradable);
|
||||
getObservableList().add(tradable);
|
||||
@ -80,7 +125,7 @@ public final class TradableList<T extends Tradable> implements Persistable {
|
||||
return changed;
|
||||
}
|
||||
|
||||
public boolean remove(Object tradable) {
|
||||
public boolean remove(T tradable) {
|
||||
boolean changed = list.remove(tradable);
|
||||
getObservableList().remove(tradable);
|
||||
if (changed)
|
||||
@ -110,47 +155,4 @@ public final class TradableList<T extends Tradable> implements Persistable {
|
||||
public boolean contains(T thing) {
|
||||
return list.contains(thing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message toProto() {
|
||||
return PB.DiskEnvelope.newBuilder().setTradableList(PB.TradableList.newBuilder()
|
||||
.addAllTradable(ProtoHelper.collectionToProto(list))).build();
|
||||
}
|
||||
|
||||
public static TradableList fromProto(PB.TradableList proto, Storage<TradableList<OpenOffer>> openOfferStorage,
|
||||
Storage<TradableList<BuyerAsMakerTrade>> buyerAsMakerTradeStorage,
|
||||
Storage<TradableList<BuyerAsTakerTrade>> buyerAsTakerTradeStorage,
|
||||
Storage<TradableList<SellerAsMakerTrade>> sellerAsMakerTradeStorage,
|
||||
Storage<TradableList<SellerAsTakerTrade>> sellerAsTakerTradeStorage,
|
||||
BtcWalletService btcWalletService) {
|
||||
List collect = proto.getTradableList().stream().map(tradable -> {
|
||||
switch (tradable.getMessageCase()) {
|
||||
case OPEN_OFFER:
|
||||
return OpenOffer.fromProto(tradable.getOpenOffer(), openOfferStorage);
|
||||
case BUYER_AS_MAKER_TRADE:
|
||||
return BuyerAsMakerTrade.fromProto(tradable.getBuyerAsMakerTrade(), buyerAsMakerTradeStorage, btcWalletService);
|
||||
case BUYER_AS_TAKER_TRADE:
|
||||
return BuyerAsTakerTrade.fromProto(tradable.getBuyerAsTakerTrade(), buyerAsTakerTradeStorage, btcWalletService);
|
||||
case SELLER_AS_MAKER_TRADE:
|
||||
return SellerAsMakerTrade.fromProto(tradable.getSellerAsMakerTrade(), sellerAsMakerTradeStorage, btcWalletService);
|
||||
case SELLER_AS_TAKER_TRADE:
|
||||
return SellerAsTakerTrade.fromProto(tradable.getSellerAsTakerTrade(), sellerAsTakerTradeStorage, btcWalletService);
|
||||
}
|
||||
return null;
|
||||
}).collect(Collectors.toList());
|
||||
switch (collect.get(0).getClass().getSimpleName()) {
|
||||
case "OpenOffer":
|
||||
return new TradableList<OpenOffer>(openOfferStorage, collect);
|
||||
case "BuyerAsMakerTrade":
|
||||
return new TradableList<BuyerAsMakerTrade>(buyerAsMakerTradeStorage, collect);
|
||||
case "BuyerAsTakerTrade":
|
||||
return new TradableList<BuyerAsTakerTrade>(buyerAsTakerTradeStorage, collect);
|
||||
case "SellerAsMakerTrade":
|
||||
return new TradableList<SellerAsMakerTrade>(sellerAsMakerTradeStorage, collect);
|
||||
case "SellerAsTakerTrade":
|
||||
return new TradableList<SellerAsTakerTrade>(sellerAsTakerTradeStorage, collect);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.bisq.core.user;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import com.google.protobuf.Parser;
|
||||
import io.bisq.common.GlobalSettings;
|
||||
import io.bisq.common.app.DevEnv;
|
||||
import io.bisq.common.app.Version;
|
||||
@ -694,9 +693,4 @@ public final class Preferences implements Persistable {
|
||||
account -> builder.setSelectedPaymentAccountForCreateOffer(selectedPaymentAccountForCreateOffer.toProto()));
|
||||
return PB.DiskEnvelope.newBuilder().setPreferences(builder).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parser getParser() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -540,7 +540,7 @@ public class MainViewModel implements ViewModel {
|
||||
}
|
||||
});
|
||||
|
||||
openOfferManager.getOpenOffers().addListener((ListChangeListener<OpenOffer>) c -> updateBalance());
|
||||
openOfferManager.getOpenOfferList().addListener((ListChangeListener<OpenOffer>) c -> updateBalance());
|
||||
tradeManager.getTrades().addListener((ListChangeListener<Trade>) c -> updateBalance());
|
||||
openOfferManager.onAllServicesInitialized();
|
||||
arbitratorManager.onAllServicesInitialized();
|
||||
@ -651,7 +651,7 @@ public class MainViewModel implements ViewModel {
|
||||
}
|
||||
|
||||
private void checkIfOpenOffersMatchTradeProtocolVersion() {
|
||||
List<OpenOffer> outDatedOffers = openOfferManager.getOpenOffers()
|
||||
List<OpenOffer> outDatedOffers = openOfferManager.getOpenOfferList()
|
||||
.stream()
|
||||
.filter(e -> e.getOffer().getProtocolVersion() != Version.TRADE_PROTOCOL_VERSION)
|
||||
.collect(Collectors.toList());
|
||||
@ -953,7 +953,7 @@ public class MainViewModel implements ViewModel {
|
||||
}
|
||||
|
||||
private void updateReservedBalance() {
|
||||
Coin sum = Coin.valueOf(openOfferManager.getOpenOffers().stream()
|
||||
Coin sum = Coin.valueOf(openOfferManager.getOpenOfferList().stream()
|
||||
.map(openOffer -> {
|
||||
Address address = btcWalletService.getOrCreateAddressEntry(openOffer.getId(), AddressEntry.Context.RESERVED_FOR_TRADE).getAddress();
|
||||
return btcWalletService.getBalanceForAddress(address);
|
||||
|
@ -107,7 +107,7 @@ class AltCoinAccountsDataModel extends ActivatableDataModel {
|
||||
}
|
||||
|
||||
public boolean onDeleteAccount(PaymentAccount paymentAccount) {
|
||||
boolean isPaymentAccountUsed = openOfferManager.getOpenOffers().stream()
|
||||
boolean isPaymentAccountUsed = openOfferManager.getOpenOfferList().stream()
|
||||
.filter(o -> o.getOffer().getMakerPaymentAccountId().equals(paymentAccount.getId()))
|
||||
.findAny()
|
||||
.isPresent();
|
||||
|
@ -108,7 +108,7 @@ class FiatAccountsDataModel extends ActivatableDataModel {
|
||||
}
|
||||
|
||||
public boolean onDeleteAccount(PaymentAccount paymentAccount) {
|
||||
boolean isPaymentAccountUsed = openOfferManager.getOpenOffers().stream()
|
||||
boolean isPaymentAccountUsed = openOfferManager.getOpenOfferList().stream()
|
||||
.filter(o -> o.getOffer().getMakerPaymentAccountId().equals(paymentAccount.getId()))
|
||||
.findAny()
|
||||
.isPresent();
|
||||
|
@ -127,7 +127,7 @@ public class LockedView extends ActivatableView<VBox, Void> {
|
||||
|
||||
@Override
|
||||
protected void activate() {
|
||||
openOfferManager.getOpenOffers().addListener(openOfferListChangeListener);
|
||||
openOfferManager.getOpenOfferList().addListener(openOfferListChangeListener);
|
||||
tradeManager.getTrades().addListener(tradeListChangeListener);
|
||||
sortedList.comparatorProperty().bind(tableView.comparatorProperty());
|
||||
tableView.setItems(sortedList);
|
||||
@ -138,7 +138,7 @@ public class LockedView extends ActivatableView<VBox, Void> {
|
||||
|
||||
@Override
|
||||
protected void deactivate() {
|
||||
openOfferManager.getOpenOffers().removeListener(openOfferListChangeListener);
|
||||
openOfferManager.getOpenOfferList().removeListener(openOfferListChangeListener);
|
||||
tradeManager.getTrades().removeListener(tradeListChangeListener);
|
||||
sortedList.comparatorProperty().unbind();
|
||||
observableList.forEach(LockedListItem::cleanup);
|
||||
|
@ -127,7 +127,7 @@ public class ReservedView extends ActivatableView<VBox, Void> {
|
||||
|
||||
@Override
|
||||
protected void activate() {
|
||||
openOfferManager.getOpenOffers().addListener(openOfferListChangeListener);
|
||||
openOfferManager.getOpenOfferList().addListener(openOfferListChangeListener);
|
||||
tradeManager.getTrades().addListener(tradeListChangeListener);
|
||||
sortedList.comparatorProperty().bind(tableView.comparatorProperty());
|
||||
tableView.setItems(sortedList);
|
||||
@ -138,7 +138,7 @@ public class ReservedView extends ActivatableView<VBox, Void> {
|
||||
|
||||
@Override
|
||||
protected void deactivate() {
|
||||
openOfferManager.getOpenOffers().removeListener(openOfferListChangeListener);
|
||||
openOfferManager.getOpenOfferList().removeListener(openOfferListChangeListener);
|
||||
tradeManager.getTrades().removeListener(tradeListChangeListener);
|
||||
sortedList.comparatorProperty().unbind();
|
||||
observableList.forEach(ReservedListItem::cleanup);
|
||||
@ -152,7 +152,7 @@ public class ReservedView extends ActivatableView<VBox, Void> {
|
||||
|
||||
private void updateList() {
|
||||
observableList.forEach(ReservedListItem::cleanup);
|
||||
observableList.setAll(openOfferManager.getOpenOffers().stream()
|
||||
observableList.setAll(openOfferManager.getOpenOfferList().stream()
|
||||
.map(openOffer -> new ReservedListItem(openOffer,
|
||||
walletService.getOrCreateAddressEntry(openOffer.getId(), AddressEntry.Context.RESERVED_FOR_TRADE),
|
||||
walletService,
|
||||
|
@ -264,7 +264,7 @@ public class TransactionsView extends ActivatableView<VBox, Void> {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void updateList() {
|
||||
Stream<Tradable> concat1 = Stream.concat(openOfferManager.getOpenOffers().stream(), tradeManager.getTrades().stream());
|
||||
Stream<Tradable> concat1 = Stream.concat(openOfferManager.getOpenOfferList().stream(), tradeManager.getTrades().stream());
|
||||
Stream<Tradable> concat2 = Stream.concat(concat1, closedTradableManager.getClosedTrades().stream());
|
||||
Stream<Tradable> concat3 = Stream.concat(concat2, failedTradesManager.getFailedTrades().stream());
|
||||
Set<Tradable> all = concat3.collect(Collectors.toSet());
|
||||
|
@ -193,21 +193,18 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||
UserThread.runAfter(() -> {
|
||||
amount.set("0.001");
|
||||
minAmount.set(amount.get());
|
||||
UserThread.runAfter(() -> {
|
||||
price.set("0.001");
|
||||
onFocusOutPriceAsPercentageTextField(true, false);
|
||||
applyMakerFee();
|
||||
}, 200, TimeUnit.MILLISECONDS);
|
||||
|
||||
price.set("0.001");
|
||||
onFocusOutPriceAsPercentageTextField(true, false);
|
||||
applyMakerFee();
|
||||
updateButtonDisableState();
|
||||
setAmountToModel();
|
||||
setMinAmountToModel();
|
||||
setPriceToModel();
|
||||
dataModel.calculateVolume();
|
||||
|
||||
dataModel.calculateTotalToPay();
|
||||
updateButtonDisableState();
|
||||
updateSpinnerInfo();
|
||||
}, 10, TimeUnit.MILLISECONDS);
|
||||
}, 100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
addBindings();
|
||||
|
@ -149,7 +149,7 @@ public class EmptyWalletWindow extends Overlay<EmptyWalletWindow> {
|
||||
}
|
||||
|
||||
private void doEmptyWallet(KeyParameter aesKey) {
|
||||
if (!openOfferManager.getOpenOffers().isEmpty()) {
|
||||
if (!openOfferManager.getOpenOfferList().isEmpty()) {
|
||||
UserThread.runAfter(() ->
|
||||
new Popup<>().warning(Res.get("emptyWalletWindow.openOffers.warn"))
|
||||
.actionButtonText(Res.get("emptyWalletWindow.openOffers.yes"))
|
||||
|
@ -52,14 +52,14 @@ class OpenOffersDataModel extends ActivatableDataModel {
|
||||
|
||||
@Override
|
||||
protected void activate() {
|
||||
openOfferManager.getOpenOffers().addListener(tradesListChangeListener);
|
||||
openOfferManager.getOpenOfferList().addListener(tradesListChangeListener);
|
||||
priceFeedService.currenciesUpdateFlagProperty().addListener(currenciesUpdateFlagPropertyListener);
|
||||
applyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void deactivate() {
|
||||
openOfferManager.getOpenOffers().removeListener(tradesListChangeListener);
|
||||
openOfferManager.getOpenOfferList().removeListener(tradesListChangeListener);
|
||||
priceFeedService.currenciesUpdateFlagProperty().removeListener(currenciesUpdateFlagPropertyListener);
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ class OpenOffersDataModel extends ActivatableDataModel {
|
||||
private void applyList() {
|
||||
list.clear();
|
||||
|
||||
list.addAll(openOfferManager.getOpenOffers().stream().map(OpenOfferListItem::new).collect(Collectors.toList()));
|
||||
list.addAll(openOfferManager.getOpenOfferList().stream().map(OpenOfferListItem::new).collect(Collectors.toList()));
|
||||
|
||||
// we sort by date, earliest first
|
||||
list.sort((o1, o2) -> o2.getOffer().getDate().compareTo(o1.getOffer().getDate()));
|
||||
|
Loading…
Reference in New Issue
Block a user