Search in sources :

Example 1 with OutputDescriptor

use of com.sparrowwallet.drongo.OutputDescriptor in project sparrow by sparrowwallet.

the class Descriptor method importWallet.

@Override
public Wallet importWallet(InputStream inputStream, String password) throws ImportException {
    try {
        String outputDescriptor = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
        OutputDescriptor descriptor = OutputDescriptor.getOutputDescriptor(outputDescriptor.trim());
        return descriptor.toWallet();
    } catch (Exception e) {
        throw new ImportException("Error importing output descriptor", e);
    }
}
Also used : OutputDescriptor(com.sparrowwallet.drongo.OutputDescriptor)

Example 2 with OutputDescriptor

use of com.sparrowwallet.drongo.OutputDescriptor in project sparrow by sparrowwallet.

the class Bwt method start.

private void start(Collection<Wallet> wallets, CallbackNotifier callback) {
    List<Wallet> validWallets = wallets.stream().filter(Wallet::isValid).collect(Collectors.toList());
    Set<String> outputDescriptors = new LinkedHashSet<>();
    for (Wallet wallet : validWallets) {
        OutputDescriptor receiveOutputDescriptor = OutputDescriptor.getOutputDescriptor(wallet, KeyPurpose.RECEIVE);
        outputDescriptors.add(receiveOutputDescriptor.toString(false, false));
        OutputDescriptor changeOutputDescriptor = OutputDescriptor.getOutputDescriptor(wallet, KeyPurpose.CHANGE);
        outputDescriptors.add(changeOutputDescriptor.toString(false, false));
    }
    int rescanSince = validWallets.stream().filter(wallet -> wallet.getBirthDate() != null).mapToInt(wallet -> (int) (wallet.getBirthDate().getTime() / 1000)).min().orElse(-1);
    int gapLimit = validWallets.stream().filter(wallet -> wallet.getGapLimit() > 0).mapToInt(Wallet::getGapLimit).max().orElse(Wallet.DEFAULT_LOOKAHEAD);
    boolean forceRescan = false;
    for (Wallet wallet : validWallets) {
        Date txBirthDate = wallet.getTransactions().values().stream().map(BlockTransactionHash::getDate).filter(Objects::nonNull).min(Date::compareTo).orElse(null);
        if ((wallet.getBirthDate() != null && txBirthDate != null && wallet.getBirthDate().before(txBirthDate)) || (txBirthDate == null && wallet.getStoredBlockHeight() != null && wallet.getStoredBlockHeight() == 0)) {
            forceRescan = true;
        }
    }
    start(outputDescriptors, rescanSince, forceRescan, gapLimit, callback);
}
Also used : java.util(java.util) Wallet(com.sparrowwallet.drongo.wallet.Wallet) LoggerFactory(org.slf4j.LoggerFactory) Config(com.sparrowwallet.sparrow.io.Config) InetAddress(java.net.InetAddress) Task(javafx.concurrent.Task) CallbackNotifier(dev.bwt.libbwt.daemon.CallbackNotifier) Gson(com.google.gson.Gson) Duration(java.time.Duration) OutputDescriptor(com.sparrowwallet.drongo.OutputDescriptor) Logger(org.slf4j.Logger) com.sparrowwallet.sparrow.event(com.sparrowwallet.sparrow.event) IOException(java.io.IOException) Service(javafx.concurrent.Service) SerializedName(com.google.gson.annotations.SerializedName) HostAndPort(com.google.common.net.HostAndPort) BlockTransactionHash(com.sparrowwallet.drongo.wallet.BlockTransactionHash) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) NativeBwtDaemon(dev.bwt.libbwt.daemon.NativeBwtDaemon) Platform(javafx.application.Platform) AppServices(com.sparrowwallet.sparrow.AppServices) KeyPurpose(com.sparrowwallet.drongo.KeyPurpose) Network(com.sparrowwallet.drongo.Network) EventManager(com.sparrowwallet.sparrow.EventManager) OutputDescriptor(com.sparrowwallet.drongo.OutputDescriptor) Wallet(com.sparrowwallet.drongo.wallet.Wallet)

Example 3 with OutputDescriptor

use of com.sparrowwallet.drongo.OutputDescriptor in project sparrow by sparrowwallet.

the class ReceiveController method displayAddress.

