Search in sources :

Example 1 with Storage

use of bisq.common.storage.Storage in project bisq-core by bisq-network.

the class TradableList method fromProto.

@Nullable
public static TradableList fromProto(PB.TradableList proto, CoreProtoResolver coreProtoResolver, Storage<TradableList<Tradable>> storage, BtcWalletService btcWalletService) {
    log.debug("TradableList fromProto of {} ", proto);
    List<Tradable> list = proto.getTradableList().stream().map(tradable -> {
        switch(tradable.getMessageCase()) {
            case OPEN_OFFER:
                return OpenOffer.fromProto(tradable.getOpenOffer());
            case BUYER_AS_MAKER_TRADE:
                return BuyerAsMakerTrade.fromProto(tradable.getBuyerAsMakerTrade(), storage, btcWalletService, coreProtoResolver);
            case BUYER_AS_TAKER_TRADE:
                return BuyerAsTakerTrade.fromProto(tradable.getBuyerAsTakerTrade(), storage, btcWalletService, coreProtoResolver);
            case SELLER_AS_MAKER_TRADE:
                return SellerAsMakerTrade.fromProto(tradable.getSellerAsMakerTrade(), storage, btcWalletService, coreProtoResolver);
            case SELLER_AS_TAKER_TRADE:
                return SellerAsTakerTrade.fromProto(tradable.getSellerAsTakerTrade(), storage, btcWalletService, coreProtoResolver);
            default:
                log.error("Unknown messageCase. tradable.getMessageCase() = " + tradable.getMessageCase());
                throw new ProtobufferException("Unknown messageCase. tradable.getMessageCase() = " + tradable.getMessageCase());
        }
    }).collect(Collectors.toList());
    return new TradableList<>(storage, list);
}
Also used : BtcWalletService(bisq.core.btc.wallet.BtcWalletService) ProtoUtil(bisq.common.proto.ProtoUtil) PersistableEnvelope(bisq.common.proto.persistable.PersistableEnvelope) Getter(lombok.Getter) OpenOffer(bisq.core.offer.OpenOffer) FXCollections(javafx.collections.FXCollections) Collectors(java.util.stream.Collectors) ProtobufferException(bisq.common.proto.ProtobufferException) ArrayList(java.util.ArrayList) CoreProtoResolver(bisq.core.proto.CoreProtoResolver) Consumer(java.util.function.Consumer) PB(io.bisq.generated.protobuffer.PB) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Storage(bisq.common.storage.Storage) Message(com.google.protobuf.Message) ObservableList(javafx.collections.ObservableList) Nullable(javax.annotation.Nullable) ProtobufferException(bisq.common.proto.ProtobufferException) Nullable(javax.annotation.Nullable)

Example 2 with Storage

use of bisq.common.storage.Storage in project bisq-desktop by bisq-network.

the class GUIUtil method exportAccounts.

public static void exportAccounts(ArrayList<PaymentAccount> accounts, String fileName, Preferences preferences, Stage stage, PersistenceProtoResolver persistenceProtoResolver) {
    if (!accounts.isEmpty()) {
        String directory = getDirectoryFromChooser(preferences, stage);
        if (directory != null && !directory.isEmpty()) {
            Storage<PersistableList<PaymentAccount>> paymentAccountsStorage = new Storage<>(new File(directory), persistenceProtoResolver);
            paymentAccountsStorage.initAndGetPersisted(new PaymentAccountList(accounts), fileName, 100);
            paymentAccountsStorage.queueUpForSave();
            new Popup<>().feedback(Res.get("guiUtil.accountExport.savedToPath", Paths.get(directory, fileName).toAbsolutePath())).show();
        }
    } else {
        new Popup<>().warning(Res.get("guiUtil.accountExport.noAccountSetup")).show();
    }
}
Also used : PaymentAccountList(bisq.core.payment.PaymentAccountList) Storage(bisq.common.storage.Storage) PersistableList(bisq.common.proto.persistable.PersistableList) Popup(bisq.desktop.main.overlays.popups.Popup) File(java.io.File)

Example 3 with Storage

use of bisq.common.storage.Storage in project bisq-desktop by bisq-network.

the class GUIUtil method importAccounts.

