[−][src]Struct lightning_invoice::InvoiceBuilder
Builder for Invoice
s. It's the most convenient and advised way to use this library. It ensures
that only a semantically and syntactically correct Invoice can be built using it.
extern crate secp256k1; extern crate lightning_invoice; extern crate bitcoin_hashes; use bitcoin_hashes::Hash; use bitcoin_hashes::sha256; use secp256k1::Secp256k1; use secp256k1::key::SecretKey; use lightning_invoice::{Currency, InvoiceBuilder}; let private_key = SecretKey::from_slice( &[ 0xe1, 0x26, 0xf6, 0x8f, 0x7e, 0xaf, 0xcc, 0x8b, 0x74, 0xf5, 0x4d, 0x26, 0x9f, 0xe2, 0x06, 0xbe, 0x71, 0x50, 0x00, 0xf9, 0x4d, 0xac, 0x06, 0x7d, 0x1c, 0x04, 0xa8, 0xca, 0x3b, 0x2d, 0xb7, 0x34 ][..] ).unwrap(); let payment_hash = sha256::Hash::from_slice(&[0; 32][..]).unwrap(); let invoice = InvoiceBuilder::new(Currency::Bitcoin) .description("Coins pls!".into()) .payment_hash(payment_hash) .current_timestamp() .build_signed(|hash| { Secp256k1::new().sign_recoverable(hash, &private_key) }) .unwrap(); assert!(invoice.to_string().starts_with("lnbc1"));
Type parameters
The two parameters D
and H
signal if the builder already contains the correct amount of the
given field:
D
: exactly oneDescription
orDescriptionHash
H
: exactly onePaymentHash
T
: the timestamp is set
Methods
impl InvoiceBuilder<False, False, False>
[src]
impl InvoiceBuilder<False, False, False>
pub fn new(currrency: Currency) -> Self | [src] |
Construct new, empty InvoiceBuilder
. All necessary fields have to be filled first before
InvoiceBuilder::build(self)
becomes available.
impl<D: Bool, H: Bool, T: Bool> InvoiceBuilder<D, H, T>
[src]
impl<D: Bool, H: Bool, T: Bool> InvoiceBuilder<D, H, T>
pub fn amount_pico_btc(self, amount: u64) -> Self | [src] |
Sets the amount in pico BTC. The optimal SI prefix is choosen automatically.
pub fn payee_pub_key(self, pub_key: PublicKey) -> Self | [src] |
Sets the payee's public key.
pub fn expiry_time(self, expiry_time: Duration) -> Self | [src] |
Sets the expiry time
pub fn min_final_cltv_expiry(self, min_final_cltv_expiry: u64) -> Self | [src] |
Sets min_final_cltv_expiry
.
pub fn fallback(self, fallback: Fallback) -> Self | [src] |
Adds a fallback address.
pub fn route(self, route: Vec<RouteHop>) -> Self | [src] |
Adds a private route.
impl<D: Bool, H: Bool> InvoiceBuilder<D, H, True>
[src]
impl<D: Bool, H: Bool> InvoiceBuilder<D, H, True>
pub fn build_raw(self) -> Result<RawInvoice, CreationError> | [src] |
Builds a RawInvoice
if no CreationError
occurred while construction any of the fields.
impl<H: Bool, T: Bool> InvoiceBuilder<False, H, T>
[src]
impl<H: Bool, T: Bool> InvoiceBuilder<False, H, T>
pub fn description(self, description: String) -> InvoiceBuilder<True, H, T> | [src] |
Set the description. This function is only available if no description (hash) was set.
pub fn description_hash( | [src] |
Set the description hash. This function is only available if no description (hash) was set.
impl<D: Bool, T: Bool> InvoiceBuilder<D, False, T>
[src]
impl<D: Bool, T: Bool> InvoiceBuilder<D, False, T>
pub fn payment_hash(self, hash: Hash) -> InvoiceBuilder<D, True, T> | [src] |
Set the payment hash. This function is only available if no payment hash was set.
impl<D: Bool, H: Bool> InvoiceBuilder<D, H, False>
[src]
impl<D: Bool, H: Bool> InvoiceBuilder<D, H, False>
pub fn timestamp(self, time: SystemTime) -> InvoiceBuilder<D, H, True> | [src] |
Sets the timestamp.
pub fn current_timestamp(self) -> InvoiceBuilder<D, H, True> | [src] |
Sets the timestamp to the current UNIX timestamp.
impl InvoiceBuilder<True, True, True>
[src]
impl InvoiceBuilder<True, True, True>
pub fn build_signed<F>(self, sign_function: F) -> Result<Invoice, CreationError> where | [src] |
Builds and signs an invoice using the supplied sign_function
. This function MAY NOT fail
and MUST produce a recoverable signature valid for the given hash and if applicable also for
the included payee public key.
pub fn try_build_signed<F, E>( | [src] |
Builds and signs an invoice using the supplied sign_function
. This function MAY fail with
an error of type E
and MUST produce a recoverable signature valid for the given hash and
if applicable also for the included payee public key.
Trait Implementations
impl<D: Clone + Bool, H: Clone + Bool, T: Clone + Bool> Clone for InvoiceBuilder<D, H, T>
[src]
impl<D: Clone + Bool, H: Clone + Bool, T: Clone + Bool> Clone for InvoiceBuilder<D, H, T>
fn clone(&self) -> InvoiceBuilder<D, H, T> | [src] |
fn clone_from(&mut self, source: &Self) | 1.0.0 [src] |
Performs copy-assignment from source
. Read more
impl<D: Eq + Bool, H: Eq + Bool, T: Eq + Bool> Eq for InvoiceBuilder<D, H, T>
[src]
impl<D: Eq + Bool, H: Eq + Bool, T: Eq + Bool> Eq for InvoiceBuilder<D, H, T>
impl<D: PartialEq + Bool, H: PartialEq + Bool, T: PartialEq + Bool> PartialEq<InvoiceBuilder<D, H, T>> for InvoiceBuilder<D, H, T>
[src]
impl<D: PartialEq + Bool, H: PartialEq + Bool, T: PartialEq + Bool> PartialEq<InvoiceBuilder<D, H, T>> for InvoiceBuilder<D, H, T>
fn eq(&self, other: &InvoiceBuilder<D, H, T>) -> bool | [src] |
fn ne(&self, other: &InvoiceBuilder<D, H, T>) -> bool | [src] |
impl<D: Debug + Bool, H: Debug + Bool, T: Debug + Bool> Debug for InvoiceBuilder<D, H, T>
[src]
impl<D: Debug + Bool, H: Debug + Bool, T: Debug + Bool> Debug for InvoiceBuilder<D, H, T>
Auto Trait Implementations
impl<D, H, T> Send for InvoiceBuilder<D, H, T> where
D: Send,
H: Send,
T: Send,
impl<D, H, T> Send for InvoiceBuilder<D, H, T> where
D: Send,
H: Send,
T: Send,
impl<D, H, T> Sync for InvoiceBuilder<D, H, T> where
D: Sync,
H: Sync,
T: Sync,
impl<D, H, T> Sync for InvoiceBuilder<D, H, T> where
D: Sync,
H: Sync,
T: Sync,
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> | [src] |
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error> | [src] |
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T | [src] |
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId | [src] |