Kixunil / tonic_lnd

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

Add usage example #8

Open Kixunil opened 2 years ago

Kixunil commented 2 years ago

This should avoid people being confused like in #7

grunch commented 2 years ago

I can do a PR with some examples, but I need to figure it out some things like this one, I want to create an invoice

pub async fn add_invoice(client: &mut tonic_lnd::Client) -> Result<AddInvoiceResponse, tonic_lnd::Error> {
    let invoice = tonic_lnd::rpc::Invoice {
        memo: "test invoice".to_string(),
        value: 999,
        expiry: 3600,
    };
    let invoice = client
        .add_invoice(invoice)
        .await?
        .into_inner();

    Ok(invoice)
}

But I get this error

error[E0063]: missing fields `add_index`, `amp_invoice_state`, `amt_paid` and 21 other fields in initializer of `tonic_lnd::rpc::Invoice`
  --> src/lightning.rs:32:19
   |
32 |     let invoice = tonic_lnd::rpc::Invoice {
   |                   ^^^^^^^^^^^^^^^^^^^^^^^ missing `add_index`, `amp_invoice_state`, `amt_paid` and 21 other fields

I know this fields are in the proto, every I want lnd calculate the preimage, hash and all that stuff like when I run lncli addinvoice, how can I do this?

Kixunil commented 2 years ago

Yeah, this is one thing I dislike about prost (the crate that generates part of the tonic code) that it's not using builders. It also causes compatibility problems. :( See also https://github.com/tokio-rs/prost/issues/399

I think adding ..Default::default() at the end of the struct should help but not sure. If not you will have to fill up the fields. :(

grunch commented 2 years ago

It works perfect with ..Default::default() thank you