Skip to content

Commit

Permalink
feat: align coinjoin signing with Dash Core, add tests (#252)
Browse files Browse the repository at this point in the history
* feat: sign coinjoin mixing tx with anyone can pay

* tests: add CoinJoinSignedInputsTest

* test was made with anyoneCanPay = false
  • Loading branch information
HashEngineering authored Apr 30, 2024
1 parent e8f0dae commit aa1d38b
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1056,10 +1056,8 @@ private boolean signFinalTransaction(Transaction finalTransactionNew, Peer node)
}
}

//KeyBag maybeDecryptingKeyBag = new DecryptingKeyBag(mixingWallet, req.aesKey);

TransactionSigner.ProposedTransaction proposal = new TransactionSigner.ProposedTransaction(finalMutableTransaction);
CoinJoinTransactionSigner signer = new CoinJoinTransactionSigner(sigs);
CoinJoinTransactionSigner signer = new CoinJoinTransactionSigner(sigs, true);

if (!signer.signInputs(proposal, mixingWallet))
log.info("{} returned false for the tx", signer.getClass().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ public class CoinJoinTransactionSigner implements TransactionSigner {
VerifyFlag.NULLDUMMY);

private final List<TransactionInput> sigs;
private final boolean anyoneCanPay;

public CoinJoinTransactionSigner(List<TransactionInput> sigs) {
public CoinJoinTransactionSigner(List<TransactionInput> sigs, boolean anyoneCanPay) {
this.sigs = sigs;
this.anyoneCanPay = anyoneCanPay;
sigs.clear();
}

Expand Down Expand Up @@ -121,8 +123,7 @@ public boolean signInputs(ProposedTransaction propTx, KeyBag keyBag) {
if (key.isEncrypted()) {
key = Context.get().coinJoinManager.requestDecryptKey(key);
}
TransactionSignature signature = tx.calculateSignature(i, key, script, Transaction.SigHash.ALL,
false);
TransactionSignature signature = tx.calculateSignature(i, key, script, Transaction.SigHash.ALL, anyoneCanPay);

// at this point we have incomplete inputScript with OP_0 in place of one or more signatures. We
// already have calculated the signature using the local key and now need to insert it in the
Expand Down
Loading

0 comments on commit aa1d38b

Please sign in to comment.