-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(coinjoin): fix private send and regular send #228
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5ccce92
fix(coinjoin): fix coinjoin send and regular send
HashEngineering e8fe45d
feat(coinjoin): add and use Denomination enum
HashEngineering 6683c95
feat(coinjoin): add outputs and rounds to CoinJoinExtension.toString
HashEngineering 04ee10c
tests(coinjoin): update CoinJoinSelectorTest with simulated fully mix…
HashEngineering 98fe7cb
tests(coinjoin): update CoinJoinSelectorTest with simulated fully mix…
HashEngineering d0f0b98
refactor: cleanup InputCoin
HashEngineering 4debe05
feat: add coincontrol to SendRequest
HashEngineering a8ed528
feat: add coincontrol to TransactionBuilder.commit and change error r…
HashEngineering 2e987ea
tests(coinjoin): refactor CoinJoin related coin selector tests
HashEngineering a83f9ff
tests(coinjoin): add is fully mixed test to Wallet
HashEngineering 45ef773
tests(coinjoin): add Denomination tests
HashEngineering f037beb
doc(coinjoin): add comments to CoinControl class
HashEngineering File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
core/src/main/java/org/bitcoinj/coinjoin/Denomination.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2023 Dash Core Group | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.bitcoinj.coinjoin; | ||
|
||
import org.bitcoinj.core.Coin; | ||
|
||
public enum Denomination { | ||
TEN(Coin.COIN.multiply(10).add(Coin.valueOf(10000))), | ||
ONE(Coin.COIN.add(Coin.valueOf(1000))), | ||
TENTH(Coin.COIN.div(10).add(Coin.valueOf(100))), | ||
HUNDREDTH(Coin.COIN.div(100).add(Coin.valueOf(10))), | ||
THOUSANDTH(Coin.COIN.div(1000).add(Coin.valueOf(1))), | ||
SMALLEST(THOUSANDTH.value); | ||
|
||
final Coin value; | ||
Denomination(Coin value) { | ||
this.value = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,12 +320,14 @@ else if (ScriptPattern.isP2PKH(script)) | |
} | ||
|
||
/** | ||
* Returns true if this output is to a coinjoin related key | ||
* Returns true if this output is to a coinjoin related key and is fully mixed | ||
*/ | ||
public boolean isCoinJoin(TransactionBag transactionBag) { | ||
try { | ||
if(!isDenominated()) | ||
return false; | ||
if(!transactionBag.isFullyMixed(this)) | ||
return false; | ||
Comment on lines
+329
to
+330
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CoinJoin coins are fully mixed. |
||
|
||
Script script = getScriptPubKey(); | ||
if (ScriptPattern.isP2PK(script)) | ||
|
@@ -445,4 +447,8 @@ public int hashCode() { | |
public boolean equalsWithoutParent(TransactionOutput output) { | ||
return value == output.value && Arrays.equals(scriptBytes, output.scriptBytes); | ||
} | ||
|
||
public boolean isFullyMixed(TransactionBag transactionBag) { | ||
return transactionBag.isFullyMixed(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,10 @@ | |
import com.google.protobuf.CodedOutputStream; | ||
import org.bitcoinj.coinjoin.CoinJoin; | ||
import org.bitcoinj.coinjoin.CoinJoinClientOptions; | ||
import org.bitcoinj.core.Address; | ||
import org.bitcoinj.core.Coin; | ||
import org.bitcoinj.core.Transaction; | ||
import org.bitcoinj.core.TransactionOutPoint; | ||
import org.bitcoinj.core.TransactionOutput; | ||
import org.bitcoinj.crypto.ChildNumber; | ||
import org.bitcoinj.crypto.factory.ECKeyFactory; | ||
|
@@ -178,6 +180,7 @@ public void setRounds(int rounds) { | |
} | ||
|
||
public TreeMap<Integer, List<TransactionOutput>> getOutputs() { | ||
checkNotNull(wallet); | ||
TreeMap<Integer, List<TransactionOutput>> outputs = Maps.newTreeMap(); | ||
for (Coin amount : CoinJoin.getStandardDenominations()) { | ||
outputs.put(CoinJoin.amountToDenomination(amount), Lists.newArrayList()); | ||
|
@@ -205,8 +208,27 @@ public String toString(boolean includeLookahead, boolean includePrivateKeys, @Nu | |
int denom = entry.getKey(); | ||
List<TransactionOutput> outputs = entry.getValue(); | ||
Coin value = outputs.stream().map(TransactionOutput::getValue).reduce(Coin::add).orElse(Coin.ZERO); | ||
builder.append(CoinJoin.denominationToString(denom)).append(" ").append(outputs.size()).append(" ") | ||
builder.append(CoinJoin.denominationToString(denom)).append(" outputs:").append(outputs.size()).append(" total:") | ||
.append(value.toFriendlyString()).append("\n"); | ||
outputs.forEach(output -> { | ||
TransactionOutPoint outPoint = new TransactionOutPoint(output.getParams(), output.getIndex(), output.getParentTransactionHash()); | ||
builder.append(" addr:") | ||
.append(Address.fromPubKeyHash(output.getParams(), ScriptPattern.extractHashFromP2PKH(output.getScriptPubKey()))) | ||
.append(" outpoint:") | ||
.append(outPoint.toStringShort()) | ||
.append(" "); | ||
int rounds = ((WalletEx) wallet).getRealOutpointCoinJoinRounds(outPoint); | ||
builder.append(CoinJoin.getRoundsString(rounds)); | ||
if (rounds >= 0) { | ||
builder.append(" ").append(rounds).append(" rounds"); | ||
if (((WalletEx) wallet).isFullyMixed(outPoint)) { | ||
builder.append(" (fully mixed)"); | ||
} | ||
} else { | ||
builder.append(" ").append(output.getValue().toFriendlyString()); | ||
} | ||
builder.append("\n"); | ||
}); | ||
Comment on lines
+213
to
+231
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change will update this section in a wallet dump to include each "output" and the rounds mixed
|
||
} | ||
return builder.toString(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unmixed coins are not fully mixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about partially mixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This question will be answered later.