@SuppressWarnings("unchecked")
public void displayAddress(ActionEvent event) {
    Wallet wallet = getWalletForm().getWallet();
    if (currentEntry != null) {
        OutputDescriptor addressDescriptor = OutputDescriptor.getOutputDescriptor(walletForm.getWallet(), currentEntry.getNode().getKeyPurpose(), currentEntry.getNode().getIndex());
        List<Device> possibleDevices = (List<Device>) displayAddress.getUserData();
        if (possibleDevices != null && !possibleDevices.isEmpty()) {
            if (possibleDevices.size() > 1 || possibleDevices.get(0).isNeedsPinSent() || possibleDevices.get(0).isNeedsPassphraseSent()) {
                DeviceAddressDialog dlg = new DeviceAddressDialog(wallet, addressDescriptor);
                dlg.showAndWait();
            } else {
                Device actualDevice = possibleDevices.get(0);
                Hwi.DisplayAddressService displayAddressService = new Hwi.DisplayAddressService(actualDevice, "", wallet.getScriptType(), addressDescriptor);
                displayAddressService.setOnFailed(failedEvent -> {
                    Platform.runLater(() -> {
                        DeviceAddressDialog dlg = new DeviceAddressDialog(wallet, addressDescriptor);
                        dlg.showAndWait();
                    });
                });
                displayAddressService.start();
            }
        } else {
            DeviceAddressDialog dlg = new DeviceAddressDialog(wallet, addressDescriptor);
            dlg.showAndWait();
        }
    }
}
Also used : OutputDescriptor(com.sparrowwallet.drongo.OutputDescriptor) Wallet(com.sparrowwallet.drongo.wallet.Wallet) Device(com.sparrowwallet.sparrow.io.Device) Hwi(com.sparrowwallet.sparrow.io.Hwi)

Example 4 with OutputDescriptor

use of com.sparrowwallet.drongo.OutputDescriptor in project sparrow by sparrowwallet.

the class ReceiveController method updateDisplayAddress.

private void updateDisplayAddress(List<Device> devices) {
    Wallet wallet = getWalletForm().getWallet();
    OutputDescriptor walletDescriptor = OutputDescriptor.getOutputDescriptor(walletForm.getWallet());
    List<String> walletFingerprints = walletDescriptor.getExtendedPublicKeys().stream().map(extKey -> walletDescriptor.getKeyDerivation(extKey).getMasterFingerprint()).collect(Collectors.toList());
    List<Device> addressDevices = devices.stream().filter(device -> walletFingerprints.contains(device.getFingerprint())).collect(Collectors.toList());
    if (addressDevices.isEmpty()) {
        addressDevices = devices.stream().filter(device -> device.isNeedsPinSent() || device.isNeedsPassphraseSent()).collect(Collectors.toList());
    }
    if (!addressDevices.isEmpty()) {
        if (currentEntry != null) {
            displayAddress.setVisible(true);
        }
        displayAddress.setUserData(addressDevices);
        return;
    } else if (currentEntry != null && wallet.getKeystores().stream().anyMatch(keystore -> keystore.getSource().equals(KeystoreSource.HW_USB))) {
        displayAddress.setVisible(true);
        displayAddress.setUserData(null);
        return;
    }
    displayAddress.setVisible(false);
    displayAddress.setUserData(null);
}
Also used : Address(com.sparrowwallet.drongo.address.Address) Initializable(javafx.fxml.Initializable) java.util(java.util) MatrixToImageWriter(com.google.zxing.client.j2se.MatrixToImageWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Wallet(com.sparrowwallet.drongo.wallet.Wallet) javafx.scene.control(javafx.scene.control) QRCodeWriter(com.google.zxing.qrcode.QRCodeWriter) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) SimpleDateFormat(java.text.SimpleDateFormat) Glyph(org.controlsfx.glyphfont.Glyph) ByteArrayInputStream(java.io.ByteArrayInputStream) FontAwesome5(com.sparrowwallet.sparrow.glyphfont.FontAwesome5) Subscribe(com.google.common.eventbus.Subscribe) OutputDescriptor(com.sparrowwallet.drongo.OutputDescriptor) MatrixToImageConfig(com.google.zxing.client.j2se.MatrixToImageConfig) DateFormat(java.text.DateFormat) Hwi(com.sparrowwallet.sparrow.io.Hwi) Device(com.sparrowwallet.sparrow.io.Device) Logger(org.slf4j.Logger) BlockTransactionHashIndex(com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex) com.sparrowwallet.sparrow.event(com.sparrowwallet.sparrow.event) CodeArea(org.fxmisc.richtext.CodeArea) Collectors(java.util.stream.Collectors) KeystoreSource(com.sparrowwallet.drongo.wallet.KeystoreSource) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) ActionEvent(javafx.event.ActionEvent) AppServices(com.sparrowwallet.sparrow.AppServices) KeyPurpose(com.sparrowwallet.drongo.KeyPurpose) Stage(javafx.stage.Stage) EncodeHintType(com.google.zxing.EncodeHintType) ImageView(javafx.scene.image.ImageView) EventManager(com.sparrowwallet.sparrow.EventManager) BitMatrix(com.google.zxing.common.BitMatrix) BarcodeFormat(com.google.zxing.BarcodeFormat) Image(javafx.scene.image.Image) com.sparrowwallet.sparrow.control(com.sparrowwallet.sparrow.control) OutputDescriptor(com.sparrowwallet.drongo.OutputDescriptor) Wallet(com.sparrowwallet.drongo.wallet.Wallet) Device(com.sparrowwallet.sparrow.io.Device)

