diff --git a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientSession.java b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientSession.java index 1ea0cd929..a7a730e24 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientSession.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientSession.java @@ -588,13 +588,9 @@ private boolean joinExistingQueue(Coin balanceNeedsAnonymized) { timeLastSuccessfulStep.set(Utils.currentTimeSeconds()); log.info("coinjoin: pending connection (from queue): sessionDenom: {} ({}), addr={}", sessionDenom, CoinJoin.denominationToString(sessionDenom), dmn.getService()); - //strAutoDenomResult = "Trying to connect..."; - //status.set(PoolStatus.CONNECTING); setStatus(PoolStatus.CONNECTING); return true; } - //strAutoDenomResult = "Failed to find mixing queue to join"; - //status.set(PoolStatus.WARN_NO_MIXING_QUEUES); setStatus(PoolStatus.WARN_NO_MIXING_QUEUES); return false; } @@ -613,9 +609,6 @@ private boolean startNewQueue(Coin balanceNeedsAnonymized) { HashSet setAmounts = new HashSet<>(); if (!mixingWallet.selectDenominatedAmounts(balanceNeedsAnonymized, setAmounts)) { // this should never happen - //strAutoDenomResult = "Can't mix: no compatible inputs found!"; - //log.error("coinjoin: error: {}", strAutoDenomResult); - //status.set(PoolStatus.ERR_NO_INPUTS); setStatus(PoolStatus.ERR_NO_INPUTS); return false; } @@ -625,9 +618,6 @@ private boolean startNewQueue(Coin balanceNeedsAnonymized) { Masternode dmn = context.coinJoinManager.coinJoinClientManagers.get(mixingWallet.getDescription()).getRandomNotUsedMasternode(); if (dmn == null) { - //strAutoDenomResult = "Can't find random Masternode."; - //status.set(PoolStatus.ERR_MASTERNODE_NOT_FOUND); - //log.info("coinjoin: error: {}", strAutoDenomResult); setStatus(PoolStatus.ERR_MASTERNODE_NOT_FOUND); return false; } @@ -671,8 +661,6 @@ private boolean startNewQueue(Coin balanceNeedsAnonymized) { timeLastSuccessfulStep.set(Utils.currentTimeSeconds()); log.info("coinjoin: start new queue -> pending connection, nSessionDenom: {} ({}), addr={}", sessionDenom, CoinJoin.denominationToString(sessionDenom), dmn.getService()); - //strAutoDenomResult = "Trying to connect..."; - //status.set(PoolStatus.CONNECTING); context.coinJoinManager.startAsync(); setStatus(PoolStatus.CONNECTING); return true; @@ -1232,9 +1220,6 @@ public boolean doAutomaticDenominating(boolean fDryRun) { Coin balanceNeedsAnonymized; if (!fDryRun && mixingWallet.isEncrypted()) { - //strAutoDenomResult = "Wallet is locked."; - //status.set(PoolStatus.ERR_WALLET_LOCKED); - //hasNothingToDo.set(true); setStatus(PoolStatus.ERR_WALLET_LOCKED); return false; } @@ -1290,10 +1275,6 @@ public boolean doAutomaticDenominating(boolean fDryRun) { // mixable balance is way too small if (nBalanceAnonymizable.isLessThan(nValueMin)) { - //strAutoDenomResult = "Not enough funds to mix."; - //log.info("coinjoin: {}", strAutoDenomResult); - //status.set(PoolStatus.ERR_NOT_ENOUGH_FUNDS); - //hasNothingToDo.set(true); setStatus(PoolStatus.ERR_NOT_ENOUGH_FUNDS); queueSessionCompleteListeners(ERR_SESSION); return false; @@ -1361,8 +1342,6 @@ public boolean doAutomaticDenominating(boolean fDryRun) { } if (sessionID.get() != 0) { - //strAutoDenomResult = "Mixing in progress..."; - //status.set(PoolStatus.MIXING); setStatus(PoolStatus.MIXING); return false; } @@ -1414,9 +1393,7 @@ public boolean doAutomaticDenominating(boolean fDryRun) { if (startNewQueue(balanceNeedsAnonymized)) { return true; } - - //strAutoDenomResult = "No compatible Masternode found."; - //status.set(PoolStatus.WARN_NO_COMPATIBLE_MASTERNODE); + setStatus(PoolStatus.WARN_NO_COMPATIBLE_MASTERNODE); return false; } diff --git a/core/src/main/java/org/bitcoinj/coinjoin/UnmixedZeroConfCoinSelector.java b/core/src/main/java/org/bitcoinj/coinjoin/UnmixedZeroConfCoinSelector.java index 008924f04..0f06c3813 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/UnmixedZeroConfCoinSelector.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/UnmixedZeroConfCoinSelector.java @@ -39,16 +39,6 @@ protected UnmixedZeroConfCoinSelector() { super(); } - /*public UnmixedZeroConfCoinSelector(Wallet wallet) { - super(); - this.wallet = wallet; - this.onlyConfirmed = false; - } - public UnmixedZeroConfCoinSelector(Wallet wallet, boolean onlyConfirmed) { - this(wallet); - this.onlyConfirmed = onlyConfirmed; - }*/ - @Override public CoinSelection select(Coin target, List candidates) { CoinSelection selection = super.select(target, candidates); diff --git a/core/src/main/java/org/bitcoinj/wallet/WalletEx.java b/core/src/main/java/org/bitcoinj/wallet/WalletEx.java index 0249ab05a..9ff944248 100644 --- a/core/src/main/java/org/bitcoinj/wallet/WalletEx.java +++ b/core/src/main/java/org/bitcoinj/wallet/WalletEx.java @@ -47,7 +47,6 @@ public class WalletEx extends Wallet { private static final Logger log = LoggerFactory.getLogger(WalletEx.class); - //protected KeyChainGroup coinJoinKeyChainGroup; protected CoinJoinExtension coinjoin; /** @@ -218,8 +217,6 @@ public Coin getBalance(BalanceType balanceType) { value = value.add(out.getValue()); } return value; - //CoinSelection selection = new CoinJoinCoinSelector(this).select(NetworkParameters.MAX_MONEY, candidates); - //return selection.valueGathered; } else if (balanceType == BalanceType.DENOMINATED || balanceType == BalanceType.DENOMINATED_SPENDABLE) { List candidates = calculateAllSpendCandidates(false, balanceType == BalanceType.DENOMINATED_SPENDABLE); CoinSelection selection = DenominatedCoinSelector.get().select(MAX_MONEY, candidates); @@ -620,7 +617,6 @@ public int countInputsWithAmount(Coin inputValue) { return count; } - // TODO: Do we need these lock functions public boolean lockCoin(TransactionOutPoint outPoint) { lockedCoinsSet.add(outPoint); clearAnonymizableCaches(); @@ -632,7 +628,6 @@ public void unlockCoin(TransactionOutPoint outPoint) { clearAnonymizableCaches(); } - //TODO: need to implement these methods public Coin getAnonymizableBalance() { return getAnonymizableBalance(false, true); } @@ -798,14 +793,7 @@ public void availableCoins(ArrayList vCoins, if (!allowUsedAddresses && isUsedDestination(wtxid, i)) { continue; } - - // our TransactionOutput doesn't have a place to put these fields, add them? - //const SigningProvider * provider = GetSigningProvider(); - - //boolean solvable = provider ? IsSolvable( * provider, pcoin->tx -> vout[i].scriptPubKey) :false; - //boolean spendable = (mine || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl -> fAllowWatchOnly && solvable)); - - vCoins.add(coin.getOutput(i));//new TransactionOutput(params, coin, coin.getOutput(i).getValue(), coin.getOutput(i).getScriptBytes())); + vCoins.add(coin.getOutput(i)); // Checks the sum amount of all UTXO's. if (nMinimumSumAmount != MAX_MONEY) { @@ -936,192 +924,6 @@ public void reorganize(StoredBlock splitPoint, List oldBlocks, List clearAnonymizableCaches(); } - /** - * Returns a list of all outputs that are being tracked by this wallet either from the {@link UTXOProvider} - * (in this case the existence or not of private keys is ignored), or the wallets internal storage (the default) - * taking into account the flags. - * - * @param excludeImmatureCoinbases Whether to ignore coinbase outputs that we will be able to spend in future once they mature. - * @param excludeUnsignable Whether to ignore outputs that we are tracking but don't have the keys to sign for. - */ -// public List calculateAllSpendCandidates(boolean excludeImmatureCoinbases, boolean excludeUnsignable, boolean isCoinJoinOnly) { -// lock.lock(); -// try { -// List candidates; -// if (getUTXOProvider() == null) { -// candidates = new ArrayList<>(myUnspents.size()); -// for (TransactionOutput output : myUnspents) { -// if (excludeUnsignable && !canSignFor(output.getScriptPubKey())) continue; -// -// // exclude non coinjoin outputs if isCoinJoinOnly is true -// // exclude coinjoin outputs when isCoinJoinOnly is false -// boolean isCoinJoin = output.isCoinJoin(this) && isFullyMixed(output); -// -// if (isCoinJoin != isCoinJoinOnly) -// continue; -// -// Transaction transaction = checkNotNull(output.getParentTransaction()); -// if (excludeImmatureCoinbases && !transaction.isMature()) -// continue; -// -// candidates.add(output); -// } -// } else { -// candidates = calculateAllSpendCandidatesFromUTXOProvider(excludeImmatureCoinbases); -// } -// return candidates; -// } finally { -// lock.unlock(); -// } -// } - - /** - * Returns the spendable coinjoin candidates from the {@link UTXOProvider} based on keys that the wallet contains. - * @return The list of candidates. - */ -// protected LinkedList calculateAllCoinJoinSpendCandidatesFromUTXOProvider(boolean mixed) { -// checkState(lock.isHeldByCurrentThread()); -// UTXOProvider utxoProvider = checkNotNull(getUTXOProvider(), "No UTXO provider has been set"); -// LinkedList candidates = Lists.newLinkedList(); -// try { -// int chainHeight = utxoProvider.getChainHeadHeight(); -// for (UTXO output : getStoredOutputsFromUTXOProvider()) { -// boolean coinbase = output.isCoinbase(); -// // Do not try and spend coinbases, they cannot be coinjoin transactions. -// if (!coinbase) { -// // TODO deterimine if this item is a coinjoin transaction -// byte [] p2pkh = ScriptPattern.extractHashFromP2PKH(output.getScript()); -// if (mixed && coinjoin.findKeyFromPubKey(p2pkh) != null) { -// candidates.add(new FreeStandingTransactionOutput(params, output, chainHeight)); -// } else if (!mixed && CoinJoin.isDenominatedAmount(output.getValue())) { -// candidates.add(new FreeStandingTransactionOutput(params, output, chainHeight)); -// } -// } -// } -// } catch (UTXOProviderException e) { -// throw new RuntimeException("UTXO provider error", e); -// } -// // We need to handle the pending transactions that we know about. -// for (Transaction tx : pending.values()) { -// // Remove the spent outputs. -// for (TransactionInput input : tx.getInputs()) { -// if (input.getConnectedOutput().isMine(this)) { -// candidates.remove(input.getConnectedOutput()); -// } -// } -// // Add change outputs. Do not try and spend coinbases that were mined too recently, the protocol forbids it. -// if (tx.isMature()) { -// for (TransactionOutput output : tx.getOutputs()) { -// if (output.isAvailableForSpending() && output.isMine(this)) { -// candidates.add(output); -// } -// } -// } -// } -// return candidates; -// } - - /** - * Returns a list of the outputs that can potentially be spent, i.e. that we have the keys for and are unspent - * according to our knowledge of the block chain. - */ -// public List calculateAllSpendCandidates() { -// return calculateAllSpendCandidates(true, true, false); -// } - - /** - * Returns a list of all outputs that are being tracked by this wallet either from the {@link UTXOProvider} - * (in this case the existence or not of private keys is ignored), or the wallets internal storage (the default) - * taking into account the flags. - * - * @param excludeImmatureCoinbases Whether to ignore coinbase outputs that we will be able to spend in future once they mature. - * @param excludeUnsignable Whether to ignore outputs that we are tracking but don't have the keys to sign for. - */ -// public List calculateAllSpendCandidates(boolean excludeImmatureCoinbases, boolean excludeUnsignable, boolean isCoinJoin) { -// lock.lock(); -// try { -// List candidates; -// if (vUTXOProvider == null) { -// candidates = new ArrayList<>(myUnspents.size()); -// for (TransactionOutput output : myUnspents) { -// if (excludeUnsignable && !canSignFor(output.getScriptPubKey())) continue; -// Transaction transaction = checkNotNull(output.getParentTransaction()); -// if (excludeImmatureCoinbases && !transaction.isMature()) -// continue; -// -// // exclude non coinjoin outputs if isCoinJoinOnly is true -// // exclude coinjoin outputs when isCoinJoinOnly is false -// boolean isOutputCoinJoin = output.isCoinJoin(this) && isFullyMixed(output); -// -// if (isCoinJoin != isOutputCoinJoin) -// continue; -// -// candidates.add(output); -// } -// } else { -// candidates = calculateAllSpendCandidatesFromUTXOProvider(excludeImmatureCoinbases, isCoinJoin); -// } -// return candidates; -// } finally { -// lock.unlock(); -// } -// } -// -// @Override -// protected LinkedList calculateAllSpendCandidatesFromUTXOProvider(boolean excludeImmatureCoinbases) { -// return calculateAllSpendCandidatesFromUTXOProvider(excludeImmatureCoinbases, false); -// } - /** - * Returns the spendable candidates from the {@link UTXOProvider} based on keys that the wallet contains. - * @return The list of candidates. - */ -// protected LinkedList calculateAllSpendCandidatesFromUTXOProvider(boolean excludeImmatureCoinbases, boolean isCoinJoinOnly) { -// checkState(lock.isHeldByCurrentThread()); -// UTXOProvider utxoProvider = checkNotNull(vUTXOProvider, "No UTXO provider has been set"); -// LinkedList candidates = Lists.newLinkedList(); -// try { -// int chainHeight = utxoProvider.getChainHeadHeight(); -// for (UTXO output : getStoredOutputsFromUTXOProvider()) { -// boolean coinjoin = false; -// if (ScriptPattern.isP2PKH(output.getScript())) -// coinjoin = isCoinJoinPubKeyHashMine(ScriptPattern.extractHashFromP2PKH(output.getScript()), Script.ScriptType.P2PKH); -// else if (ScriptPattern.isP2PK(output.getScript())) -// coinjoin = isCoinJoinPubKeyMine(ScriptPattern.extractKeyFromP2PK(output.getScript())); -// else if (ScriptPattern.isP2SH(output.getScript())) -// coinjoin = isCoinJoinPayToScriptHashMine(ScriptPattern.extractHashFromP2SH(output.getScript())); -// -// if (coinjoin != isCoinJoinOnly) -// continue; -// boolean coinbase = output.isCoinbase(); -// int depth = chainHeight - output.getHeight() + 1; // the current depth of the output (1 = same as head). -// // Do not try and spend coinbases that were mined too recently, the protocol forbids it. -// if (!excludeImmatureCoinbases || !coinbase || depth >= params.getSpendableCoinbaseDepth()) { -// candidates.add(new FreeStandingTransactionOutput(params, output, chainHeight)); -// } -// } -// } catch (UTXOProviderException e) { -// throw new RuntimeException("UTXO provider error", e); -// } -// // We need to handle the pending transactions that we know about. -// for (Transaction tx : pending.values()) { -// // Remove the spent outputs. -// for (TransactionInput input : tx.getInputs()) { -// if (input.getConnectedOutput().isMine(this)) { -// candidates.remove(input.getConnectedOutput()); -// } -// } -// // Add change outputs. Do not try and spend coinbases that were mined too recently, the protocol forbids it. -// if (!excludeImmatureCoinbases || tx.isMature()) { -// for (TransactionOutput output : tx.getOutputs()) { -// if (output.isAvailableForSpending() && output.isMine(this) && output.isCoinJoin(this) == isCoinJoinOnly) { -// candidates.add(output); -// } -// } -// } -// } -// return candidates; -// } - public CoinJoinExtension getCoinJoin() { return coinjoin; } diff --git a/core/src/test/java/org/bitcoinj/wallet/CoinJoinWalletTest.java b/core/src/test/java/org/bitcoinj/wallet/CoinJoinWalletTest.java index 96c3a959d..9f5e5c7a8 100644 --- a/core/src/test/java/org/bitcoinj/wallet/CoinJoinWalletTest.java +++ b/core/src/test/java/org/bitcoinj/wallet/CoinJoinWalletTest.java @@ -67,10 +67,10 @@ public void setUp() throws UnreadableWalletException { .seed(seed) .accountPath(DerivationPathFactory.get(TESTNET).bip44DerivationPath(0)) .build(); - //coinJoin.getKeys(KeyChain.KeyPurpose.RECEIVE_FUNDS, 500); + wallet.addAndActivateHDChain(bip44); wallet.initializeCoinJoin(); - ((WalletEx)wallet).coinjoin.getActiveKeyChain().getKeys(KeyChain.KeyPurpose.RECEIVE_FUNDS, 3000); + wallet.coinjoin.getActiveKeyChain().getKeys(KeyChain.KeyPurpose.RECEIVE_FUNDS, 3000); wallet.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.SPENT, new Transaction(TESTNET, inputTx))); ArrayList unspentTxList = Lists.newArrayList(); diff --git a/tools/src/main/java/org/bitcoinj/tools/WalletTool.java b/tools/src/main/java/org/bitcoinj/tools/WalletTool.java index c3ab9a21b..b221ab1de 100644 --- a/tools/src/main/java/org/bitcoinj/tools/WalletTool.java +++ b/tools/src/main/java/org/bitcoinj/tools/WalletTool.java @@ -687,9 +687,6 @@ private static void addAddr() { private static void send(List outputs, Coin feePerKb, String lockTimeStr, boolean allowUnconfirmed, boolean isCoinJoin) throws VerificationException { try { - //if (options.has(roundsFlag)) { - // CoinJoinClientOptions.setRounds(options.valueOf(roundsFlag)); - //} // Convert the input strings to outputs. Transaction t = new Transaction(params); for (String spec : outputs) {