public static void importAccounts(User user, String fileName, Preferences preferences, Stage stage, PersistenceProtoResolver persistenceProtoResolver) {
    FileChooser fileChooser = new FileChooser();
    File initDir = new File(preferences.getDirectoryChooserPath());
    if (initDir.isDirectory()) {
        fileChooser.setInitialDirectory(initDir);
    }
    fileChooser.setTitle(Res.get("guiUtil.accountExport.selectPath", fileName));
    File file = fileChooser.showOpenDialog(stage.getOwner());
    if (file != null) {
        String path = file.getAbsolutePath();
        if (Paths.get(path).getFileName().toString().equals(fileName)) {
            String directory = Paths.get(path).getParent().toString();
            preferences.setDirectoryChooserPath(directory);
            Storage<PaymentAccountList> paymentAccountsStorage = new Storage<>(new File(directory), persistenceProtoResolver);
            PaymentAccountList persisted = paymentAccountsStorage.initAndGetPersistedWithFileName(fileName, 100);
            if (persisted != null) {
                final StringBuilder msg = new StringBuilder();
                persisted.getList().stream().forEach(paymentAccount -> {
                    final String id = paymentAccount.getId();
                    if (user.getPaymentAccount(id) == null) {
                        user.addPaymentAccount(paymentAccount);
                        msg.append(Res.get("guiUtil.accountExport.tradingAccount", id));
                    } else {
                        msg.append(Res.get("guiUtil.accountImport.noImport", id));
                    }
                });
                new Popup<>().feedback(Res.get("guiUtil.accountImport.imported", path, msg)).show();
            } else {
                new Popup<>().warning(Res.get("guiUtil.accountImport.noAccountsFound", path, fileName)).show();
            }
        } else {
            log.error("The selected file is not the expected file for import. The expected file name is: " + fileName + ".");
        }
    }
}
Also used : PaymentAccountList(bisq.core.payment.PaymentAccountList) Storage(bisq.common.storage.Storage) Popup(bisq.desktop.main.overlays.popups.Popup) FileChooser(javafx.stage.FileChooser) File(java.io.File)

Example 4 with Storage

use of bisq.common.storage.Storage in project bisq-core by bisq-network.

the class TradableListTest method protoTesting.

@Test
public void protoTesting(@Mocked OfferPayload offerPayload) {
    Storage<TradableList<OpenOffer>> storage = new Storage<>(null, null);
    TradableList<OpenOffer> openOfferTradableList = new TradableList<>(storage, "filename");
    PB.PersistableEnvelope message = (PB.PersistableEnvelope) openOfferTradableList.toProtoMessage();
    assertTrue(message.getMessageCase().equals(TRADABLE_LIST));
    // test adding an OpenOffer and convert toProto
    Offer offer = new Offer(offerPayload);
    OpenOffer openOffer = new OpenOffer(offer, storage);
    // openOfferTradableList = new TradableList<OpenOffer>(storage,Lists.newArrayList(openOffer));
    openOfferTradableList.add(openOffer);
    message = (PB.PersistableEnvelope) openOfferTradableList.toProtoMessage();
    assertTrue(message.getMessageCase().equals(TRADABLE_LIST));
    assertEquals(1, message.getTradableList().getTradableList().size());
}
Also used : PB(io.bisq.generated.protobuffer.PB) Storage(bisq.common.storage.Storage) Offer(bisq.core.offer.Offer) OpenOffer(bisq.core.offer.OpenOffer) OpenOffer(bisq.core.offer.OpenOffer) Test(org.junit.Test)

Aggregations

Storage (bisq.common.storage.Storage)4 OpenOffer (bisq.core.offer.OpenOffer)2 PaymentAccountList (bisq.core.payment.PaymentAccountList)2 Popup (bisq.desktop.main.overlays.popups.Popup)2 PB (io.bisq.generated.protobuffer.PB)2 File (java.io.File)2 ProtoUtil (bisq.common.proto.ProtoUtil)1 ProtobufferException (bisq.common.proto.ProtobufferException)1 PersistableEnvelope (bisq.common.proto.persistable.PersistableEnvelope)1 PersistableList (bisq.common.proto.persistable.PersistableList)1 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)1 Offer (bisq.core.offer.Offer)1 CoreProtoResolver (bisq.core.proto.CoreProtoResolver)1 Message (com.google.protobuf.Message)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 FXCollections (javafx.collections.FXCollections)1