pub struct InvoiceBuilder<D, H, T, C, S, M>where
D: Bool,
H: Bool,
T: Bool,
C: Bool,
S: Bool,
M: Bool,{ /* private fields */ }
Expand description
Builder for Bolt11Invoice
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;
extern crate lightning_invoice;
extern crate bitcoin_hashes;
use bitcoin_hashes::Hash;
use bitcoin_hashes::sha256;
use secp256k1::Secp256k1;
use secp256k1::SecretKey;
use lightning::ln::PaymentSecret;
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 payment_secret = PaymentSecret([42u8; 32]);
let invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("Coins pls!".into())
.payment_hash(payment_hash)
.payment_secret(payment_secret)
.current_timestamp()
.min_final_cltv_expiry_delta(144)
.build_signed(|hash| {
Secp256k1::new().sign_ecdsa_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 oneTaggedField::Description
orTaggedField::DescriptionHash
H
: exactly oneTaggedField::PaymentHash
T
: the timestamp is setC
: the CLTV expiry is setS
: the payment secret is setM
: payment metadata is set
This is not exported to bindings users as we likely need to manually select one set of boolean type parameters.
Implementations§
§impl InvoiceBuilder<False, False, False, False, False, False>
impl InvoiceBuilder<False, False, False, False, False, False>
pub fn new(
currency: Currency,
) -> InvoiceBuilder<False, False, False, False, False, False>
pub fn new( currency: Currency, ) -> InvoiceBuilder<False, False, False, False, False, False>
Construct new, empty InvoiceBuilder
. All necessary fields have to be filled first before
InvoiceBuilder::build(self)
becomes available.
§impl<D, H, T, C, S, M> InvoiceBuilder<D, H, T, C, S, M>where
D: Bool,
H: Bool,
T: Bool,
C: Bool,
S: Bool,
M: Bool,
impl<D, H, T, C, S, M> InvoiceBuilder<D, H, T, C, S, M>where
D: Bool,
H: Bool,
T: Bool,
C: Bool,
S: Bool,
M: Bool,
pub fn amount_milli_satoshis(
self,
amount_msat: u64,
) -> InvoiceBuilder<D, H, T, C, S, M>
pub fn amount_milli_satoshis( self, amount_msat: u64, ) -> InvoiceBuilder<D, H, T, C, S, M>
Sets the amount in millisatoshis. The optimal SI prefix is chosen automatically.
pub fn payee_pub_key(
self,
pub_key: PublicKey,
) -> InvoiceBuilder<D, H, T, C, S, M>
pub fn payee_pub_key( self, pub_key: PublicKey, ) -> InvoiceBuilder<D, H, T, C, S, M>
Sets the payee’s public key.
pub fn expiry_time(
self,
expiry_time: Duration,
) -> InvoiceBuilder<D, H, T, C, S, M>
pub fn expiry_time( self, expiry_time: Duration, ) -> InvoiceBuilder<D, H, T, C, S, M>
Sets the expiry time, dropping the subsecond part (which is not representable in BOLT 11 invoices).
pub fn fallback(self, fallback: Fallback) -> InvoiceBuilder<D, H, T, C, S, M>
pub fn fallback(self, fallback: Fallback) -> InvoiceBuilder<D, H, T, C, S, M>
Adds a fallback address.
pub fn private_route(self, hint: RouteHint) -> InvoiceBuilder<D, H, T, C, S, M>
pub fn private_route(self, hint: RouteHint) -> InvoiceBuilder<D, H, T, C, S, M>
Adds a private route.
§impl<D, H, C, S, M> InvoiceBuilder<D, H, True, C, S, M>where
D: Bool,
H: Bool,
C: Bool,
S: Bool,
M: Bool,
impl<D, H, C, S, M> InvoiceBuilder<D, H, True, C, S, M>where
D: Bool,
H: Bool,
C: Bool,
S: Bool,
M: Bool,
pub fn build_raw(self) -> Result<RawBolt11Invoice, CreationError>
pub fn build_raw(self) -> Result<RawBolt11Invoice, CreationError>
Builds a RawBolt11Invoice
if no CreationError
occurred while construction any of the
fields.
§impl<H, T, C, S, M> InvoiceBuilder<False, H, T, C, S, M>where
H: Bool,
T: Bool,
C: Bool,
S: Bool,
M: Bool,
impl<H, T, C, S, M> InvoiceBuilder<False, H, T, C, S, M>where
H: Bool,
T: Bool,
C: Bool,
S: Bool,
M: Bool,
pub fn description(
self,
description: String,
) -> InvoiceBuilder<True, H, T, C, S, M>
pub fn description( self, description: String, ) -> InvoiceBuilder<True, H, T, C, S, M>
Set the description. This function is only available if no description (hash) was set.
pub fn description_hash(
self,
description_hash: Hash,
) -> InvoiceBuilder<True, H, T, C, S, M>
pub fn description_hash( self, description_hash: Hash, ) -> InvoiceBuilder<True, H, T, C, S, M>
Set the description hash. This function is only available if no description (hash) was set.
pub fn invoice_description(
self,
description: Bolt11InvoiceDescription<'_>,
) -> InvoiceBuilder<True, H, T, C, S, M>
pub fn invoice_description( self, description: Bolt11InvoiceDescription<'_>, ) -> InvoiceBuilder<True, H, T, C, S, M>
Set the description or description hash. This function is only available if no description (hash) was set.
§impl<D, T, C, S, M> InvoiceBuilder<D, False, T, C, S, M>where
D: Bool,
T: Bool,
C: Bool,
S: Bool,
M: Bool,
impl<D, T, C, S, M> InvoiceBuilder<D, False, T, C, S, M>where
D: Bool,
T: Bool,
C: Bool,
S: Bool,
M: Bool,
pub fn payment_hash(self, hash: Hash) -> InvoiceBuilder<D, True, T, C, S, M>
pub fn payment_hash(self, hash: Hash) -> InvoiceBuilder<D, True, T, C, S, M>
Set the payment hash. This function is only available if no payment hash was set.
§impl<D, H, C, S, M> InvoiceBuilder<D, H, False, C, S, M>where
D: Bool,
H: Bool,
C: Bool,
S: Bool,
M: Bool,
impl<D, H, C, S, M> InvoiceBuilder<D, H, False, C, S, M>where
D: Bool,
H: Bool,
C: Bool,
S: Bool,
M: Bool,
pub fn timestamp(self, time: SystemTime) -> InvoiceBuilder<D, H, True, C, S, M>
pub fn timestamp(self, time: SystemTime) -> InvoiceBuilder<D, H, True, C, S, M>
Sets the timestamp to a specific SystemTime
.
pub fn duration_since_epoch(
self,
time: Duration,
) -> InvoiceBuilder<D, H, True, C, S, M>
pub fn duration_since_epoch( self, time: Duration, ) -> InvoiceBuilder<D, H, True, C, S, M>
Sets the timestamp to a duration since the Unix epoch, dropping the subsecond part (which is not representable in BOLT 11 invoices).
pub fn current_timestamp(self) -> InvoiceBuilder<D, H, True, C, S, M>
pub fn current_timestamp(self) -> InvoiceBuilder<D, H, True, C, S, M>
Sets the timestamp to the current system time.
§impl<D, H, T, S, M> InvoiceBuilder<D, H, T, False, S, M>where
D: Bool,
H: Bool,
T: Bool,
S: Bool,
M: Bool,
impl<D, H, T, S, M> InvoiceBuilder<D, H, T, False, S, M>where
D: Bool,
H: Bool,
T: Bool,
S: Bool,
M: Bool,
pub fn min_final_cltv_expiry_delta(
self,
min_final_cltv_expiry_delta: u64,
) -> InvoiceBuilder<D, H, T, True, S, M>
pub fn min_final_cltv_expiry_delta( self, min_final_cltv_expiry_delta: u64, ) -> InvoiceBuilder<D, H, T, True, S, M>
Sets min_final_cltv_expiry_delta
.
§impl<D, H, T, C, M> InvoiceBuilder<D, H, T, C, False, M>where
D: Bool,
H: Bool,
T: Bool,
C: Bool,
M: Bool,
impl<D, H, T, C, M> InvoiceBuilder<D, H, T, C, False, M>where
D: Bool,
H: Bool,
T: Bool,
C: Bool,
M: Bool,
pub fn payment_secret(
self,
payment_secret: PaymentSecret,
) -> InvoiceBuilder<D, H, T, C, True, M>
pub fn payment_secret( self, payment_secret: PaymentSecret, ) -> InvoiceBuilder<D, H, T, C, True, M>
Sets the payment secret and relevant features.
§impl<D, H, T, C, S> InvoiceBuilder<D, H, T, C, S, False>where
D: Bool,
H: Bool,
T: Bool,
C: Bool,
S: Bool,
impl<D, H, T, C, S> InvoiceBuilder<D, H, T, C, S, False>where
D: Bool,
H: Bool,
T: Bool,
C: Bool,
S: Bool,
pub fn payment_metadata(
self,
payment_metadata: Vec<u8>,
) -> InvoiceBuilder<D, H, T, C, S, True>
pub fn payment_metadata( self, payment_metadata: Vec<u8>, ) -> InvoiceBuilder<D, H, T, C, S, True>
Sets the payment metadata.
By default features are set to optionally allow the sender to include the payment metadata.
If you wish to require that the sender include the metadata (and fail to parse the invoice if
they don’t support payment metadata fields), you need to call
InvoiceBuilder::require_payment_metadata
after this.
§impl<D, H, T, C, S> InvoiceBuilder<D, H, T, C, S, True>where
D: Bool,
H: Bool,
T: Bool,
C: Bool,
S: Bool,
impl<D, H, T, C, S> InvoiceBuilder<D, H, T, C, S, True>where
D: Bool,
H: Bool,
T: Bool,
C: Bool,
S: Bool,
pub fn require_payment_metadata(self) -> InvoiceBuilder<D, H, T, C, S, True>
pub fn require_payment_metadata(self) -> InvoiceBuilder<D, H, T, C, S, True>
Sets forwarding of payment metadata as required. A reader of the invoice which does not support sending payment metadata will fail to read the invoice.
§impl<D, H, T, C, M> InvoiceBuilder<D, H, T, C, True, M>where
D: Bool,
H: Bool,
T: Bool,
C: Bool,
M: Bool,
impl<D, H, T, C, M> InvoiceBuilder<D, H, T, C, True, M>where
D: Bool,
H: Bool,
T: Bool,
C: Bool,
M: Bool,
pub fn basic_mpp(self) -> InvoiceBuilder<D, H, T, C, True, M>
pub fn basic_mpp(self) -> InvoiceBuilder<D, H, T, C, True, M>
Sets the basic_mpp
feature as optional.
§impl<M> InvoiceBuilder<True, True, True, True, True, M>where
M: Bool,
impl<M> InvoiceBuilder<True, True, True, True, True, M>where
M: Bool,
pub fn build_signed<F>(
self,
sign_function: F,
) -> Result<Bolt11Invoice, CreationError>
pub fn build_signed<F>( self, sign_function: F, ) -> Result<Bolt11Invoice, CreationError>
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>(
self,
sign_function: F,
) -> Result<Bolt11Invoice, SignOrCreationError<E>>
pub fn try_build_signed<F, E>( self, sign_function: F, ) -> Result<Bolt11Invoice, SignOrCreationError<E>>
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, H, T, C, S, M> Clone for InvoiceBuilder<D, H, T, C, S, M>
impl<D, H, T, C, S, M> Clone for InvoiceBuilder<D, H, T, C, S, M>
§fn clone(&self) -> InvoiceBuilder<D, H, T, C, S, M>
fn clone(&self) -> InvoiceBuilder<D, H, T, C, S, M>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl<D, H, T, C, S, M> Debug for InvoiceBuilder<D, H, T, C, S, M>
impl<D, H, T, C, S, M> Debug for InvoiceBuilder<D, H, T, C, S, M>
§impl<D, H, T, C, S, M> PartialEq for InvoiceBuilder<D, H, T, C, S, M>
impl<D, H, T, C, S, M> PartialEq for InvoiceBuilder<D, H, T, C, S, M>
impl<D, H, T, C, S, M> Eq for InvoiceBuilder<D, H, T, C, S, M>
impl<D, H, T, C, S, M> StructuralPartialEq for InvoiceBuilder<D, H, T, C, S, M>where
D: Bool,
H: Bool,
T: Bool,
C: Bool,
S: Bool,
M: Bool,
Auto Trait Implementations§
impl<D, H, T, C, S, M> Freeze for InvoiceBuilder<D, H, T, C, S, M>
impl<D, H, T, C, S, M> RefUnwindSafe for InvoiceBuilder<D, H, T, C, S, M>where
D: RefUnwindSafe,
H: RefUnwindSafe,
T: RefUnwindSafe,
C: RefUnwindSafe,
S: RefUnwindSafe,
M: RefUnwindSafe,
impl<D, H, T, C, S, M> Send for InvoiceBuilder<D, H, T, C, S, M>
impl<D, H, T, C, S, M> Sync for InvoiceBuilder<D, H, T, C, S, M>
impl<D, H, T, C, S, M> Unpin for InvoiceBuilder<D, H, T, C, S, M>
impl<D, H, T, C, S, M> UnwindSafe for InvoiceBuilder<D, H, T, C, S, M>
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request