-
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): improve asset lock handling and other fixes #244
feat(coinjoin): improve asset lock handling and other fixes #244
Conversation
* refactor: rename credit funding to asset lock * tests: update tests
public String getTransactionReport() { | ||
MonetaryFormat format = MonetaryFormat.BTC.noCode(); | ||
StringBuilder s = new StringBuilder("Transaction History Report"); | ||
s.append("\n-----------------------------------------------\n"); | ||
|
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 function will give us a high level view of transaction history that will display transactions in order by date.
public String toString() { | ||
return String.format("AssetLockPayload(creditOutputs: %d)", | ||
creditOutputs.size()); | ||
StringBuilder s = new StringBuilder("AssetLockPayload"); | ||
creditOutputs.forEach(output -> { | ||
Script scriptPubKey = output.getScriptPubKey(); | ||
s.append("\n out "); | ||
s.append(scriptPubKey.getChunks().size() > 0 ? scriptPubKey.toString() : "<no scriptPubKey>"); | ||
s.append(" "); | ||
s.append(output.getValue().toFriendlyString()); | ||
s.append('\n'); | ||
s.append(" "); | ||
Script.ScriptType scriptType = scriptPubKey.getScriptType(); | ||
s.append(scriptType).append(" addr:").append(scriptPubKey.getToAddress(params)); | ||
}); | ||
return s.toString(); | ||
} |
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 output will be similar to that of Transaction.toString
public static Script createAssetLockOutput() { | ||
ScriptBuilder builder = new ScriptBuilder(); | ||
builder.addChunk(new ScriptChunk(OP_RETURN, null)); | ||
builder.data(creditBurnKey.getPubKeyHash()); | ||
builder.data(new byte[0]); | ||
return builder.build(); | ||
} |
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.
The OP_RETURN will not have a reference to the key that will sign the state transitions that uses this asset lock. instead this information is in the AssetLockPayload.
if (version != MIN_STANDARD_VERSION) { | ||
if (getVersionShort() == SPECIAL_VERSION) { | ||
s.append(indent).append("version: ").append(getVersionShort()).append('\n'); | ||
Type type = (getVersionShort() == SPECIAL_VERSION) ? getType() : Type.TRANSACTION_NORMAL; | ||
s.append(" type: ").append(type.toString()).append('(').append(type.getValue()).append(")\n"); | ||
} else { | ||
s.append(indent).append("version: ").append(version).append('\n'); | ||
} | ||
} |
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 is to make the version number nicer to look at. This should also be added to master.
core/src/main/java/org/bitcoinj/evolution/AssetLockTransaction.java
Outdated
Show resolved
Hide resolved
* fixes bug that prevented creation of more denominations past the goal count
for (TransactionOutput output : myUnspents) { | ||
TransactionConfidence confidence = output.getParentTransaction().getConfidence(); | ||
// confirmations must be 0 or higher, not conflicted or dead | ||
if (confidence != null && (confidence.getConfidenceType() == TransactionConfidence.ConfidenceType.PENDING || confidence.getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)) { | ||
// inputValue must match, the TX is mine and is not spent | ||
if (output.getValue().equals(inputValue) && output.getSpentBy() == null) { | ||
count++; | ||
} | ||
} |
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 fixes a minor bug where spent outputs were counted. Over time this would keep some denominations from being unused, especially 0.001 and 0.01. Though there was another bug that was contributing to this too.
Also refactored to turn change this from O(n^2)
to O(n)
.
Though the output.getSpentBy() == null
is redundant because myUnspents
would only have unspent outputs.
if (balanceToDenominate.isGreaterThanOrEqualTo(Coin.ZERO)) break; | ||
if (balanceToDenominate.isLessThanOrEqualTo(Coin.ZERO)) break; |
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 problem of >
being used instead of <
meant that this for loop was not being executed when it should have been. This bug prevented part of the demomination process from running.
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.
Looks good
Issue being fixed or feature implemented
What was done?
How Has This Been Tested?
Breaking Changes
Checklist:
For repository code-owners and collaborators only