Skip to content
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

DRAFT push payjoin details to transaction model #372

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/_model/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Transaction with _$Transaction {
bdk.TransactionDetails? bdkTx,
// Wallet? wallet,
@Default(false) bool isSwap,
@Default(false) bool isPayjoin,
SwapTx? swapTx,
@Default(false) bool isLiquid,
@Default('') String unblindedUrl,
Expand Down
7 changes: 0 additions & 7 deletions lib/_pkg/payjoin/manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,6 @@ class PayjoinManager {
);
}

Future<List<bdk.LocalUtxo>> _listUnspent(
Wallet wallet,
bool isTestnet,
) async {
return await _walletTx.listUnspent(wallet: wallet);
}

Future<String> _processPsbt({
required String psbt,
required Wallet wallet,
Expand Down
4 changes: 3 additions & 1 deletion lib/_pkg/wallet/bdk/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ class BDKTransactions {
required List<UTXO> selectedUtxos,
int? absFee,
String? note,
bool isPayjoin = false,
}) async {
try {
final isMainnet = wallet.network == BBNetwork.Mainnet;
Expand Down Expand Up @@ -569,9 +570,10 @@ class BDKTransactions {
label: (note == null || note == '')
? labelsString
: note, // for now we just take the first label
toAddress: address,
toAddress: isPayjoin ? null : address,
outAddrs: outAddrs,
psbt: base64Encode(psbtStr),
isPayjoin: isPayjoin,
);
return ((tx, feeAmt?.toInt(), base64Encode(psbtStr)), null);
} on Exception catch (e) {
Expand Down
11 changes: 11 additions & 0 deletions lib/_pkg/wallet/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class WalletTx implements IWalletTransactions {
required bool enableRbf,
List<UTXO>? selectedUtxos,
int? absFee,
bool isPayjoin = false,
}) async {
try {
switch (wallet.baseWalletType) {
Expand All @@ -159,6 +160,7 @@ class WalletTx implements IWalletTransactions {
selectedUtxos: selectedUtxos ?? [],
note: note,
absFee: absFee,
isPayjoin: isPayjoin,
);
if (err != null) throw err;
final (tx, feeAmt, psbt) = buildResp!;
Expand All @@ -176,6 +178,15 @@ class WalletTx implements IWalletTransactions {
bdkWallet: bdkSignerWallet!,
);
if (errSign != null) throw errSign;
if (isPayjoin) {
final signedTx = tx!.copyWith(psbt: signed!.$2);
final txs = wallet.transactions.toList();
txs.add(signedTx);
final (w, errAdd) = await addUnsignedTxToWallet(
transaction: signedTx, wallet: wallet);
if (errAdd != null) throw errAdd;
return ((w, signedTx, feeAmt), null);
}
return ((wallet, tx!.copyWith(psbt: signed!.$2), feeAmt), null);
} else {
final txs = wallet.transactions.toList();
Expand Down
28 changes: 18 additions & 10 deletions lib/send/bloc/send_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,14 @@ class SendCubit extends Cubit<SendState> {
final (wallet, tx, feeAmt) = buildResp!;

if (!wallet!.watchOnly()) {
if (state.hasPjParam()) {
await payjoinBuild(
networkFees: networkFees,
originalPsbt: tx!.psbt!,
wallet: wallet,
);
}

emit(
state.copyWith(
sending: false,
Expand Down Expand Up @@ -951,8 +959,16 @@ class SendCubit extends Cubit<SendState> {
if (state.selectedWalletBloc == null) return;
if (state.payjoinSender == null) return;

// TODO copy originalPsbt.extractTx() to state.tx
// emit(state.copyWith(tx: originalPsbtTxWithId));
// Save originalPsbt to history
state.selectedWalletBloc!.add(
UpdateWallet(
wallet,
updateTypes: [
UpdateWalletTypes.transactions,
],
),
);

emit(state.copyWith(sending: true, sent: false));
await _payjoinManager.spawnSender(
isTestnet: _networkCubit.state.testnet,
Expand Down Expand Up @@ -1170,14 +1186,6 @@ class SendCubit extends Cubit<SendState> {
if (!isLn) {
final fees = _networkFeesCubit.state.selectedOrFirst(false);
await baseLayerBuild(networkFees: fees);
if (state.hasPjParam()) {
await payjoinBuild(
networkFees: fees,
originalPsbt: state.psbtSigned!,
wallet: wallet,
);
return;
}
return;
}
// context.read<WalletBloc>().state.wallet;
Expand Down
5 changes: 5 additions & 0 deletions lib/transaction/transaction_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ class _TxDetails extends StatelessWidget {
const Gap(4),
AmountValue(isReceived: isReceived, amtStr: amtStr, units: units),
const Gap(24),
if (tx.isPayjoin) ...[
const Gap(24),
const BBText.title('Payjoin'),
const Gap(4),
],
if (!isSwapPending) ...[
const BBText.title('Transaction ID'),
const Gap(4),
Expand Down