pub struct PaymentRequest {
pub payment_id: Option<String>,
pub amount: Option<Amount>,
pub unit: Option<CurrencyUnit>,
pub single_use: Option<bool>,
pub mints: Option<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: Option<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: Some(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 more