feat(NIP-111): pay to relay (experimental)
This commit is contained in:
committed by
Greg Heartsfield
parent
164603dedd
commit
c0158af18b
+77
@@ -4,6 +4,32 @@ use crate::config::Settings;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const CARGO_PKG_VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
|
||||
pub const UNIT: &str = "sats";
|
||||
|
||||
/// Limitations of the relay as specified in NIP-111
|
||||
/// (This nip isn't finalized so may change)
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[allow(unused)]
|
||||
pub struct Limitation {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
payment_required: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[allow(unused)]
|
||||
pub struct Fees {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
admission: Option<Vec<Fee>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
publication: Option<Vec<Fee>>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[allow(unused)]
|
||||
pub struct Fee {
|
||||
amount: u64,
|
||||
unit: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[allow(unused)]
|
||||
@@ -24,6 +50,12 @@ pub struct RelayInfo {
|
||||
pub software: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub version: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub limitation: Option<Limitation>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub payment_url: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub fees: Option<Fees>,
|
||||
}
|
||||
|
||||
/// Convert an Info configuration into public Relay Info
|
||||
@@ -37,6 +69,48 @@ impl From<Settings> for RelayInfo {
|
||||
}
|
||||
|
||||
let i = c.info;
|
||||
let p = c.pay_to_relay;
|
||||
|
||||
let limitations = Limitation {
|
||||
payment_required: Some(p.enabled),
|
||||
};
|
||||
|
||||
let (payment_url, fees) = if p.enabled {
|
||||
let admission_fee = if p.admission_cost > 0 {
|
||||
Some(vec![Fee {
|
||||
amount: p.admission_cost,
|
||||
unit: UNIT.to_string(),
|
||||
}])
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let post_fee = if p.cost_per_event > 0 {
|
||||
Some(vec![Fee {
|
||||
amount: p.cost_per_event,
|
||||
unit: UNIT.to_string(),
|
||||
}])
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let fees = Fees {
|
||||
admission: admission_fee,
|
||||
publication: post_fee,
|
||||
};
|
||||
|
||||
let payment_url = if p.enabled && i.relay_url.is_some() {
|
||||
Some(format!(
|
||||
"{}join",
|
||||
i.relay_url.clone().unwrap().replace("ws", "http")
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
(payment_url, Some(fees))
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
RelayInfo {
|
||||
id: i.relay_url,
|
||||
@@ -47,6 +121,9 @@ impl From<Settings> for RelayInfo {
|
||||
supported_nips: Some(supported_nips),
|
||||
software: Some("https://git.sr.ht/~gheartsfield/nostr-rs-relay".to_owned()),
|
||||
version: CARGO_PKG_VERSION.map(std::borrow::ToOwned::to_owned),
|
||||
limitation: Some(limitations),
|
||||
payment_url,
|
||||
fees,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user