Search in sources :

Example 11 with Storage

use of com.sparrowwallet.sparrow.io.Storage in project sparrow by sparrowwallet.

the class SendController method addChildWallets.

public List<Wallet> addChildWallets(PaymentCode externalPaymentCode, PayNym payNym) {
    List<Wallet> addedWallets = new ArrayList<>();
    Wallet masterWallet = getWalletForm().getMasterWallet();
    Storage storage = AppServices.get().getOpenWallets().get(masterWallet);
    List<ScriptType> scriptTypes = PayNym.getSegwitScriptTypes();
    for (ScriptType childScriptType : scriptTypes) {
        String label = (payNym == null ? externalPaymentCode.toAbbreviatedString() : payNym.nymName()) + " " + childScriptType.getName();
        Wallet addedWallet = masterWallet.addChildWallet(externalPaymentCode, childScriptType, label);
        if (!storage.isPersisted(addedWallet)) {
            try {
                storage.saveWallet(addedWallet);
            } catch (Exception e) {
                log.error("Error saving wallet", e);
                AppServices.showErrorDialog("Error saving wallet " + addedWallet.getName(), e.getMessage());
            }
        }
        addedWallets.add(addedWallet);
    }
    return addedWallets;
}
Also used : ScriptType(com.sparrowwallet.drongo.protocol.ScriptType) Storage(com.sparrowwallet.sparrow.io.Storage) SecureString(com.sparrowwallet.drongo.SecureString) InvalidAddressException(com.sparrowwallet.drongo.address.InvalidAddressException) IOException(java.io.IOException)

Example 12 with Storage

use of com.sparrowwallet.sparrow.io.Storage in project sparrow by sparrowwallet.

the class CoinTreeTable method getDefaultPlaceholder.

protected Node getDefaultPlaceholder(Wallet wallet) {
    StackPane stackPane = new StackPane();
    stackPane.getChildren().add(AppServices.isConnecting() ? new Label("Loading transactions...") : new Label("No transactions"));
    if (Config.get().getServerType() == ServerType.BITCOIN_CORE && !AppServices.isConnecting()) {
        Hyperlink hyperlink = new Hyperlink();
        hyperlink.setTranslateY(30);
        hyperlink.setOnAction(event -> {
            WalletBirthDateDialog dlg = new WalletBirthDateDialog(wallet.getBirthDate());
            Optional<Date> optDate = dlg.showAndWait();
            if (optDate.isPresent()) {
                Storage storage = AppServices.get().getOpenWallets().get(wallet);
                Wallet pastWallet = wallet.copy();
                wallet.setBirthDate(optDate.get());
                // Trigger background save of birthdate
                EventManager.get().post(new WalletDataChangedEvent(wallet));
                // Trigger full wallet rescan
                wallet.clearHistory();
                EventManager.get().post(new WalletHistoryClearedEvent(wallet, pastWallet, storage.getWalletId(wallet)));
            }
        });
        if (wallet.getBirthDate() == null) {
            hyperlink.setText("Scan for previous transactions?");
        } else {
            DateFormat dateFormat = new SimpleDateFormat(DateStringConverter.FORMAT_PATTERN);
            hyperlink.setText("Scan for transactions earlier than " + dateFormat.format(wallet.getBirthDate()) + "?");
        }
        stackPane.getChildren().add(hyperlink);
    }
    stackPane.setAlignment(Pos.CENTER);
    return stackPane;
}
Also used : WalletHistoryClearedEvent(com.sparrowwallet.sparrow.event.WalletHistoryClearedEvent) Storage(com.sparrowwallet.sparrow.io.Storage) Wallet(com.sparrowwallet.drongo.wallet.Wallet) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Label(javafx.scene.control.Label) WalletDataChangedEvent(com.sparrowwallet.sparrow.event.WalletDataChangedEvent) SimpleDateFormat(java.text.SimpleDateFormat) StackPane(javafx.scene.layout.StackPane) Date(java.util.Date) Hyperlink(javafx.scene.control.Hyperlink)

Aggregations

Storage (com.sparrowwallet.sparrow.io.Storage)12 SecureString (com.sparrowwallet.drongo.SecureString)8 PaymentCode (com.sparrowwallet.drongo.bip47.PaymentCode)4 InvalidAddressException (com.sparrowwallet.drongo.address.InvalidAddressException)2 SecretPoint (com.sparrowwallet.drongo.bip47.SecretPoint)2 ECKey (com.sparrowwallet.drongo.crypto.ECKey)2 Wallet (com.sparrowwallet.drongo.wallet.Wallet)2 StorageEvent (com.sparrowwallet.sparrow.event.StorageEvent)2 TransactionEntry (com.sparrowwallet.sparrow.wallet.TransactionEntry)2 IOException (java.io.IOException)2 Subscribe (com.google.common.eventbus.Subscribe)1 InvalidPasswordException (com.sparrowwallet.drongo.crypto.InvalidPasswordException)1 ScriptType (com.sparrowwallet.drongo.protocol.ScriptType)1 Sha256Hash (com.sparrowwallet.drongo.protocol.Sha256Hash)1 PSBT (com.sparrowwallet.drongo.psbt.PSBT)1 WalletPasswordDialog (com.sparrowwallet.sparrow.control.WalletPasswordDialog)1 WalletDataChangedEvent (com.sparrowwallet.sparrow.event.WalletDataChangedEvent)1 WalletHistoryClearedEvent (com.sparrowwallet.sparrow.event.WalletHistoryClearedEvent)1 ElectrumServer (com.sparrowwallet.sparrow.net.ElectrumServer)1 Whirlpool (com.sparrowwallet.sparrow.whirlpool.Whirlpool)1