From 055bc65bff558cc109a5bf159ec054ab3a06abd7 Mon Sep 17 00:00:00 2001 From: QcMrHyde Date: Fri, 30 May 2025 16:45:43 -0400 Subject: [PATCH] - Added code findings for WalletTransaction creation --- .../sparrow/joinstr/JoinstrPool.java | 54 ++++++++++++++++--- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/joinstr/JoinstrPool.java b/src/main/java/com/sparrowwallet/sparrow/joinstr/JoinstrPool.java index 40eb6ddd..29bc6257 100644 --- a/src/main/java/com/sparrowwallet/sparrow/joinstr/JoinstrPool.java +++ b/src/main/java/com/sparrowwallet/sparrow/joinstr/JoinstrPool.java @@ -2,23 +2,33 @@ package com.sparrowwallet.sparrow.joinstr; import com.sparrowwallet.drongo.KeyPurpose; import com.sparrowwallet.drongo.address.Address; +import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.psbt.PSBT; +import com.sparrowwallet.drongo.wallet.CoinbaseTxoFilter; +import com.sparrowwallet.drongo.wallet.FrozenTxoFilter; +import com.sparrowwallet.drongo.wallet.Payment; +import com.sparrowwallet.drongo.wallet.SpentTxoFilter; +import com.sparrowwallet.drongo.wallet.TxoFilter; +import com.sparrowwallet.drongo.wallet.UtxoSelector; +import com.sparrowwallet.drongo.wallet.WalletNode; +import com.sparrowwallet.drongo.wallet.WalletTransaction; +import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.control.QRScanDialog; import com.sparrowwallet.sparrow.net.Tor; import com.sparrowwallet.sparrow.wallet.NodeEntry; import com.sparrowwallet.sparrow.wallet.WalletForm; -import java.util.Optional; +import java.util.*; public class JoinstrPool { private final String relay; private final Integer port; private final String pubkey; - private final Double denomination; + private final long denomination; // Should be in sats, like transaction amounts private final WalletForm walletForm; // [FormController].getWalletForm() - public JoinstrPool(WalletForm walletForm,String relay, Integer port, String pubkey, Double denomination) { + public JoinstrPool(WalletForm walletForm,String relay, Integer port, String pubkey, long denomination) { this.walletForm = walletForm; this.relay = relay; @@ -40,7 +50,7 @@ public class JoinstrPool { return pubkey; } - public Double getDenomination() { + public long getDenomination() { return denomination; } @@ -59,7 +69,6 @@ public class JoinstrPool { public void createPSBT() { Address sendAddress = getNewSendAddress(); - PSBT psbt; /* String to byte[] @@ -99,10 +108,41 @@ public class JoinstrPool { psbt = txdata.getPsbt(); */ + // PSBT from WalletTransaction + + List utxoSelectors; + /// TODO select UTXO for transaction + + SpentTxoFilter spentTxoFilter = new SpentTxoFilter(null); + List txoFilters = List.of(spentTxoFilter, new FrozenTxoFilter(), new CoinbaseTxoFilter(walletForm.getWallet())); + + long satsLeft = 0L; + Payment coinjoinPayment = new Payment(sendAddress, "coinjoin", denomination, false); + /// TODO create multiple coinjoin payments for selected UTXO + Payment changePayment = new Payment(sendAddress, "change", satsLeft, false); + List payments = List.of(coinjoinPayment, changePayment); + + List opReturns = null; + + Set excludedChangeNodes; + /// TODO fill excludedChangeNodes + + double feeRate = 10.0; + double longTermFeeRate = 10.0; + Long fee = 10L; + Integer currentBlockHeight = AppServices.getCurrentBlockHeight(); + boolean groupByAddress = false; + boolean includeMempoolOutputs = false; + + WalletTransaction toSign = walletForm.getWallet().createWalletTransaction(utxoSelectors, txoFilters, payments, opReturns, excludedChangeNodes, feeRate, longTermFeeRate, fee, currentBlockHeight, groupByAddress, includeMempoolOutputs); + PSBT psbt = toSign.createPSBT(); + + // decryptedWallet.sign(psbt); + // decryptedWallet.finalise(psbt); + // Transaction transaction = psbt.extractTransaction(); + /* PSBT from Transaction - Transaction toSign; - /// TODO fill toSign PSBT psbt = new PSBT(toSign); PSBTInput psbtInput = psbt.getPsbtInputs().get(0);