add utxo mix data storage to wallet

This commit is contained in:
Craig Raw 2021-08-23 16:34:40 +02:00
parent 2eedd2290c
commit 81c202198e
5 changed files with 50 additions and 1 deletions

View file

@ -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<KeyPurpose> DEFAULT_PURPOSES = List.of(RECEIVE, CHANGE);
private final ChildNumber pathIndex;
KeyPurpose(ChildNumber pathIndex) {

View file

@ -20,6 +20,7 @@ public enum StandardAccount {
WHIRLPOOL_BADBANK("Badbank", new ChildNumber(2147483644, true));
public static final List<StandardAccount> WHIRLPOOL_ACCOUNTS = List.of(WHIRLPOOL_PREMIX, WHIRLPOOL_POSTMIX, WHIRLPOOL_BADBANK);
public static final List<StandardAccount> WHIRLPOOL_MIX_ACCOUNTS = List.of(WHIRLPOOL_PREMIX, WHIRLPOOL_POSTMIX);
StandardAccount(String name, ChildNumber childNumber) {
this.name = name;

View file

@ -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 + "}";
}
}

View file

@ -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<Keystore> keystores = new ArrayList<>();
private final TreeSet<WalletNode> purposeNodes = new TreeSet<>();
private final Map<Sha256Hash, BlockTransaction> transactions = new HashMap<>();
private final Map<Sha256Hash, UtxoMixData> 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<Sha256Hash, UtxoMixData> getUtxoMixes() {
return utxoMixes;
}
public Integer getStoredBlockHeight() {
return storedBlockHeight;
}

View file

@ -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;
}