Skip to content

Commit

Permalink
Support payjoin PSBT with multiple sender inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
spacebear21 committed May 8, 2024
1 parent 2a10899 commit 865247c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/jmclient/payjoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ def request_to_psbt(self, payment_psbt_base64, sender_parameters):
# to create the PSBT we need the spent_outs for each input,
# in the right order:
spent_outs = []
sender_indices = []
for i, inp in enumerate(unsigned_payjoin_tx.vin):
input_found = False
for j, inp2 in enumerate(payment_psbt.unsigned_tx.vin):
Expand All @@ -862,7 +863,7 @@ def request_to_psbt(self, payment_psbt_base64, sender_parameters):
inp.nSequence = inp2.nSequence
spent_outs.append(payment_psbt.inputs[j].utxo)
input_found = True
sender_index = i
sender_indices.append(i)
break
if input_found:
continue
Expand Down Expand Up @@ -900,10 +901,11 @@ def request_to_psbt(self, payment_psbt_base64, sender_parameters):
assert not signresult.is_final

# with signing successful, remove the utxo field from the
# counterparty's input (this is required by BIP78). Note we don't
# counterparty's inputs (this is required by BIP78). Note we don't
# do this on PSBT creation as the psbt signing code throws ValueError
# unless utxos are present.
receiver_signed_psbt.inputs[sender_index] = btc.PSBT_Input(index=sender_index)
for sender_index in sender_indices:
receiver_signed_psbt.inputs[sender_index] = btc.PSBT_Input(index=sender_index)
log.debug("Receiver signing successful. Payjoin PSBT is now:\n{}".format(
self.wallet_service.human_readable_psbt(receiver_signed_psbt)))
# construct txoutset for the wallet service callback; we cannot use
Expand Down

0 comments on commit 865247c

Please sign in to comment.