Add wait_for_payment function in the wallet #963

Merged
crodas merged 2 commits from feature/wait-for-invoice into main 2025-08-18 11:57:45 +00:00
crodas commented 2025-08-13 22:15:35 +00:00 (Migrated from github.com)

Description

Fixes #941


Notes to the reviewers


Suggested CHANGELOG Updates

CHANGED

ADDED

REMOVED

FIXED


Checklist

### Description Fixes #941 ----- ### Notes to the reviewers <!-- In this section you can include notes directed to the reviewers, like explaining why some parts of the PR were done in a specific way --> ----- ### Suggested [CHANGELOG](https://github.com/cashubtc/cdk/blob/main/CHANGELOG.md) Updates <!-- Please do not edit the actual changelog but note what you changed here. --> #### CHANGED #### ADDED #### REMOVED #### FIXED ---- ### Checklist * [ ] I followed the [code style guidelines](https://github.com/cashubtc/cdk/blob/main/CODE_STYLE.md) * [ ] I ran `just final-check` before committing
thesimplekid (Migrated from github.com) requested changes 2025-08-14 15:42:04 +00:00
@ -29,7 +28,8 @@ async fn test_swap() {
let invoice = Bolt11Invoice::from_str(&mint_quote.request).unwrap();
thesimplekid (Migrated from github.com) commented 2025-08-14 15:37:02 +00:00

Don't change this now but I don't mind unwrap in tests whatever you prefer

Don't change this now but I don't mind unwrap in tests whatever you prefer
@ -0,0 +40,4 @@
}
}
}
thesimplekid (Migrated from github.com) commented 2025-08-14 15:40:39 +00:00

I think we should have another fn mint_once_paid to allow this flow:

let quote = wallet.mint_quote(amount, None).await?;

let waiter = wallet.wait_for_payment(&quote.id, Duration::from_secs(10));
let proofs = waiter.await?;

With wait_payment it does not mint once it is paid so another fn call is needed.

I think we should have another fn `mint_once_paid` to allow this flow: ``` let quote = wallet.mint_quote(amount, None).await?; let waiter = wallet.wait_for_payment(&quote.id, Duration::from_secs(10)); let proofs = waiter.await?; ``` With `wait_payment` it does not mint once it is paid so another fn call is needed.
@ -0,0 +108,4 @@
let subs = self.subscribe::<WalletSubscription>(event.into().into());
Box::pin(async move {
timeout(timeout_duration, async {
thesimplekid (Migrated from github.com) commented 2025-08-14 15:41:00 +00:00

This will fall back to polling right if the mint does not support ws?

This will fall back to polling right if the mint does not support ws?
thesimplekid commented 2025-08-14 15:42:19 +00:00 (Migrated from github.com)

Can we update the examples to use this as well

Can we update the examples to use this as well
crodas (Migrated from github.com) reviewed 2025-08-14 16:29:12 +00:00
@ -0,0 +108,4 @@
let subs = self.subscribe::<WalletSubscription>(event.into().into());
Box::pin(async move {
timeout(timeout_duration, async {
crodas (Migrated from github.com) commented 2025-08-14 16:29:12 +00:00

Yes, the subscription function already does that. There is a ws.rs client and an http.rs client

Yes, the subscription function already does that. There is a ws.rs client and an http.rs client
thesimplekid (Migrated from github.com) reviewed 2025-08-14 17:12:57 +00:00
@ -0,0 +108,4 @@
let subs = self.subscribe::<WalletSubscription>(event.into().into());
Box::pin(async move {
timeout(timeout_duration, async {
thesimplekid (Migrated from github.com) commented 2025-08-14 17:12:57 +00:00

Yeah that's what I thought just wanted to make sure. Thanks

Yeah that's what I thought just wanted to make sure. Thanks
thesimplekid (Migrated from github.com) approved these changes 2025-08-18 11:57:35 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cashubtc/cdk!963
No description provided.