diff --git a/.env.example b/.env.example index a58a88d..82bb576 100644 --- a/.env.example +++ b/.env.example @@ -11,3 +11,4 @@ INCLUDE_HOP_HINTS=true # Adds route hints to an invoice NOSTR_PRIVATE_KEY="Random nsec or hex private key to sign zaps" NIP_05_PUBKEY="Your npub or hex public key" RELAYS="wss://relay.nostr.band, wss://nostr-pub.wellorder.net, wss://brb.io" # comma separated list of relays +MAX_SENDABLE=100000 #Max amount someone can send you in milli sats. diff --git a/.vscode/settings.json b/.vscode/settings.json index 024c385..d65d167 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "[rust]": { - "editor.defaultFormatter": "rust-lang.rust-analyzer", - "editor.formatOnSave": true + "editor.defaultFormatter": "rust-lang.rust-analyzer", + "editor.formatOnSave": true }, -} \ No newline at end of file +} diff --git a/Cargo.lock b/Cargo.lock index ef51d67..898a4cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1286,7 +1286,7 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustdress" -version = "0.4.14" +version = "0.5.14" dependencies = [ "anyhow", "bech32", diff --git a/Cargo.toml b/Cargo.toml index 80643ce..652d390 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustdress" -version = "0.4.14" +version = "0.5.14" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/server/constants.rs b/src/server/constants.rs index 33096b4..439d5ea 100644 --- a/src/server/constants.rs +++ b/src/server/constants.rs @@ -46,6 +46,7 @@ pub enum EnvVariables { NOSTR_PRIVATE_KEY, NIP_05_PUBKEY, RELAYS, + MAX_SENDABLE, } impl AsRef for EnvVariables { @@ -64,6 +65,7 @@ impl AsRef for EnvVariables { EnvVariables::NOSTR_PRIVATE_KEY => OsStr::new("NOSTR_PRIVATE_KEY"), EnvVariables::NIP_05_PUBKEY => OsStr::new("NIP_05_PUBKEY"), EnvVariables::RELAYS => OsStr::new("RELAYS"), + EnvVariables::MAX_SENDABLE => OsStr::new("MAX_SENDABLE"), } } } diff --git a/src/server/parsing_functions.rs b/src/server/parsing_functions.rs index 15a0dc6..6f0f1e2 100644 --- a/src/server/parsing_functions.rs +++ b/src/server/parsing_functions.rs @@ -1,3 +1,5 @@ +use std::env; + use hyper::{Body, Response, StatusCode}; use rusted_nostr_tools::{ event_methods::{get_event_hash, SignedEvent, UnsignedEvent}, @@ -9,7 +11,10 @@ use urlencoding::decode; use crate::server::constants::CONSTANTS; -use super::utils::{get_identifiers, get_nostr_keys}; +use super::{ + constants::EnvVariables, + utils::{get_identifiers, get_nostr_keys}, +}; pub fn find_key<'a>(key: &'a str, vector: &'a [(String, String)]) -> Option<&'a (String, String)> { vector.iter().find(|(k, _)| *k == key) @@ -202,10 +207,24 @@ pub fn handle_response_body() -> String { let lnurl_url = "https://".to_owned() + &domain + "/.well-known/lnurlp/" + username.as_str(); + let max_sendable = match env::var(EnvVariables::MAX_SENDABLE) + .unwrap_or(CONSTANTS.max_sendamount.to_string()) + .parse::() + { + Ok(n) => { + if n < 1000 { + CONSTANTS.max_sendamount + } else { + n + } + } + Err(_) => CONSTANTS.max_sendamount, + }; + let mut response_body = json!({ "callback": lnurl_url, "commentAllowed": CONSTANTS.max_comment_length, - "maxSendable": CONSTANTS.max_sendamount, + "maxSendable": max_sendable, "metadata": metadata, "minSendable": CONSTANTS.min_sendamount, "tag": "payRequest",