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);
}
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();
}
}
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 + ".");
}
}
}
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());
}
Aggregations