From 67836b2b557839317316a3e1c8d18b98a51d0e29 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 1 Sep 2021 13:08:18 +0200 Subject: [PATCH] add mix config to wallet --- .../drongo/wallet/MixConfig.java | 66 +++++++++++++++++++ .../sparrowwallet/drongo/wallet/Wallet.java | 21 ++++++ 2 files changed, 87 insertions(+) create mode 100644 src/main/java/com/sparrowwallet/drongo/wallet/MixConfig.java diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/MixConfig.java b/src/main/java/com/sparrowwallet/drongo/wallet/MixConfig.java new file mode 100644 index 0000000..63016bb --- /dev/null +++ b/src/main/java/com/sparrowwallet/drongo/wallet/MixConfig.java @@ -0,0 +1,66 @@ +package com.sparrowwallet.drongo.wallet; + +import java.io.File; + +public class MixConfig extends Persistable { + private String scode; + private Boolean mixOnStartup; + private File mixToWalletFile; + private String mixToWalletName; + private Integer minMixes; + + public MixConfig() { + } + + public MixConfig(String scode, Boolean mixOnStartup, File mixToWalletFile, String mixToWalletName, Integer minMixes) { + this.scode = scode; + this.mixOnStartup = mixOnStartup; + this.mixToWalletFile = mixToWalletFile; + this.mixToWalletName = mixToWalletName; + this.minMixes = minMixes; + } + + public String getScode() { + return scode; + } + + public void setScode(String scode) { + this.scode = scode; + } + + public Boolean getMixOnStartup() { + return mixOnStartup; + } + + public void setMixOnStartup(Boolean mixOnStartup) { + this.mixOnStartup = mixOnStartup; + } + + public File getMixToWalletFile() { + return mixToWalletFile; + } + + public void setMixToWalletFile(File mixToWalletFile) { + this.mixToWalletFile = mixToWalletFile; + } + + public String getMixToWalletName() { + return mixToWalletName; + } + + public void setMixToWalletName(String mixToWalletName) { + this.mixToWalletName = mixToWalletName; + } + + public Integer getMinMixes() { + return minMixes; + } + + public void setMinMixes(Integer minMixes) { + this.minMixes = minMixes; + } + + public MixConfig copy() { + return new MixConfig(scode, mixOnStartup, mixToWalletFile, mixToWalletName, minMixes); + } +} diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index a443a39..1db5590 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -36,6 +36,7 @@ public class Wallet extends Persistable { private List keystores = new ArrayList<>(); private final TreeSet purposeNodes = new TreeSet<>(); private final Map transactions = new HashMap<>(); + private MixConfig mixConfig; private final Map utxoMixes = new HashMap<>(); private Integer storedBlockHeight; private Integer gapLimit; @@ -230,6 +231,22 @@ public class Wallet extends Persistable { } } + public MixConfig getMixConfig() { + return mixConfig; + } + + public MixConfig getOrCreateMixConfig() { + if(mixConfig == null) { + mixConfig = new MixConfig(); + } + + return mixConfig; + } + + public void setMixConfig(MixConfig mixConfig) { + this.mixConfig = mixConfig; + } + public UtxoMixData getUtxoMixData(BlockTransactionHashIndex utxo) { return getUtxoMixData(Sha256Hash.of(utxo.toString().getBytes(StandardCharsets.UTF_8))); } @@ -1339,6 +1356,10 @@ public class Wallet extends Persistable { for(Sha256Hash hash : transactions.keySet()) { copy.transactions.put(hash, transactions.get(hash)); } + copy.setMixConfig(mixConfig == null ? null : mixConfig.copy()); + for(Sha256Hash hash : utxoMixes.keySet()) { + copy.utxoMixes.put(hash, utxoMixes.get(hash)); + } copy.setStoredBlockHeight(getStoredBlockHeight()); copy.gapLimit = gapLimit; copy.birthDate = birthDate;