Skip to content

Commit

Permalink
Add a basic cli binary
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalturtle committed Nov 4, 2023
1 parent bf3e07d commit bb5da5c
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 20 deletions.
147 changes: 130 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ version = "0.0.1"
edition = "2021"
repository = "https://github.com/lndk-org/lndk"

[[bin]]
name = "lndk-cli"
path = "src/cli.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[package.metadata.configure_me]
spec = "config_spec.toml"

[dependencies]
async-trait = "0.1.66"
bitcoin = { version = "0.29.2", features = ["rand"] }
clap = { version = "4.4.6", features = ["derive"] }
futures = "0.3.26"
lightning = "0.0.118"
rand_chacha = "0.3.1"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ In order for `LNDK` successfully connect to `LND`, we need to pass in the grpc a

1) These values can be passed in via the command line when running the `LNDK` program, like this:

`cargo run -- --address=<ADDRESS> --cert=<TLSPATH> --macaroon=<MACAROONPATH>`
`cargo run --bin=lndk -- --address=<ADDRESS> --cert=<TLSPATH> --macaroon=<MACAROONPATH>`

Or in a more concrete example:

`cargo run -- --address=https://localhost:10009 --cert=/home/<USERNAME>/.lnd/tls.cert --macaroon=/home/<USERNAME>/.lnd/data/chain/bitcoin/regtest/admin.macaroon`
`cargo run --bin=lndk -- --address=https://localhost:10009 --cert=/home/<USERNAME>/.lnd/tls.cert --macaroon=/home/<USERNAME>/.lnd/data/chain/bitcoin/regtest/admin.macaroon`

**Remember** that the grpc address must start with https:// for the program to work.

Expand All @@ -81,7 +81,7 @@ Or in a more concrete example:
* `address="<ADDRESS"`
* `cert="<TLSPATH>"`
* `macaroon="<MACAROONPATH>"`
* Run `cargo run -- --conf lndk.conf`
* Run `cargo run --bin=lndk -- --conf lndk.conf`

- Use any of the commands with the --help option for more information about each argument.

Expand Down
35 changes: 35 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use clap::{Parser, Subcommand};
use lndk::lndk_offers::decode;

/// A cli for interacting with lndk
#[derive(Debug, Parser)]
#[command(name = "lndk-cli")]
#[command(about = "A cli for interacting with lndk", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}

#[derive(Debug, Subcommand)]
enum Commands {
/// Decodes a bech32-encoded offer string into a BOLT 12 offer
Decode {
/// The offer string to decode
offer_string: String,
},
}

fn main() {
let args = Cli::parse();
match args.command {
Commands::Decode { offer_string } => {
println!("Decoding offer: {offer_string}");
match decode(offer_string) {
Ok(offer) => println!("Decoded offer: {:?}", offer),
Err(_) => {
println!("ERROR provided offer argument is invalid")
}
}
}
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[allow(dead_code)]
pub mod lndk_offers;
7 changes: 7 additions & 0 deletions src/lndk_offers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use lightning::offers::offer::Offer;
use lightning::offers::parse::Bolt12ParseError;

// Decodes a bech32 string into an LDK offer.
pub fn decode(offer_str: String) -> Result<Offer, Bolt12ParseError> {
offer_str.parse::<Offer>()
}

0 comments on commit bb5da5c

Please sign in to comment.