pub struct PaymentRequest {
pub payment_id: Option<String>,
pub amount: Option<Amount>,
pub unit: Option<CurrencyUnit>,
pub single_use: Option<bool>,
pub mints: Vec<MintUrl>,
pub description: Option<String>,
pub transports: Vec<Transport>,
pub nut10: Option<Nut10SecretRequest>,
}Expand description
Payment Request
Fields§
§payment_id: Option<String>Payment id
amount: Option<Amount>Amount
unit: Option<CurrencyUnit>Unit
single_use: Option<bool>Single use
mints: Vec<MintUrl>Mints
description: Option<String>Description
transports: Vec<Transport>Transport
nut10: Option<Nut10SecretRequest>Nut10
Implementations§
Source§impl PaymentRequest
impl PaymentRequest
Sourcepub fn builder() -> PaymentRequestBuilder
pub fn builder() -> PaymentRequestBuilder
Create a new PaymentRequestBuilder
Source§impl PaymentRequest
CREQ-B encoding and decoding implementation
impl PaymentRequest
CREQ-B encoding and decoding implementation
Sourcepub fn to_bech32_string(&self) -> Result<String, Error>
pub fn to_bech32_string(&self) -> Result<String, Error>
Encodes a payment request to CREQB1 bech32m format.
This function serializes a payment request according to the NUT-26 specification and encodes it using the bech32m encoding scheme with the “creqb” human-readable part (HRP). The output is always uppercase for optimal QR code compatibility.
§Returns
Returns a Result containing:
Ok(String)- The bech32m-encoded payment request string in uppercaseErr(Error)- If serialization or encoding fails
§Errors
This function will return an error if:
- The payment request cannot be serialized to TLV format
- The bech32m encoding process fails
§Specification
See NUT-26 for the complete specification of the CREQB1 payment request format.
§Examples
use std::str::FromStr;
use cashu::nuts::nut18::PaymentRequest;
use cashu::{Amount, MintUrl};
let payment_request = PaymentRequest {
payment_id: Some("test123".to_string()),
amount: Some(Amount::from(1000)),
unit: Some(cashu::nuts::CurrencyUnit::Sat),
single_use: None,
mints: vec![MintUrl::from_str("https://mint.example.com")?],
description: None,
transports: vec![],
nut10: None,
};
let encoded = payment_request.to_bech32_string()?;
assert!(encoded.starts_with("CREQB1"));Sourcepub fn from_bech32_string(s: &str) -> Result<PaymentRequest, Error>
pub fn from_bech32_string(s: &str) -> Result<PaymentRequest, Error>
Decodes a payment request from CREQB1 bech32m format.
This function takes a bech32m-encoded payment request string (case-insensitive) with the “creqb” human-readable part and deserializes it back into a payment request according to the NUT-26 specification.
§Arguments
s- The bech32m-encoded payment request string (case-insensitive)
§Returns
Returns a Result containing:
Ok(PaymentRequest)- The decoded payment requestErr(Error)- If decoding or deserialization fails
§Errors
This function will return an error if:
- The input string is not valid bech32m encoding
- The human-readable part is not “creqb” (case-insensitive)
- The decoded data cannot be deserialized into a valid payment request
- The TLV structure is malformed
§Specification
See NUT-26 for the complete specification of the CREQB1 payment request format.
§Examples
use cashu::nuts::nut18::PaymentRequest;
let encoded = "CREQB1QYQQWAR9WD6RZV3NQ5QPS6R5W3C8XW309AKKJMN59EJHSCTDWPKX2TNRDAKS4U8XXF";
let payment_request = PaymentRequest::from_bech32_string(encoded)?;
assert_eq!(payment_request.payment_id, Some("test123".to_string()));Trait Implementations§
Source§impl Clone for PaymentRequest
impl Clone for PaymentRequest
Source§fn clone(&self) -> PaymentRequest
fn clone(&self) -> PaymentRequest
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PaymentRequest
impl Debug for PaymentRequest
Source§impl<'de> Deserialize<'de> for PaymentRequest
impl<'de> Deserialize<'de> for PaymentRequest
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<PaymentRequest, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<PaymentRequest, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for PaymentRequest
impl Display for PaymentRequest
Source§impl FromStr for PaymentRequest
impl FromStr for PaymentRequest
Source§impl Hash for PaymentRequest
impl Hash for PaymentRequest
Source§impl PartialEq for PaymentRequest
impl PartialEq for PaymentRequest
Source§impl Serialize for PaymentRequest
impl Serialize for PaymentRequest
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for PaymentRequest
impl StructuralPartialEq for PaymentRequest
Auto Trait Implementations§
impl Freeze for PaymentRequest
impl RefUnwindSafe for PaymentRequest
impl Send for PaymentRequest
impl Sync for PaymentRequest
impl Unpin for PaymentRequest
impl UnsafeUnpin for PaymentRequest
impl UnwindSafe for PaymentRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.