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

Introduce subscription support in the Wallet crate. #473

Merged
merged 2 commits into from
Dec 8, 2024

Conversation

crodas
Copy link
Contributor

@crodas crodas commented Nov 25, 2024

Description

The last bit missing to wrap up #442

The main goal is to add a subscription to CDK Mint updates into the wallet. This feature will be particularly useful for improving the code whenever loops hit the mint server to check status changes.

The goal is to add an easy-to-use interface that will hide the fact that we're connecting to WebSocket and subscribing to events. This will also hide the fact that the CDK-mint server may not support WebSocket updates.

To be fully backward compatible, the HttpClientMethods traits have a new method, subscribe, which will return an object that implements ActiveSubscription.

In the primary implementation, there is a SubscriptionClient that will attempt to connect through WebSocket and will fall to the HTTP-status pull and sleep approach (the current approach), but upper stream code will receive updates as if they come from a stream of updates through WebSocket. This SubscriptionClient struct will also manage reconnections to WebSockets (with automatic resubscriptions) and all the low-level stuff, providing an easy-to-use interface and leaving the upper-level code with a nice interface that is hard to misuse. When ActiveSubscription is dropped, it will automatically unsubscribe.


Notes to the reviewers


Suggested CHANGELOG Updates

Added Websocket subscription to the Wallet.

CHANGED

ADDED

REMOVED

FIXED


Checklist

@crodas crodas force-pushed the web-socket-for-wallet branch 7 times, most recently from 2ff8f0b to 8990de4 Compare November 27, 2024 14:51
@crodas crodas marked this pull request as draft November 27, 2024 15:23
@crodas crodas force-pushed the web-socket-for-wallet branch 4 times, most recently from 259d800 to 3e3fa23 Compare November 28, 2024 11:54
@crodas crodas marked this pull request as ready for review November 28, 2024 11:56
@crodas crodas force-pushed the web-socket-for-wallet branch 2 times, most recently from 73afc03 to cc155a9 Compare November 30, 2024 18:05
Copy link
Collaborator

@thesimplekid thesimplekid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work just a few comments.

crates/cdk/src/wallet/subscription/mod.rs Outdated Show resolved Hide resolved
crates/cdk/src/wallet/subscription/mod.rs Outdated Show resolved Hide resolved
crates/cdk/src/wallet/subscription/ws.rs Outdated Show resolved Hide resolved
crates/cdk/src/wallet/subscription/ws.rs Outdated Show resolved Hide resolved
@crodas crodas force-pushed the web-socket-for-wallet branch 3 times, most recently from b514281 to 34bd97b Compare December 4, 2024 23:40
@crodas crodas requested a review from thesimplekid December 4, 2024 23:54
@thesimplekid
Copy link
Collaborator

thesimplekid commented Dec 5, 2024

@thesimplekid thesimplekid added this to the v0.6.0 milestone Dec 5, 2024
@crodas crodas force-pushed the web-socket-for-wallet branch 2 times, most recently from f3f5d32 to 04d38ef Compare December 5, 2024 17:58
@crodas
Copy link
Contributor Author

crodas commented Dec 5, 2024

I fixed #493 in 8b3ff74

@crodas crodas force-pushed the web-socket-for-wallet branch from 47e0d58 to 2c3b683 Compare December 5, 2024 20:45
crodas added a commit to crodas/cdk that referenced this pull request Dec 6, 2024
@crodas crodas requested a review from thesimplekid December 6, 2024 15:58
crodas added a commit to crodas/cdk that referenced this pull request Dec 6, 2024
@crodas crodas force-pushed the web-socket-for-wallet branch from 641c301 to b8171ab Compare December 6, 2024 16:38
The main goal is to add a subscription to CDK Mint updates into the wallet.
This feature will be particularly useful for improving the code whenever loops
hit the mint server to check status changes.

The goal is to add an easy-to-use interface that will hide the fact that we're
connecting to WebSocket and subscribing to events. This will also hide the fact
that the CDK-mint server may not support WebSocket updates.

To be fully backward compatible, the HttpClientMethods traits have a new
method, `subscribe,` which will return an object that implements
`ActiveSubscription.`

In the primary implementation, there is a `SubscriptionClient` that will
attempt to connect through WebSocket and will fall to the HTTP-status pull and
sleep approach (the current approach), but upper stream code will receive
updates as if they come from a stream of updates through WebSocket. This
`SubscriptionClient` struct will also manage reconnections to WebSockets (with
automatic resubscriptions) and all the low-level stuff, providing an
easy-to-use interface and leaving the upper-level code with a nice interface
that is hard to misuse. When `ActiveSubscription` is dropped, it will
automatically unsubscribe.

Fixed bug with Default as described in cashubtc#473 (comment)
@thesimplekid thesimplekid force-pushed the web-socket-for-wallet branch from b8171ab to 760564c Compare December 8, 2024 16:29
Copy link
Collaborator

@thesimplekid thesimplekid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 2462168

@thesimplekid thesimplekid merged commit 2462168 into cashubtc:main Dec 8, 2024
42 checks passed
vnprc pushed a commit to vnprc/cdk that referenced this pull request Dec 18, 2024
The main goal is to add a subscription to CDK Mint updates into the wallet.
This feature will be particularly useful for improving the code whenever loops
hit the mint server to check status changes.

The goal is to add an easy-to-use interface that will hide the fact that we're
connecting to WebSocket and subscribing to events. This will also hide the fact
that the CDK-mint server may not support WebSocket updates.

To be fully backward compatible, the HttpClientMethods traits have a new
method, `subscribe,` which will return an object that implements
`ActiveSubscription.`

In the primary implementation, there is a `SubscriptionClient` that will
attempt to connect through WebSocket and will fall to the HTTP-status pull and
sleep approach (the current approach), but upper stream code will receive
updates as if they come from a stream of updates through WebSocket. This
`SubscriptionClient` struct will also manage reconnections to WebSockets (with
automatic resubscriptions) and all the low-level stuff, providing an
easy-to-use interface and leaving the upper-level code with a nice interface
that is hard to misuse. When `ActiveSubscription` is dropped, it will
automatically unsubscribe.

Fixed bug with Default as described in cashubtc#473 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants