Skip to content

Commit

Permalink
refactor: Add WalletEx class to handle coinjoin related functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
HashEngineering committed Jan 18, 2023
1 parent 8b83903 commit 64dac26
Show file tree
Hide file tree
Showing 17 changed files with 1,711 additions and 965 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.bitcoinj.wallet.Balance;
import org.bitcoinj.wallet.CoinControl;
import org.bitcoinj.wallet.SendRequest;
import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.WalletEx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -98,7 +98,7 @@ public class CoinJoinClientSession extends CoinJoinBaseSession {

private final KeyHolderStorage keyHolderStorage; // storage for keys used in PrepareDenominate

private final Wallet mixingWallet;
private final WalletEx mixingWallet;

private final AtomicBoolean hasNothingToDo = new AtomicBoolean(false); // is mixing finished?

Expand Down Expand Up @@ -413,7 +413,7 @@ private boolean makeCollateralAmounts(CompactTallyItem tallyItem, boolean fTryDe
}

//const auto pwallet = GetWallet(mixingWallet.GetName());
final Wallet wallet = mixingWallet;
final WalletEx wallet = mixingWallet;

if (wallet == null) {
log.info("coinjoin: Couldn't get wallet pointer");
Expand Down Expand Up @@ -1068,7 +1068,7 @@ protected void setNull() {
static int nextId = 0;
private final int id;

public CoinJoinClientSession(Wallet mixingWallet) {
public CoinJoinClientSession(WalletEx mixingWallet) {
super(mixingWallet.getContext());
this.mixingWallet = mixingWallet;
this.keyHolderStorage = new KeyHolderStorage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
import org.bitcoinj.core.TransactionDestination;
import org.bitcoinj.script.Script;
import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.WalletEx;

public class KeyHolder {
ReserveDestination reserveDestination; // TODO: use ReserveKey
TransactionDestination destination;

public KeyHolder(Wallet wallet) {
public KeyHolder(WalletEx wallet) {
// get the next CoinJoinKey?
reserveDestination = new ReserveDestination(wallet);
destination = reserveDestination.getReservedDestination(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.bitcoinj.script.Script;
import org.bitcoinj.utils.Threading;
import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.WalletEx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -32,7 +33,7 @@ public class KeyHolderStorage {
@GuardedBy("lock")
ArrayList<KeyHolder> storage = Lists.newArrayList();

public Script addKey(Wallet wallet) {
public Script addKey(WalletEx wallet) {
KeyHolder keyHolder = new KeyHolder(wallet);
Script script = keyHolder.getScriptForDestination();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import org.bitcoinj.core.TransactionDestination;
import org.bitcoinj.crypto.DeterministicKey;
import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.WalletEx;

public class ReserveDestination extends ReserveScript {
//! The wallet to reserve from
protected final Wallet wallet;
protected final WalletEx wallet;
//LegacyScriptPubKeyMan* m_spk_man{nullptr};

//! The index of the address's key in the keypool
Expand All @@ -37,7 +38,7 @@ public class ReserveDestination extends ReserveScript {
protected boolean internal = false;

//! Construct a ReserveDestination object. This does NOT reserve an address yet
public ReserveDestination(Wallet wallet) {
public ReserveDestination(WalletEx wallet) {
this.wallet = wallet;
}

Expand All @@ -49,7 +50,7 @@ protected void finalize() {
//! Reserve an address
public TransactionDestination getReservedDestination(boolean internal) {
if (index == -1) {
DeterministicKey key = wallet.freshCoinJoinKey();
DeterministicKey key = wallet.getCoinJoin().freshReceiveKey();
if (key == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.bitcoinj.wallet.CoinControl;
import org.bitcoinj.wallet.SendRequest;
import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.WalletEx;

import javax.annotation.concurrent.GuardedBy;
import java.util.ArrayList;
Expand All @@ -41,7 +42,7 @@

public class TransactionBuilder {
/// Wallet the transaction will be build for
private final Wallet wallet;
private final WalletEx wallet;
/// See CTransactionBuilder() for initialization
private final CoinControl coinControl = new CoinControl();
/// Dummy since we anyway use tallyItem's destination as change destination in coincontrol.
Expand All @@ -63,7 +64,7 @@ public class TransactionBuilder {
private final ArrayList<TransactionBuilderOutput> vecOutputs = new ArrayList<>();
/// Needed by CTransactionBuilderOutput::UpdateAmount to lock cs_outputs

public TransactionBuilder(Wallet wallet, final CompactTallyItem tallyItem) {
public TransactionBuilder(WalletEx wallet, final CompactTallyItem tallyItem) {
this.wallet = wallet;
dummyReserveDestination = new ReserveDestination(wallet);
this.tallyItem = tallyItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.TransactionDestination;
import org.bitcoinj.script.Script;
import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.WalletEx;

public class TransactionBuilderOutput {
/// Used for amount updates
Expand All @@ -30,7 +30,7 @@ public class TransactionBuilderOutput {
/// ScriptPubKey of this output
Script script;

public TransactionBuilderOutput(TransactionBuilder txBuilder, Wallet wallet, Coin amount) {
public TransactionBuilderOutput(TransactionBuilder txBuilder, WalletEx wallet, Coin amount) {
this.txBuilder = txBuilder;
this.amount = amount;
this.dest = new ReserveDestination(wallet);
Expand Down
Loading

0 comments on commit 64dac26

Please sign in to comment.