Skip to content

Commit

Permalink
Merge pull request #113 from orbitalturtle/max-width-fmt
Browse files Browse the repository at this point in the history
Cleanup: cargo fmt max comment length
  • Loading branch information
orbitalturtle authored Jun 8, 2024
2 parents b2586d7 + 27df32b commit 6132601
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 135 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
name: cargo fmt
with:
command: fmt
args: --check
args: -- --config unstable_features=true --config wrap_comments=true --config comment_width=100 --check
- uses: actions-rs/cargo@v1
name: cargo clippy
with:
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
- name: Generate code coverage
run: cargo llvm-cov --bin lndk --workspace --lcov --output-path lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
files: lcov.info
fail_ci_if_error: true
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
lndk.conf*
/.vscode
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ General guidelines for code contribution:

#### Conventions
The following conventions are use for code style (and enforced by the CI):
1. Rust format: `cargo fmt`
1. Rust format: `cargo fmt -- --config unstable_features=true --config wrap_comments=true --config comment_width=100`. We require a few config parameters when formatting to enforce a maximum comment length per-line.
2. Clippy:
```
rustup component add clippy
Expand Down
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ async fn main() -> Result<(), ()> {
return Err(());
}

// Let's grab the macaroon string now. If neither macaroon_path nor macaroon_hex are set, use the
// default macaroon path.
// Let's grab the macaroon string now. If neither macaroon_path nor macaroon_hex are
// set, use the default macaroon path.
let macaroon = match args.macaroon_path {
Some(path) => read_macaroon_from_file(path)
.map_err(|e| println!("ERROR reading macaroon from file {e:?}"))?,
Expand Down
19 changes: 11 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ impl LndkOnionMessenger {
return Err(());
}

// On startup, we want to get a list of our currently online peers to notify the onion messenger that they are
// connected. This sets up our "start state" for the messenger correctly.
// On startup, we want to get a list of our currently online peers to notify the onion
// messenger that they are connected. This sets up our "start state" for the
// messenger correctly.
let current_peers = client
.lightning()
.list_peers(tonic_lnd::lnrpc::ListPeersRequest {
Expand Down Expand Up @@ -229,7 +230,8 @@ pub struct PayOfferParams {
pub client: Client,
/// The destination the offer creator provided, which we will use to send the invoice request.
pub destination: Destination,
/// The path we will send back to the offer creator, so it knows where to send back the invoice.
/// The path we will send back to the offer creator, so it knows where to send back the
/// invoice.
pub reply_path: Option<BlindedPath>,
}

Expand All @@ -248,7 +250,8 @@ impl OfferHandler {
}
}

/// Adds an offer to be paid with the amount specified. May only be called once for a single offer.
/// Adds an offer to be paid with the amount specified. May only be called once for a single
/// offer.
pub async fn pay_offer(
&self,
cfg: PayOfferParams,
Expand Down Expand Up @@ -333,10 +336,10 @@ impl OffersMessageHandler for OfferHandler {
let secp_ctx = &Secp256k1::new();
// We verify that this invoice is a response to the invoice request we just sent.
match invoice.verify(&self.expanded_key, secp_ctx) {
// TODO: Eventually when we allow for multiple payments in flight, we can use the
// returned payment id below to check if we already processed an invoice for
// this payment. Right now it's safe to let this be because we won't try to pay
// a second invoice (if it comes through).
// TODO: Eventually when we allow for multiple payments in flight, we can use
// the returned payment id below to check if we already processed an invoice
// for this payment. Right now it's safe to let this be because we won't try to
// pay a second invoice (if it comes through).
Ok(_payment_id) => {
let mut active_invoices = self.active_invoices.lock().unwrap();
active_invoices.push(invoice.clone());
Expand Down
6 changes: 4 additions & 2 deletions src/lnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ use tonic_lnd::{Client, ConnectError};
const ONION_MESSAGES_REQUIRED: u32 = 38;
pub(crate) const ONION_MESSAGES_OPTIONAL: u32 = 39;

/// get_lnd_client connects to LND's grpc api using the config provided, blocking until a connection is established.
/// get_lnd_client connects to LND's grpc api using the config provided, blocking until a connection
/// is established.
pub fn get_lnd_client(cfg: LndCfg) -> Result<Client, ConnectError> {
match cfg.creds {
Creds::Path { macaroon, cert } => block_on(tonic_lnd::connect(cfg.address, cert, macaroon)),
Expand Down Expand Up @@ -173,7 +174,8 @@ impl Creds {
}
}

/// features_support_onion_messages returns a boolean indicating whether a feature set supports onion messaging.
/// features_support_onion_messages returns a boolean indicating whether a feature set supports
/// onion messaging.
pub fn features_support_onion_messages(features: &HashMap<u32, tonic_lnd::lnrpc::Feature>) -> bool {
features.contains_key(&ONION_MESSAGES_OPTIONAL)
|| features.contains_key(&ONION_MESSAGES_REQUIRED)
Expand Down
17 changes: 9 additions & 8 deletions src/lndk_offers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ impl OfferHandler {
) -> Result<u64, OfferError<bitcoin::secp256k1::Error>> {
let validated_amount = validate_amount(&cfg.offer, cfg.amount).await?;

// For now we connect directly to the introduction node of the blinded path so we don't need any
// intermediate nodes here. In the future we'll query for a full path to the introduction node for
// better sender privacy.
// For now we connect directly to the introduction node of the blinded path so we don't need
// any intermediate nodes here. In the future we'll query for a full path to the
// introduction node for better sender privacy.
match cfg.destination {
Destination::Node(pubkey) => connect_to_peer(cfg.client.clone(), pubkey).await?,
Destination::BlindedPath(ref path) => {
Expand Down Expand Up @@ -157,7 +157,8 @@ impl OfferHandler {
Ok(validated_amount)
}

// create_invoice_request builds and signs an invoice request, the first step in the BOLT 12 process of paying an offer.
// create_invoice_request builds and signs an invoice request, the first step in the BOLT 12
// process of paying an offer.
pub async fn create_invoice_request(
&self,
mut signer: impl MessageSigner + std::marker::Send + 'static,
Expand All @@ -182,10 +183,10 @@ impl OfferHandler {

// Generate a new payment id for this payment.
let bytes = self.messenger_utils.get_secure_random_bytes();
// We need to add some metadata to the invoice request to help with verification of the invoice
// once returned from the offer maker. Once we get an invoice back, this metadata will help us
// to determine: 1) That the invoice is truly for the invoice request we sent. 2) We don't pay
// duplicate invoices.
// We need to add some metadata to the invoice request to help with verification of the
// invoice once returned from the offer maker. Once we get an invoice back, this
// metadata will help us to determine: 1) That the invoice is truly for the invoice
// request we sent. 2) We don't pay duplicate invoices.
let unsigned_invoice_req = offer
.request_invoice_deriving_metadata(
pubkey,
Expand Down
Loading

0 comments on commit 6132601

Please sign in to comment.