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,6 +1821,7 @@ 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());
} }
if(includeHistory) {
for(WalletNode node : purposeNodes) { for(WalletNode node : purposeNodes) {
copy.purposeNodes.add(node.copy(copy)); copy.purposeNodes.add(node.copy(copy));
} }
@ -1826,11 +1831,12 @@ public class Wallet extends Persistable implements Comparable<Wallet> {
for(String entry : detachedLabels.keySet()) { for(String entry : detachedLabels.keySet()) {
copy.detachedLabels.put(entry, detachedLabels.get(entry)); copy.detachedLabels.put(entry, detachedLabels.get(entry));
} }
copy.setWalletConfig(walletConfig == null ? null : walletConfig.copy());
copy.setMixConfig(mixConfig == null ? null : mixConfig.copy());
for(Sha256Hash hash : utxoMixes.keySet()) { for(Sha256Hash hash : utxoMixes.keySet()) {
copy.utxoMixes.put(hash, utxoMixes.get(hash)); copy.utxoMixes.put(hash, utxoMixes.get(hash));
} }
}
copy.setWalletConfig(walletConfig == null ? null : walletConfig.copy());
copy.setMixConfig(mixConfig == null ? null : mixConfig.copy());
copy.setStoredBlockHeight(getStoredBlockHeight()); copy.setStoredBlockHeight(getStoredBlockHeight());
copy.gapLimit = gapLimit; copy.gapLimit = gapLimit;
copy.watchLast = watchLast; copy.watchLast = watchLast;