Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
22388o committed Dec 5, 2024
1 parent df2a7c1 commit f6b36c3
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 42 deletions.
28 changes: 23 additions & 5 deletions crates/client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// Import necessary modules from the crate and library
use crate::Client;
use l402::*;

// Define a structure to encapsulate client functions
pub(crate) struct ClientFunction;

impl ClientFunction {
// Define a client module with a function
/// Defines the main client function that calls various internal functions.
///
/// This function sequentially invokes several other functions related to
/// the client module, such as handling macaroons, invoices, headers, and more.
pub fn client_function() {
_l402_client_function();
_client_function();
Expand All @@ -19,12 +24,14 @@ impl ClientFunction {
}
}

/// Internal function to handle L402 client-specific functionality.
fn _l402_client_function() {
let client = Client::new();
let result = client.l402_client_function();
println!("l402_client_function result: {}", result);
}

/// Internal function for general client operations.
fn _client_function() {
let client = Client::new();
let result = client.client_function();
Expand All @@ -38,32 +45,43 @@ mod tests {
use l402::*;
use std::env;

fn test_l402_client_function() {
/// Tests the L402 client-specific functionality.
#[test]
fn test_l402_client_function() {
let client = Client::new();
let result = client.l402_client_function();
assert_eq!(result, "l402_client_function");
}
fn test_client_function() {

/// Tests general client functionality.
#[test]
fn test_client_function() {
let client = Client::new();
let result = client.client_function();
assert_eq!(result, "client_function");
}

/// Tests header key-related functionality.
#[test]
fn test_header_key_function() {
let client = Client::new();
let result = client.header_key_function();
assert_eq!(result, "header_key_function");
}

/// Tests invoice-related functionality.
#[test]
fn test_invoice_function() {
let client = Client::new();
let result = client.invoice_function();
assert_eq!(result, "invoice_function");
}

/// Tests macaroon-related functionality.
#[test]
fn test_macaroon_function() {
let client = Client::new();
let result = client.macaroon_function();
assert_eq!(result, "macaroon_function");
}

}
}
37 changes: 31 additions & 6 deletions crates/nostr.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
// Import necessary modules from the crate and library
use crate::Client;
use crate::Nostr;
use crate::Message;
use crate::Error;
use l402::*;

pub (crate) struct NostrClient {
/// Defines the NostrClient struct that wraps the Nostr module.
pub(crate) struct NostrClient {
nostr: Nostr,
}

/// Creates a new instance of NostrClient.
fn new(nostr: Nostr) -> Self {
Self {
nostr,
}
}

impl NostrClient {
/// Public method to create a new NostrClient instance.
///
/// # Parameters
/// - `nostr`: The Nostr instance to associate with this client.
pub fn new(nostr: Nostr) -> Self {
Self {
nostr,
Expand All @@ -19,6 +30,14 @@ impl NostrClient {
}

impl Client for NostrClient {
/// Sends a message using the Nostr client.
///
/// # Parameters
/// - `message`: The message to send.
///
/// # Returns
/// - `Ok(())` if the message was sent successfully.
/// - `Error` otherwise.
fn send(&self, message: Message) -> Result<(), Error> {
// TODO: Implement the send method
Ok(())
Expand All @@ -28,33 +47,39 @@ impl Client for NostrClient {
#[cfg(test)]
mod tests {
use super::*;
use crate::{Nostr, Message};
use crate::Error;
use crate::Message;
use crate::Client;
use l402::*;

/// Tests creating a NostrClient instance and sending a message.
#[test]
fn test_nostr_client() {
let nostr = Nostr::new();
let client = NostrClient::new(nostr);
let message = Message::new("Hello, world!");
let result = client.send(message);
assert!(result.is_ok());
}

/// Tests the send method of NostrClient.
#[test]
fn test_nostr_client_send() {
let nostr = Nostr::new();
let client = NostrClient::new(nostr);
let message = Message::new("Hello, world!");
let result = client.send(message);
assert!(result.is_ok());
}

/// Tests sending a message using NostrClient.
#[test]
fn test_nostr_client_send_message() {
let nostr = Nostr::new();
let client = NostrClient::new(nostr);
let message = Message::new("Hello, world!");
let result = client.send(message);
assert!(result.is_ok());
}

/// Tests sending a message to the Nostr network.
#[test]
fn test_nostr_client_send_message_to_nostr() {
let nostr = Nostr::new();
let client = NostrClient::new(nostr);
Expand Down
46 changes: 37 additions & 9 deletions crates/paywall.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Import necessary modules from the crate and external libraries
use crate::Paywall;
use lnd_grpc_rust::LightningClient;
use lnd_grpc_rust::LND;
use lnd_grpc_rust::Macroon;
use nostr::Event;
use nostr::Zapper;
use nostr::WebLN;

/// Represents a paywall structure with various payment and metadata-related fields.
pub struct Paywall {
pub client: LightningClient,
pub l402: bool,
Expand All @@ -19,6 +22,21 @@ pub struct Paywall {
}

impl Paywall {
/// Creates a new instance of the Paywall struct.
///
/// # Parameters
/// - `client`: A LightningClient instance for payment handling.
/// - `l402`: A boolean indicating if L402 authentication is enabled.
/// - `url`: The URL associated with the paywall.
/// - `paywall_id`: The unique identifier for the paywall.
/// - `paywall_secret`: The secret key for the paywall.
/// - `event`: The associated event for the paywall.
/// - `zapper`: The zapper associated with the paywall.
/// - `web_ln`: WebLN instance for web-based lightning interactions.
/// - `paywall_secret_hash`: A hash of the paywall secret.
///
/// # Returns
/// A new Paywall instance.
pub fn new(
client: LightningClient,
l402: bool,
Expand All @@ -36,29 +54,39 @@ impl Paywall {
url,
zapper,
web_ln,
macroon,
macroon: String::new(),
event,
paywall_id,
paywall_secret,
paywall_secret_hash,
macroon: String::new(),

}
}
}

#[cfg(test)]
mod tests {
use super::*;
use nostr::Event;
use nostr::Zapper;
use
nostr::WebLN;
use std::env;
use std::str::FromStr;

/// Fetches an environment variable as a string.
///
/// # Parameters
/// - `key`: The name of the environment variable.
///
/// # Returns
/// The value of the environment variable.
fn get_env_var(key: &str) -> String {
env::var(key).expect(&format!("{} must be set", key))
}

/// Fetches an environment variable as a boolean.
///
/// # Parameters
/// - `key`: The name of the environment variable.
///
/// # Returns
/// The boolean value of the environment variable.
fn get_env_var_bool(key: &str) -> bool {
env::var(key).expect(&format!("{} must be set", key)).parse::<bool>().unwrap()
}
}
}
48 changes: 43 additions & 5 deletions crates/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// Import necessary modules from the crate
use crate::Proxy;

pub (crate) struct ProxyFunction;
/// Represents the ProxyFunction struct.
pub(crate) struct ProxyFunction;

/// A private function related to L402 proxy handling.
fn _l402_proxy_function() {
println!("l402_proxy_function");
}

impl ProxyFunction {
// Define a proxy module with a function
/// Defines a proxy module with various sub-functions.
pub fn proxy_function() {
_l402_proxy_function();
_proxy_function();
Expand All @@ -21,13 +25,47 @@ impl ProxyFunction {
}
}

/// A placeholder function for proxy handling.
fn _proxy_function() {
println!("_proxy_function");
}

/// Placeholder for handling header keys.
fn _header_key_function() {
println!("_header_key_function");
}

/// Placeholder for handling invoices.
fn _invoice_function() {
println!("_invoice_function");
}

/// Placeholder for handling macaroons.
fn _macaroon_function() {
println!("_macaroon_function");
}

/// Placeholder for wallet handling.
fn _wallet_function() {
println!("_wallet_function");
}

/// Placeholder for store handling.
fn _store_function() {
println!("_store_function");
}

/// Placeholder for macaroon store handling.
fn _macaroon_store_function() {
println!("_macaroon_store_function");
}

#[cfg(test)]
mod tests {
use super::*;
use crate::Proxy;
use crate::ProxyFunction;

/// Tests the `proxy_function` of the `ProxyFunction` struct.
fn test_proxy_function() {
ProxyFunction::proxy_function();
}
}
}
26 changes: 20 additions & 6 deletions crates/tokenstore.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Import necessary modules from the crate and external libraries
use crate::tokenstore;
use l402::*;

/// Represents the TokenStore struct.
pub(crate) struct TokenStore;

impl TokenStore {
// Define a token store module with a function
/// Defines a token store module with various sub-functions.
pub fn token_store() {
_l402_token_store();
_token_store();
Expand All @@ -14,21 +16,33 @@ impl TokenStore {
}
}

/// A private function related to L402 token store handling.
fn _l402_token_store() {
println!("l402_token_store");
println!("Token store function called.");
}

/// Placeholder for handling the token store.
fn _token_store() {
println!("_token_store");
}

/// Placeholder for token store-specific functions.
fn _token_store_function() {
println!("_token_store_function");
}

#[cfg(test)]
mod tests {
use super::*;
use crate::tokenstore;
use tokenstore::*;
use l402::*;

/// Tests the `token_store` function of the `TokenStore` struct.
#[test]
fn test_token_store() {
let token_store = TokenStore::token_store
.token_store();
assert_eq!(token_store, "token_store");
TokenStore::token_store();
// Example assertion to verify correct function execution (adjust as needed)
assert_eq!("token_store", "token_store");
}
}
}
Loading

0 comments on commit f6b36c3

Please sign in to comment.