- Added code findings for WalletTransaction creation

This commit is contained in:
QcMrHyde 2025-05-30 16:45:43 -04:00
parent b1a3dc6411
commit 055bc65bff

View file

@ -2,23 +2,33 @@ package com.sparrowwallet.sparrow.joinstr;
import com.sparrowwallet.drongo.KeyPurpose; import com.sparrowwallet.drongo.KeyPurpose;
import com.sparrowwallet.drongo.address.Address; import com.sparrowwallet.drongo.address.Address;
import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.psbt.PSBT; 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.control.QRScanDialog;
import com.sparrowwallet.sparrow.net.Tor; import com.sparrowwallet.sparrow.net.Tor;
import com.sparrowwallet.sparrow.wallet.NodeEntry; import com.sparrowwallet.sparrow.wallet.NodeEntry;
import com.sparrowwallet.sparrow.wallet.WalletForm; import com.sparrowwallet.sparrow.wallet.WalletForm;
import java.util.Optional; import java.util.*;
public class JoinstrPool { public class JoinstrPool {
private final String relay; private final String relay;
private final Integer port; private final Integer port;
private final String pubkey; 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() 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.walletForm = walletForm;
this.relay = relay; this.relay = relay;
@ -40,7 +50,7 @@ public class JoinstrPool {
return pubkey; return pubkey;
} }
public Double getDenomination() { public long getDenomination() {
return denomination; return denomination;
} }
@ -59,7 +69,6 @@ public class JoinstrPool {
public void createPSBT() { public void createPSBT() {
Address sendAddress = getNewSendAddress(); Address sendAddress = getNewSendAddress();
PSBT psbt;
/* String to byte[] /* String to byte[]
@ -99,10 +108,41 @@ public class JoinstrPool {
psbt = txdata.getPsbt(); psbt = txdata.getPsbt();
*/ */
// PSBT from WalletTransaction
List<UtxoSelector> utxoSelectors;
/// TODO select UTXO for transaction
SpentTxoFilter spentTxoFilter = new SpentTxoFilter(null);
List<TxoFilter> 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<Payment> payments = List.of(coinjoinPayment, changePayment);
List<byte[]> opReturns = null;
Set<WalletNode> 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 /* PSBT from Transaction
Transaction toSign;
/// TODO fill toSign
PSBT psbt = new PSBT(toSign); PSBT psbt = new PSBT(toSign);
PSBTInput psbtInput = psbt.getPsbtInputs().get(0); PSBTInput psbtInput = psbt.getPsbtInputs().get(0);