Skip to main content

CkbInvoice

Struct CkbInvoice 

Source
pub struct CkbInvoice {
    pub currency: Currency,
    pub amount: Option<u128>,
    pub signature: Option<InvoiceSignature>,
    pub data: InvoiceData,
}
Expand description

Represents a syntactically and semantically correct Fiber invoice.

There are three ways to construct a CkbInvoice:

  1. using CkbInvoiceBuilder
  2. using str::parse::<CkbInvoice>(&str) (see CkbInvoice::from_str)

Fields§

§currency: Currency

The currency of the invoice.

§amount: Option<u128>

The amount of the invoice.

§signature: Option<InvoiceSignature>

The signature of the invoice.

§data: InvoiceData

The invoice data, including the payment hash, timestamp and other attributes.

Implementations§

Source§

impl CkbInvoice

Source

pub fn check_signature(&self) -> Result<(), InvoiceError>

Check that the invoice is signed correctly and that key recovery works.

Source

pub fn recover_payee_pub_key(&self) -> Result<PublicKey, Error>

Recovers the public key used for signing the invoice from the recoverable signature.

Source

pub fn payee_pub_key(&self) -> Option<&PublicKey>

Returns the payee public key if set in the invoice attributes.

Source

pub fn is_signed(&self) -> bool

Returns whether the invoice has a signature.

Source

pub fn payment_hash(&self) -> &Hash256

Returns the payment hash of the invoice.

Source

pub fn amount(&self) -> Option<u128>

Returns the amount of the invoice.

Source

pub fn udt_type_script(&self) -> Option<&PackedScript>

Returns the UDT type script if set in the invoice attributes.

Source

pub fn expiry_time(&self) -> Option<&Duration>

Returns the expiry time if set in the invoice attributes.

Source

pub fn description(&self) -> Option<&String>

Returns the description if set in the invoice attributes.

Source

pub fn final_tlc_minimum_expiry_delta(&self) -> Option<&u64>

Returns the final TLC minimum expiry delta if set in the invoice attributes.

Source

pub fn final_tlc_minimum_expiry_delta_or_default(&self) -> u64

Returns the effective final TLC minimum expiry delta.

Uses DEFAULT_FINAL_TLC_EXPIRY_DELTA when the invoice omits the corresponding attribute.

Source

pub fn fallback_address(&self) -> Option<&String>

Returns the fallback address if set in the invoice attributes.

Source

pub fn hash_algorithm(&self) -> Option<&HashAlgorithm>

Returns the hash algorithm if set in the invoice attributes.

Source

pub fn payment_secret(&self) -> Option<&Hash256>

Returns the payment secret if set in the invoice attributes.

Source

pub fn allow_mpp(&self) -> bool

Returns whether the invoice allows MPP (multi-part payments).

Source

pub fn allow_trampoline_routing(&self) -> bool

Returns whether the invoice allows trampoline routing.

Source

pub fn is_expired(&self) -> bool

Returns whether the invoice has expired based on the current time.

Source

pub fn is_tlc_expire_too_soon(&self, tlc_expiry: u64) -> bool

Returns whether the TLC expiry is too soon for the given invoice.

Source

pub fn update_signature<F>( &mut self, sign_function: F, ) -> Result<(), InvoiceError>

Updates the invoice signature using the provided signing function.

Source§

impl CkbInvoice

Source

pub fn from_str_allowing_unsigned(s: &str) -> Result<Self, InvoiceError>

Parses an invoice from its bech32m string representation, accepting both signed and unsigned invoices.

Most callers should use FromStr::from_str, which additionally requires the invoice to be signed. Only use this method in contexts where an unsigned invoice is legitimately expected (for example, decoding an invoice purely for inspection).

Trait Implementations§

Source§

impl Clone for CkbInvoice

Source§

fn clone(&self) -> CkbInvoice

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 CkbInvoice

Source§

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

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

impl<'de> Deserialize<'de> for CkbInvoice

Source§

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

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

impl Display for CkbInvoice

Source§

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

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

impl Eq for CkbInvoice

Source§

impl From<CkbInvoice> for RawCkbInvoice

Source§

fn from(invoice: CkbInvoice) -> Self

Converts to this type from the input type.
Source§

impl FromStr for CkbInvoice

Source§

type Err = InvoiceError

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

fn from_str(s: &str) -> Result<Self, Self::Err>

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

impl PartialEq for CkbInvoice

Source§

fn eq(&self, other: &CkbInvoice) -> 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 CkbInvoice

Source§

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

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

impl StructuralPartialEq for CkbInvoice

Source§

impl TryFrom<RawCkbInvoice> for CkbInvoice

Source§

type Error = InvoiceError

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

fn try_from(invoice: RawCkbInvoice) -> Result<Self, Self::Error>

Performs the conversion.

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<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Same for T

Source§

type Output = T

Should always be Self
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