add minimal wallet copy functionality

This commit is contained in:
Craig Raw 2022-12-15 08:28:16 +02:00
parent 692f23e026
commit ca98d4d9b6

View file

@ -1802,12 +1802,16 @@ public class Wallet extends Persistable implements Comparable<Wallet> {
} }
public Wallet copy() { public Wallet copy() {
return copy(true);
}
public Wallet copy(boolean includeHistory) {
Wallet copy = new Wallet(name); Wallet copy = new Wallet(name);
copy.setId(getId()); copy.setId(getId());
copy.setLabel(label); copy.setLabel(label);
copy.setMasterWallet(masterWallet); copy.setMasterWallet(masterWallet);
for(Wallet childWallet : childWallets) { for(Wallet childWallet : childWallets) {
Wallet copyChildWallet = childWallet.copy(); Wallet copyChildWallet = childWallet.copy(includeHistory);
copyChildWallet.setMasterWallet(copy); copyChildWallet.setMasterWallet(copy);
copy.childWallets.add(copyChildWallet); copy.childWallets.add(copyChildWallet);
} }
@ -1817,20 +1821,22 @@ public class Wallet extends Persistable implements Comparable<Wallet> {
for(Keystore keystore : keystores) { for(Keystore keystore : keystores) {
copy.getKeystores().add(keystore.copy()); copy.getKeystores().add(keystore.copy());
} }
for(WalletNode node : purposeNodes) { if(includeHistory) {
copy.purposeNodes.add(node.copy(copy)); for(WalletNode node : purposeNodes) {
} copy.purposeNodes.add(node.copy(copy));
for(Sha256Hash hash : transactions.keySet()) { }
copy.transactions.put(hash, transactions.get(hash)); for(Sha256Hash hash : transactions.keySet()) {
} copy.transactions.put(hash, transactions.get(hash));
for(String entry : detachedLabels.keySet()) { }
copy.detachedLabels.put(entry, detachedLabels.get(entry)); for(String entry : detachedLabels.keySet()) {
copy.detachedLabels.put(entry, detachedLabels.get(entry));
}
for(Sha256Hash hash : utxoMixes.keySet()) {
copy.utxoMixes.put(hash, utxoMixes.get(hash));
}
} }
copy.setWalletConfig(walletConfig == null ? null : walletConfig.copy()); copy.setWalletConfig(walletConfig == null ? null : walletConfig.copy());
copy.setMixConfig(mixConfig == null ? null : mixConfig.copy()); copy.setMixConfig(mixConfig == null ? null : mixConfig.copy());
for(Sha256Hash hash : utxoMixes.keySet()) {
copy.utxoMixes.put(hash, utxoMixes.get(hash));
}
copy.setStoredBlockHeight(getStoredBlockHeight()); copy.setStoredBlockHeight(getStoredBlockHeight());
copy.gapLimit = gapLimit; copy.gapLimit = gapLimit;
copy.watchLast = watchLast; copy.watchLast = watchLast;