|
|
@ -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<SpecterWalletDevice> 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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|