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: Vec<MintUrl>,
    pub mint_preferred: Option<bool>,
    pub supported_methods: Vec<SupportedMethod>,
    pub description: Option<String>,
    pub transports: Vec<Transport>,
    pub nut10: Option<Nut10SecretRequest>,
}
Expand description

NUT-18 payment request.

A receiver creates this request to tell a payer how much to send, which mints and payment methods are acceptable, and which transports can deliver the resulting PaymentRequestPayload.

Fields§

§payment_id: Option<String>

Payment id to include in the payment payload.

§amount: Option<Amount>

Requested amount net of input fees.

If this is set, Self::unit must also be set.

§unit: Option<CurrencyUnit>

Unit of the requested amount.

§single_use: Option<bool>

Whether this request is intended for a single payment.

§mints: Vec<MintUrl>

Mint URLs the receiver accepts or prefers.

If non-empty and Self::mint_preferred is omitted or false, this list is strict and the payer must only send proofs from these mints. If Self::mint_preferred is true, this list is advisory and other mints may be used.

§mint_preferred: Option<bool>

Whether Self::mints is preferred instead of strict.

true means the payer should prefer the listed mints but may send from others. false or omitted means the mint list is strict. Ignored when Self::mints is empty.

§supported_methods: Vec<SupportedMethod>

Payment methods the payer’s mint must support.

If non-empty, the payer must send ecash from a mint that supports at least one listed method. Each method can carry a fee that only applies to payments from non-preferred mints, or from any mint if no mint list is set.

§description: Option<String>

Human-readable description for the payer to display.

§transports: Vec<Transport>

Transports for delivering the payment payload, sorted by preference.

An empty list means the payment is expected to be delivered in-band by the surrounding protocol.

§nut10: Option<Nut10SecretRequest>

Optional NUT-10 locking condition requested for the payment proofs.

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: vec![MintUrl::from_str("https://mint.example.com")?],
    mint_preferred: None,
    supported_methods: vec![],
    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 (const: unstable) · 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 Eq for PaymentRequest

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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