From 81c202198e8b057271414d15259df556a90bc6f1 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 23 Aug 2021 16:34:40 +0200 Subject: [PATCH] add utxo mix data storage to wallet --- .../com/sparrowwallet/drongo/KeyPurpose.java | 4 +++ .../drongo/wallet/StandardAccount.java | 1 + .../drongo/wallet/UtxoMixData.java | 30 +++++++++++++++++++ .../sparrowwallet/drongo/wallet/Wallet.java | 14 +++++++++ .../drongo/wallet/WalletModel.java | 2 +- 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/sparrowwallet/drongo/wallet/UtxoMixData.java diff --git a/src/main/java/com/sparrowwallet/drongo/KeyPurpose.java b/src/main/java/com/sparrowwallet/drongo/KeyPurpose.java index 4563692..0af33fb 100644 --- a/src/main/java/com/sparrowwallet/drongo/KeyPurpose.java +++ b/src/main/java/com/sparrowwallet/drongo/KeyPurpose.java @@ -2,9 +2,13 @@ package com.sparrowwallet.drongo; import com.sparrowwallet.drongo.crypto.ChildNumber; +import java.util.List; + public enum KeyPurpose { RECEIVE(ChildNumber.ZERO), CHANGE(ChildNumber.ONE); + public static final List DEFAULT_PURPOSES = List.of(RECEIVE, CHANGE); + private final ChildNumber pathIndex; KeyPurpose(ChildNumber pathIndex) { diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/StandardAccount.java b/src/main/java/com/sparrowwallet/drongo/wallet/StandardAccount.java index b6778b7..4d66905 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/StandardAccount.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/StandardAccount.java @@ -20,6 +20,7 @@ public enum StandardAccount { WHIRLPOOL_BADBANK("Badbank", new ChildNumber(2147483644, true)); public static final List WHIRLPOOL_ACCOUNTS = List.of(WHIRLPOOL_PREMIX, WHIRLPOOL_POSTMIX, WHIRLPOOL_BADBANK); + public static final List WHIRLPOOL_MIX_ACCOUNTS = List.of(WHIRLPOOL_PREMIX, WHIRLPOOL_POSTMIX); StandardAccount(String name, ChildNumber childNumber) { this.name = name; diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/UtxoMixData.java b/src/main/java/com/sparrowwallet/drongo/wallet/UtxoMixData.java new file mode 100644 index 0000000..07eaf10 --- /dev/null +++ b/src/main/java/com/sparrowwallet/drongo/wallet/UtxoMixData.java @@ -0,0 +1,30 @@ +package com.sparrowwallet.drongo.wallet; + +public class UtxoMixData extends Persistable { + private final String poolId; + private final int mixesDone; + private final Long forwarding; + + public UtxoMixData(String poolId, int mixesDone, Long forwarding) { + this.poolId = poolId; + this.mixesDone = mixesDone; + this.forwarding = forwarding; + } + + public String getPoolId() { + return poolId; + } + + public int getMixesDone() { + return mixesDone; + } + + public Long getForwarding() { + return forwarding; + } + + @Override + public String toString() { + return "{poolId:" + poolId + ", mixesDone:" + mixesDone + ", forwarding:" + forwarding + "}"; + } +} diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index d23ca26..aaf1078 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -14,6 +14,7 @@ import com.sparrowwallet.drongo.protocol.*; import com.sparrowwallet.drongo.psbt.PSBT; import com.sparrowwallet.drongo.psbt.PSBTInput; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -35,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 final Map utxoMixes = new HashMap<>(); private Integer storedBlockHeight; private Integer gapLimit; private Date birthDate; @@ -167,6 +169,10 @@ public class Wallet extends Persistable { return whirlpoolAccounts.isEmpty(); } + public boolean isWhirlpoolMixWallet() { + return !isMasterWallet() && StandardAccount.WHIRLPOOL_MIX_ACCOUNTS.contains(getStandardAccountType()); + } + public void setName(String name) { this.name = name; } @@ -224,6 +230,14 @@ public class Wallet extends Persistable { } } + public UtxoMixData getUtxoMixData(BlockTransactionHashIndex utxo) { + return utxoMixes.get(Sha256Hash.of(utxo.toString().getBytes(StandardCharsets.UTF_8))); + } + + public Map getUtxoMixes() { + return utxoMixes; + } + public Integer getStoredBlockHeight() { return storedBlockHeight; } diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/WalletModel.java b/src/main/java/com/sparrowwallet/drongo/wallet/WalletModel.java index 29efd53..afd24b1 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/WalletModel.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/WalletModel.java @@ -44,7 +44,7 @@ public enum WalletModel { } public boolean alwaysIncludeNonWitnessUtxo() { - if(this == COLDCARD || this == COBO_VAULT || this == PASSPORT) { + if(this == COLDCARD || this == COBO_VAULT || this == PASSPORT || this == KEYSTONE) { return false; }