Skip to main content

PaymentRequest

Struct PaymentRequest 

Source
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

Source

pub fn builder() -> PaymentRequestBuilder

Create a new PaymentRequestBuilder

Source§

impl PaymentRequest

CREQ-B encoding and decoding implementation

Source

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 uppercase
  • Err(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"));
Source

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 request
  • Err(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 AsRef<Option<String>> for PaymentRequest

Source§

fn as_ref(&self) -> &Option<String>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for PaymentRequest

Source§

fn clone(&self) -> PaymentRequest

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PaymentRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PaymentRequest

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<PaymentRequest, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for PaymentRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl FromStr for PaymentRequest

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<PaymentRequest, <PaymentRequest as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for PaymentRequest

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PaymentRequest

Source§

fn eq(&self, other: &PaymentRequest) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for PaymentRequest

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for PaymentRequest

Source§

impl StructuralPartialEq for PaymentRequest

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,