Kixunil / tonic_lnd

Rust implementation of LND RPC client using async GRPC library `tonic`
31 stars 44 forks source link

Add streaming example #10

Closed yzernik closed 2 years ago

yzernik commented 2 years ago

Can I use the streaming gRPC methods? It would be nice to have an example, something like SubscribeInvoices.

Kixunil commented 2 years ago

Yes you can, I even used it myself! See https://github.com/Kixunil/loptos/blob/4390bb008bbd67b4428bbd46b6fe11dc109c4489/src/main.rs#L348-L367

yzernik commented 2 years ago

Thanks. I'll try to get a basic example working locally, and open a PR to add it here: https://github.com/Kixunil/tonic_lnd/tree/master/examples

grunch commented 2 years ago

Hi, I am using tonic_lnd too but I can't make SubscribeInvoices work correctly with my code.

I created this subscribe::invoice call which works perfectly, the problem is that this functions needs to run two .awaits, so I made it async as you can see it here:

https://github.com/grunch/cacri/blob/main/src/lightning/subscribe.rs#L12-L18

Then when I tried to call this function on main() and it doesn't work, so I called when the user make a POST /invoice

https://github.com/grunch/cacri/blob/main/src/routes.rs#L91

And it works but it stops the function there and never go to insert the record on database, I am a newbie on rust as you can tell, how can I run SubscribeInvoices when the program starts and in parallel?

grunch commented 2 years ago

BTW I did a PR with the example

https://github.com/Kixunil/tonic_lnd/pull/19

Kixunil commented 2 years ago

I don't have much time to look into it deeply right now but I think you want to call tokio::spawn(invoice(&mut client)); (no await).

grunch commented 2 years ago

I don't have much time to look into it deeply right now but I think you want to call tokio::spawn(invoice(&mut client)); (no await).

thanks I'll try that

the-kollider commented 2 years ago

Does anyone have a working example of streaming SendPayment?