Example 5 with OutputDescriptor

use of com.sparrowwallet.drongo.OutputDescriptor in project sparrow by sparrowwallet.

the class SpecterDIYTest method testExport.

@Test
public void testExport() throws ExportException, IOException {
    OutputDescriptor walletDescriptor = OutputDescriptor.getOutputDescriptor("wsh(sortedmulti(2,[7fd1bbf4/48h/0h/0h/2h]xpub6DnVFCXjZKhSAJw1oGzksdc1CtMxHxqG6DgNSjZHsymMSgcNEb2c3bz5N2bBMEEUFos98CeAWbh1pTMBcJrsKW63icdAQNGT6Aqv1WWrkxg,[8ff26349/48h/0h/0h/2h]xpub6ErPooPdSeBoXVZocBe8EWF9GXjFuV52kme35p4MtrP2SAFdUmgTJM1urrJzSuA44izrEuiQNNdmWEVRaBJcBDcPpnLBR8tP2Pcu2EiyeHu,[ff3305c2/48h/0h/0h/2h]xpub6Dpndp2xurqbfSGhxKVXzk3nJZgah3PdD3qD11KyPicYYBatRxfxqoN7s9tnWKXaz7zhyVqcvnJyak7BVKonW2wTXHd1zNDxJAu8jcxF59j))");
    Wallet wallet = walletDescriptor.toWallet();
    wallet.setName("Sparrow Multisig");
    SpecterDIY specterDIY = new SpecterDIY();
    byte[] walletBytes = ByteStreams.toByteArray(getInputStream("specter-diy-export.txt"));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    specterDIY.exportWallet(wallet, baos);
    String original = new String(walletBytes);
    String exported = new String(baos.toByteArray());
    Assert.assertEquals(original, exported);
}
Also used : OutputDescriptor(com.sparrowwallet.drongo.OutputDescriptor) Wallet(com.sparrowwallet.drongo.wallet.Wallet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

OutputDescriptor (com.sparrowwallet.drongo.OutputDescriptor)9 Wallet (com.sparrowwallet.drongo.wallet.Wallet)5 Gson (com.google.gson.Gson)2 KeyPurpose (com.sparrowwallet.drongo.KeyPurpose)2 AppServices (com.sparrowwallet.sparrow.AppServices)2 EventManager (com.sparrowwallet.sparrow.EventManager)2 com.sparrowwallet.sparrow.event (com.sparrowwallet.sparrow.event)2 Device (com.sparrowwallet.sparrow.io.Device)2 Hwi (com.sparrowwallet.sparrow.io.Hwi)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStreamReader (java.io.InputStreamReader)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Platform (javafx.application.Platform)2 Subscribe (com.google.common.eventbus.Subscribe)1 HostAndPort (com.google.common.net.HostAndPort)1 SerializedName (com.google.gson.annotations.SerializedName)1 BarcodeFormat (com.google.zxing.BarcodeFormat)1 EncodeHintType (com.google.zxing.EncodeHintType)1 MatrixToImageConfig (com.google.zxing.client.j2se.MatrixToImageConfig)1