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 14, 2023
1 parent b1ecfad commit 97de626
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 4 deletions.
115 changes: 114 additions & 1 deletion 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"
home = "0.5.5"
lightning = "0.0.118"
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
39 changes: 39 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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(e) => {
println!(
"ERROR please provide offer starting with lno. Provided offer is \
invalid, failed to decode with error: {:?}.",
e
)
}
}
}
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod clock;
pub mod lnd;
#[allow(dead_code)]
pub mod lndk_offers;
mod onion_messenger;
mod rate_limit;

Expand Down
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 97de626

Please sign in to comment.