mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 21:36:45 +00:00
import address labels from electrum wallets
This commit is contained in:
parent
64c3db3656
commit
88dfde3c67
1 changed files with 30 additions and 1 deletions
|
@ -4,7 +4,9 @@ import com.google.gson.*;
|
|||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sparrowwallet.drongo.ExtendedKey;
|
||||
import com.sparrowwallet.drongo.KeyDerivation;
|
||||
import com.sparrowwallet.drongo.KeyPurpose;
|
||||
import com.sparrowwallet.drongo.Utils;
|
||||
import com.sparrowwallet.drongo.address.Address;
|
||||
import com.sparrowwallet.drongo.crypto.*;
|
||||
import com.sparrowwallet.drongo.policy.Policy;
|
||||
import com.sparrowwallet.drongo.policy.PolicyType;
|
||||
|
@ -91,6 +93,10 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport
|
|||
}
|
||||
}
|
||||
|
||||
if(key.equals("addresses")) {
|
||||
ew.addresses = gson.fromJson(map.get(key), ElectrumAddresses.class);
|
||||
}
|
||||
|
||||
if(key.equals("verified_tx3")) {
|
||||
JsonObject jsonObject = (JsonObject)map.get(key);
|
||||
for(String txKey : jsonObject.keySet()) {
|
||||
|
@ -195,7 +201,24 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport
|
|||
blockTransaction.setLabel(ew.labels.get(key));
|
||||
}
|
||||
} catch(Exception e) {
|
||||
//not a tx, probably an address
|
||||
//not a tx - try an address
|
||||
if(ew.addresses != null) {
|
||||
try {
|
||||
Address address = Address.fromString(key);
|
||||
Map<KeyPurpose, List<String>> keyPurposes = Map.of(KeyPurpose.RECEIVE, ew.addresses.receiving, KeyPurpose.CHANGE, ew.addresses.change);
|
||||
for(KeyPurpose keyPurpose : keyPurposes.keySet()) {
|
||||
WalletNode purposeNode = wallet.getNode(keyPurpose);
|
||||
purposeNode.fillToIndex(keyPurposes.get(keyPurpose).size() - 1);
|
||||
for(WalletNode addressNode : purposeNode.getChildren()) {
|
||||
if(address.equals(wallet.getAddress(addressNode))) {
|
||||
addressNode.setLabel(ew.labels.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
//not an address
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,6 +365,7 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport
|
|||
public String wallet_type;
|
||||
public String seed_type;
|
||||
public Boolean use_encryption;
|
||||
public ElectrumAddresses addresses;
|
||||
public Map<String, String> labels = new LinkedHashMap<>();
|
||||
public Map<Sha256Hash, BlockTransaction> transactions = new HashMap<>();
|
||||
}
|
||||
|
@ -360,4 +384,9 @@ public class Electrum implements KeystoreFileImport, WalletImport, WalletExport
|
|||
public String passphrase;
|
||||
public Integer pw_hash_version;
|
||||
}
|
||||
|
||||
public static class ElectrumAddresses {
|
||||
public List<String> receiving;
|
||||
public List<String> change;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue