diff --git a/drongo b/drongo index 5e8a1467..c0213007 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 5e8a14678d264dfc5e30cc594f60a6f7f87292ef +Subproject commit c02130079782cc10dc47f933274f12d08c497c19 diff --git a/src/main/java/com/sparrowwallet/sparrow/io/SpecterDesktop.java b/src/main/java/com/sparrowwallet/sparrow/io/SpecterDesktop.java index c30704f4..b2c15a86 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/SpecterDesktop.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/SpecterDesktop.java @@ -3,10 +3,7 @@ package com.sparrowwallet.sparrow.io; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.sparrowwallet.drongo.OutputDescriptor; -import com.sparrowwallet.drongo.wallet.BlockTransactionHash; -import com.sparrowwallet.drongo.wallet.InvalidWalletException; -import com.sparrowwallet.drongo.wallet.Wallet; -import com.sparrowwallet.drongo.wallet.WalletModel; +import com.sparrowwallet.drongo.wallet.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,6 +12,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.nio.charset.StandardCharsets; +import java.util.List; public class SpecterDesktop implements WalletImport, WalletExport { private static final Logger log = LoggerFactory.getLogger(SpecterDesktop.class); @@ -63,6 +61,29 @@ public class SpecterDesktop implements WalletImport, WalletExport { Wallet wallet = outputDescriptor.toWallet(); wallet.setName(specterWallet.label); + if(specterWallet.devices != null && specterWallet.devices.size() == wallet.getKeystores().size()) { + boolean uniqueLabels = specterWallet.devices.stream().map(d -> d.label).distinct().count() == specterWallet.devices.size(); + for(int i = 0; i < specterWallet.devices.size(); i++) { + SpecterWalletDevice device = specterWallet.devices.get(i); + Keystore keystore = wallet.getKeystores().get(i); + keystore.setLabel(device.label + (uniqueLabels ? "" : " " + i)); + + WalletModel walletModel = device.getWalletModel(); + if(walletModel != null) { + keystore.setWalletModel(walletModel); + if(walletModel == WalletModel.TREZOR_1 || walletModel == WalletModel.TREZOR_T || walletModel == WalletModel.KEEPKEY || + walletModel == WalletModel.LEDGER_NANO_S || walletModel == WalletModel.LEDGER_NANO_X || + walletModel == WalletModel.BITBOX_02 || walletModel == WalletModel.COLDCARD) { + keystore.setSource(KeystoreSource.HW_USB); + } else if(walletModel == WalletModel.BITCOIN_CORE) { + keystore.setSource(KeystoreSource.SW_WATCH); + } else { + keystore.setSource(KeystoreSource.HW_AIRGAPPED); + } + } + } + } + try { wallet.checkWallet(); } catch(InvalidWalletException e) { @@ -113,5 +134,32 @@ public class SpecterDesktop implements WalletImport, WalletExport { public String label; public Integer blockheight; public String descriptor; + public List devices; + } + + public static class SpecterWalletDevice { + public String type; + public String label; + + public WalletModel getWalletModel() { + if(type != null) { + String model = type; + if(model.equals("cobo")) { + model = "cobovault"; + } + + WalletModel walletModel = WalletModel.fromType(model); + if(walletModel == WalletModel.SPECTER_DESKTOP) { + walletModel = WalletModel.SPECTER_DIY; + } + if(walletModel == WalletModel.TREZOR_1) { + walletModel = WalletModel.TREZOR_T; + } + + return walletModel; + } + + return null; + } } }