1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
// Copyright (c) 2022-2023 Yuki Kishimoto
// Distributed under the MIT software license
//! NIP57
//!
//! <https://github.com/nostr-protocol/nips/blob/master/57.md>
use secp256k1::XOnlyPublicKey;
use super::nip33::ParameterizedReplaceableEvent;
use crate::{EventId, UncheckedUrl};
/// Zap Request Data
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ZapRequestData {
/// Public key of the recipient
pub public_key: XOnlyPublicKey,
/// List of relays the recipient's wallet should publish its zap receipt to
pub relays: Vec<UncheckedUrl>,
/// Amount in `millisats` the sender intends to pay
pub amount: Option<u64>,
/// Lnurl pay url of the recipient, encoded using bech32 with the prefix lnurl.
pub lnurl: Option<String>,
/// Event ID
pub event_id: Option<EventId>,
/// NIP-33 event coordinate that allows tipping parameterized replaceable events such as NIP-23 long-form notes.
pub event_coordinate: Option<ParameterizedReplaceableEvent>,
}
impl ZapRequestData {
/// New Zap Request Data
pub fn new(public_key: XOnlyPublicKey, relays: Vec<UncheckedUrl>) -> Self {
Self {
public_key,
relays,
amount: None,
lnurl: None,
event_id: None,
event_coordinate: None,
}
}
/// Amount in `millisats` the sender intends to pay
pub fn amount(self, amount: u64) -> Self {
Self {
amount: Some(amount),
..self
}
}
/// Lnurl pay url of the recipient, encoded using bech32 with the prefix lnurl.
pub fn lnurl<S>(self, lnurl: S) -> Self
where
S: Into<String>,
{
Self {
lnurl: Some(lnurl.into()),
..self
}
}
/// Event ID
pub fn event_id(self, event_id: EventId) -> Self {
Self {
event_id: Some(event_id),
..self
}
}
/// NIP-33 event coordinate that allows tipping parameterized replaceable events such as NIP-23 long-form notes.
pub fn event_coordinate(self, event_coordinate: ParameterizedReplaceableEvent) -> Self {
Self {
event_coordinate: Some(event_coordinate),
..self
}
}
}