mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-23 20:36:44 +00:00
set keystore label, model and source type when importing a wallet from specter desktop
This commit is contained in:
parent
a9ab4d6c78
commit
02e144f802
2 changed files with 53 additions and 5 deletions
2
drongo
2
drongo
|
@ -1 +1 @@
|
|||
Subproject commit 5e8a14678d264dfc5e30cc594f60a6f7f87292ef
|
||||
Subproject commit c02130079782cc10dc47f933274f12d08c497c19
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue