Skip to content

Commit

Permalink
make maxSendable dynamic through env variables
Browse files Browse the repository at this point in the history
Signed-off-by: Nitesh Balusu <[email protected]>
  • Loading branch information
niteshbalusu11 committed Apr 22, 2024
1 parent e24202d commit 76cd30c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
},
}
}
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/server/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub enum EnvVariables {
NOSTR_PRIVATE_KEY,
NIP_05_PUBKEY,
RELAYS,
MAX_SENDABLE,
}

impl AsRef<OsStr> for EnvVariables {
Expand All @@ -64,6 +65,7 @@ impl AsRef<OsStr> 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"),
}
}
}
Expand Down
23 changes: 21 additions & 2 deletions src/server/parsing_functions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::env;

use hyper::{Body, Response, StatusCode};
use rusted_nostr_tools::{
event_methods::{get_event_hash, SignedEvent, UnsignedEvent},
Expand All @@ -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)
Expand Down Expand Up @@ -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::<i64>()
{
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",
Expand Down

0 comments on commit 76cd30c

Please sign in to comment.