Code Monkey home page Code Monkey logo

lnd_rest's Introduction

lnd_rest

pipeline crates.io docs.rs

Rust wrapper to interact with the REST API of a Lightning Network Daemon node.

Usage

Add package to your Cargo.toml manifest:

cargo add lnd_rest

Add a new invoice

use lnd_rest::node::Node;
use lnd_rest::types::AddInvoiceRequest;

#[tokio::main]
async fn main() {
    let host = "your_lnd_host".to_string();
    let macaroon_path = "path/to/macaroon".to_string();
    let cert_path = "path/to/cert".to_string();

    let node = Node::init(host, macaroon_path, cert_path).await.unwrap();

    let add_invoice_request = AddInvoiceRequest {
        value_msat: 1000, // Set the invoice value in millisatoshis
        expiry: 3600, // Set the expiry time in seconds
        // Set other fields as needed
        ..Default::default()
    };

    let add_invoice_response = node.add_invoice(&add_invoice_request).await;

    match add_invoice_response {
        Ok(response) => {
            println!("Payment hash: {}", response.r_hash);
            // Access other fields as needed
        }
        Err(err) => {
            eprintln!("Error adding invoice: {}", err);
        }
    }
}

Lookup an invoice

use lnd_rest::node::Node;

#[tokio::main]
async fn main() {
    let host = "your_lnd_host".to_string();
    let macaroon_path = "path/to/macaroon".to_string();
    let cert_path = "path/to/cert".to_string();

    let node = Node::init(host, macaroon_path, cert_path).await.unwrap();

    let payment_hash = "your_payment_hash".to_string();

    let lookup_invoice_response = node.lookup_invoice(&payment_hash).await;

    match lookup_invoice_response {
        Ok(response) => {
            println!("Invoice state: {:?}", response.state);
            // Access other fields as needed
        }
        Err(err) => {
            eprintln!("Error looking up invoice: {}", err);
        }
    }
}

Pay an invoice

use lnd_rest::node::Node;
use lnd_rest::types::SendPaymentSyncRequest;

#[tokio::main]
async fn main() {
    let host = "your_lnd_host".to_string();
    let macaroon_path = "path/to/macaroon".to_string();
    let cert_path = "path/to/cert".to_string();

    let node = Node::init(host, macaroon_path, cert_path).await.unwrap();

    let send_payment_request = SendPaymentSyncRequest {
        payment_request: "your_payment_request".to_string(),
        // Set other fields as needed
        ..Default::default()
    };

    let send_payment_response = node.pay_invoice(&send_payment_request).await;

    match send_payment_response {
        Ok(response) => {
            println!("Payment preimage: {}", response.payment_preimage);
            // Access other fields as needed
        }
        Err(err) => {
            eprintln!("Error paying invoice: {}", err);
        }
    }
}

List payments

use lnd_rest::node::Node;
use lnd_rest::types::ListPaymentsRequest;

#[tokio::main]
async fn main() {
    let host = "your_lnd_host".to_string();
    let macaroon_path = "path/to/macaroon".to_string();
    let cert_path = "path/to/cert".to_string();

    let node = Node::init(host, macaroon_path, cert_path).await.unwrap();

    let list_payments_request = ListPaymentsRequest {
        include_incomplete: true, // Include incomplete payments
        // Set other fields as needed
        ..Default::default()
    };

    let list_payments_response = node.list_payments(&list_payments_request).await;

    match list_payments_response {
        Ok(response) => {
            for payment in response.payments {
                println!("Payment hash: {}", payment.payment_hash);
                // Access other fields as needed
            }
        }
        Err(err) => {
            eprintln!("Error listing payments: {}", err);
        }
    }
}

lnd_rest's People

Contributors

zenoxygen avatar

Stargazers

Luis Antonio Escobar avatar

Watchers

 avatar

lnd_rest's Issues

Error[E0560]: struct SendPaymentSyncRequest has no field named dest_custom_records - lnd_rest - (pay_invoice)

Hello @zenoxygen
Error SendPaymentSyncRequest
I am using your library to work with RUST, the part to send a uanso payment (pay_invoice) works well for me, but additionally, I want to be able to add a description/note when sending the payment, as I have investigated, I should use ( dest_custom_records: ) (An optional field that can be used to pass an arbitrary set of TLV records to a peer which understands the new records. This can be used to pass application specific data during the payment attempt. Record types are required to be in the custom range >= 65536. When using REST, the values must be encoded as base64.) https://api.lightning.community/api/lnd/lightning/send-payment-sync/index.html#lnrpcsendrequestdestcustomrecordsentry

Even though that field is not in your code, I have added it locally, but when compiling I get this error: (error[E0560]: struct SendPaymentSyncRequest has no field named dest_custom_records) even though I already added it locally it does not finish If I recognize it, do you know how I can solve it? And additionally if you know if to add a note or description when sending the payment the ideal in LND is to use the field (dest_custom_records) or if there is another way to do it.

Thanks for your help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.