9696from lightspark .scripts .lightning_fee_estimate_for_node import (
9797 LIGHTNING_FEE_ESTIMATE_FOR_NODE_QUERY ,
9898)
99+ from lightspark .scripts .outgoing_payment_for_idempotency_key import (
100+ OUTGOING_PAYMENT_FOR_IDEMPOTENCY_KEY_QUERY ,
101+ )
99102from lightspark .scripts .outgoing_payments_for_invoice import (
100103 OUTGOING_PAYMENTS_FOR_INVOICE_QUERY ,
101104)
@@ -497,6 +500,7 @@ def pay_invoice(
497500 timeout_secs : int ,
498501 maximum_fees_msats : int ,
499502 amount_msats : Optional [int ] = None ,
503+ idempotency_key : Optional [str ] = None ,
500504 ) -> OutgoingPayment :
501505 variables = {
502506 "node_id" : node_id ,
@@ -506,6 +510,8 @@ def pay_invoice(
506510 }
507511 if amount_msats is not None :
508512 variables ["amount_msats" ] = amount_msats
513+ if idempotency_key is not None :
514+ variables ["idempotency_key" ] = idempotency_key
509515 json = self ._requester .execute_graphql (
510516 PAY_INVOICE_MUTATION ,
511517 variables ,
@@ -522,6 +528,7 @@ def pay_uma_invoice(
522528 timeout_secs : int ,
523529 maximum_fees_msats : int ,
524530 amount_msats : Optional [int ] = None ,
531+ idempotency_key : Optional [str ] = None ,
525532 ) -> OutgoingPayment :
526533 variables = {
527534 "node_id" : node_id ,
@@ -531,6 +538,8 @@ def pay_uma_invoice(
531538 }
532539 if amount_msats is not None :
533540 variables ["amount_msats" ] = amount_msats
541+ if idempotency_key is not None :
542+ variables ["idempotency_key" ] = idempotency_key
534543 json = self ._requester .execute_graphql (
535544 PAY_UMA_INVOICE_MUTATION ,
536545 variables ,
@@ -615,21 +624,24 @@ def request_withdrawal(
615624 amount_sats : int ,
616625 bitcoin_address : str ,
617626 withdrawal_mode : WithdrawalMode ,
627+ idempotency_key : Optional [str ] = None ,
618628 ) -> WithdrawalRequest :
619629 """Withdraws funds from the account and sends it to the requested bitcoin address.
620630
621631 Depending on the chosen mode, it will first take the funds from the wallet, and if applicable, close channels appropriately to recover enough funds and reopen channels with the remaining funds.
622632 The process is asynchronous and may take up to a few minutes. You can check the progress by polling the `WithdrawalRequest` that is created, or by subscribing to a webhook.
623633 """
624-
634+ variables = {
635+ "node_id" : node_id ,
636+ "amount_sats" : amount_sats ,
637+ "bitcoin_address" : bitcoin_address ,
638+ "withdrawal_mode" : withdrawal_mode ,
639+ }
640+ if idempotency_key is not None :
641+ variables ["idempotency_key" ] = idempotency_key
625642 json = self ._requester .execute_graphql (
626643 REQUEST_WITHDRAWAL_MUTATION ,
627- {
628- "node_id" : node_id ,
629- "amount_sats" : amount_sats ,
630- "bitcoin_address" : bitcoin_address ,
631- "withdrawal_mode" : withdrawal_mode ,
632- },
644+ variables ,
633645 self .get_signing_key (node_id ),
634646 )
635647 return WithdrawalRequest_from_json (
@@ -723,6 +735,26 @@ def outgoing_payments_for_payment_hash(
723735 for payment in json ["outgoing_payments_for_payment_hash" ]["payments" ]
724736 ]
725737
738+ def outgoing_payment_for_idempotency_key (
739+ self ,
740+ idempotency_key : str ,
741+ ) -> Optional [OutgoingPayment ]:
742+ """
743+ Fetches the outgoing payment (if any) which have been made for a given idempotency key.
744+ """
745+
746+ json = self ._requester .execute_graphql (
747+ OUTGOING_PAYMENT_FOR_IDEMPOTENCY_KEY_QUERY ,
748+ {"idempotency_key" : idempotency_key },
749+ )
750+ if "outgoing_payment_for_idempotency_key" not in json :
751+ return None
752+ if "payment" not in json ["outgoing_payment_for_idempotency_key" ]:
753+ return None
754+ return OutgoingPayment_from_json (
755+ self ._requester , json ["outgoing_payment_for_idempotency_key" ]["payment" ]
756+ )
757+
726758 def incoming_payments_for_invoice (
727759 self ,
728760 invoice_id : str ,
0 commit comments