Struct breez_sdk_liquid::sdk::LiquidSdk

source ·
pub struct LiquidSdk { /* private fields */ }

Implementations§

source§

impl LiquidSdk

source

pub async fn connect(req: ConnectRequest) -> Result<Arc<LiquidSdk>>

Initializes the SDK services and starts the background tasks. This must be called to create the LiquidSdk instance.

§Arguments
  • req - the ConnectRequest containing:
    • mnemonic - the Liquid wallet mnemonic
    • config - the SDK Config
source

pub async fn disconnect(&self) -> SdkResult<()>

Disconnects the LiquidSdk instance and stops the background tasks.

source

pub async fn add_event_listener( &self, listener: Box<dyn EventListener>, ) -> SdkResult<String>

Adds an event listener to the LiquidSdk instance, where all SdkEvent’s will be emitted to. The event listener can be removed be calling LiquidSdk::remove_event_listener.

§Arguments
  • listener - The listener which is an implementation of the EventListener trait
source

pub async fn remove_event_listener(&self, id: String) -> SdkResult<()>

Removes an event listener from the LiquidSdk instance.

§Arguments
source

pub async fn get_info(&self) -> Result<GetInfoResponse>

Get the wallet info, calculating the current pending and confirmed balances.

source

pub fn sign_message( &self, req: &SignMessageRequest, ) -> SdkResult<SignMessageResponse>

Sign given message with the private key. Returns a zbase encoded signature.

source

pub fn check_message( &self, req: &CheckMessageRequest, ) -> SdkResult<CheckMessageResponse>

Check whether given message was signed by the given pubkey and the signature (zbase encoded) is valid.

source

pub async fn prepare_send_payment( &self, req: &PrepareSendRequest, ) -> Result<PrepareSendResponse, PaymentError>

Prepares to pay a Lightning invoice via a submarine swap.

§Arguments
  • req - the PrepareSendRequest containing:
    • destination - Either a Liquid BIP21 URI/address or a BOLT11 invoice
    • amount_sat - Should only be specified when paying directly onchain or via amount-less BIP21
§Returns

Returns a PrepareSendResponse containing: * destination - the parsed destination, of type SendDestination * fees_sat - the additional fees which will be paid by the sender

source

pub async fn send_payment( &self, req: &SendPaymentRequest, ) -> Result<SendPaymentResponse, PaymentError>

Either pays a Lightning invoice via a submarine swap or sends funds directly to an address.

Depending on Config’s payment_timeout_sec, this function will return:

§Arguments
§Errors
source

pub async fn fetch_lightning_limits( &self, ) -> Result<LightningPaymentLimitsResponse, PaymentError>

Fetch the current payment limits for LiquidSdk::send_payment and LiquidSdk::receive_payment.

source

pub async fn fetch_onchain_limits( &self, ) -> Result<OnchainPaymentLimitsResponse, PaymentError>

Fetch the current payment limits for LiquidSdk::pay_onchain and LiquidSdk::receive_onchain.

source

pub async fn prepare_pay_onchain( &self, req: &PreparePayOnchainRequest, ) -> Result<PreparePayOnchainResponse, PaymentError>

Prepares to pay to a Bitcoin address via a chain swap.

§Arguments
source

pub async fn pay_onchain( &self, req: &PayOnchainRequest, ) -> Result<SendPaymentResponse, PaymentError>

Pays to a Bitcoin address via a chain swap.

Depending on Config’s payment_timeout_sec, this function will return:

§Arguments
§Errors
source

pub async fn prepare_receive_payment( &self, req: &PrepareReceiveRequest, ) -> Result<PrepareReceiveResponse, PaymentError>

Prepares to receive a Lightning payment via a reverse submarine swap.

§Arguments
  • req - the PrepareReceiveRequest containing:
    • payer_amount_sat - the amount in satoshis to be paid by the payer
    • payment_method - the supported payment methods; either an invoice, a Liquid address or a Bitcoin address
source

pub async fn receive_payment( &self, req: &ReceivePaymentRequest, ) -> Result<ReceivePaymentResponse, PaymentError>

Receive a Lightning payment via a reverse submarine swap, a chain swap or via direct Liquid payment.

§Arguments
§Returns
  • A ReceivePaymentResponse containing:
    • destination - the final destination to be paid by the payer, either a BIP21 URI (Liquid or Bitcoin), a Liquid address or an invoice
source

pub async fn list_refundables(&self) -> SdkResult<Vec<RefundableSwap>>

List all failed chain swaps that need to be refunded. They can be refunded by calling LiquidSdk::prepare_refund then LiquidSdk::refund.

source

pub async fn prepare_refund( &self, req: &PrepareRefundRequest, ) -> SdkResult<PrepareRefundResponse>

Prepares to refund a failed chain swap by calculating the refund transaction size and absolute fee.

§Arguments
  • req - the PrepareRefundRequest containing:
    • swap_address - the swap address to refund from RefundableSwap::swap_address
    • refund_address - the Bitcoin address to refund to
    • sat_per_vbyte - the fee rate at which to broadcast the refund transaction
source

pub async fn refund( &self, req: &RefundRequest, ) -> Result<RefundResponse, PaymentError>

Refund a failed chain swap.

§Arguments
  • req - the RefundRequest containing:
    • swap_address - the swap address to refund from RefundableSwap::swap_address
    • refund_address - the Bitcoin address to refund to
    • sat_per_vbyte - the fee rate at which to broadcast the refund transaction
source

pub async fn rescan_onchain_swaps(&self) -> SdkResult<()>

Rescans all expired chain swaps created from calling LiquidSdk::receive_onchain within the monitoring period to check if there are any confirmed funds available to refund.

source

pub async fn prepare_buy_bitcoin( &self, req: &PrepareBuyBitcoinRequest, ) -> Result<PrepareBuyBitcoinResponse, PaymentError>

Prepares to buy Bitcoin via a chain swap.

§Arguments
source

pub async fn buy_bitcoin( &self, req: &BuyBitcoinRequest, ) -> Result<String, PaymentError>

Generate a URL to a third party provider used to buy Bitcoin via a chain swap.

§Arguments
source

pub async fn list_payments( &self, req: &ListPaymentsRequest, ) -> Result<Vec<Payment>, PaymentError>

Lists the SDK payments in reverse chronological order, from newest to oldest. The payments are determined based on onchain transactions and swaps.

source

pub fn empty_wallet_cache(&self) -> Result<()>

Empties the Liquid Wallet cache for the Config::network.

source

pub async fn sync(&self) -> SdkResult<()>

Synchronizes the local state with the mempool and onchain data.

source

pub fn backup(&self, req: BackupRequest) -> Result<()>

Backup the local state to the provided backup path.

§Arguments
source

pub fn restore(&self, req: RestoreRequest) -> Result<()>

Restores the local state from the provided backup path.

§Arguments
source

pub async fn lnurl_pay( &self, req: LnUrlPayRequest, ) -> Result<LnUrlPayResult, LnUrlPayError>

Second step of LNURL-pay. The first step is parse, which also validates the LNURL destination and generates the LnUrlPayRequest payload needed here.

This call will validate the amount_msat and comment parameters of req against the parameters of the LNURL endpoint (req_data). If they match the endpoint requirements, the LNURL payment is made.

source

pub async fn lnurl_withdraw( &self, req: LnUrlWithdrawRequest, ) -> Result<LnUrlWithdrawResult, LnUrlWithdrawError>

Second step of LNURL-withdraw. The first step is parse, which also validates the LNURL destination and generates the LnUrlWithdrawRequest payload needed here.

This call will validate the given amount_msat against the parameters of the LNURL endpoint (data). If they match the endpoint requirements, the LNURL withdraw request is made. A successful result here means the endpoint started the payment.

source

pub async fn lnurl_auth( &self, req_data: LnUrlAuthRequestData, ) -> Result<LnUrlCallbackStatus, LnUrlAuthError>

Third and last step of LNURL-auth. The first step is parse, which also validates the LNURL destination and generates the LnUrlAuthRequestData payload needed here. The second step is user approval of auth action.

This call will sign k1 of the LNURL endpoint (req_data) on secp256k1 using linkingPrivKey and DER-encodes the signature. If they match the endpoint requirements, the LNURL auth request is made. A successful result here means the client signature is verified.

source

pub async fn register_webhook(&self, webhook_url: String) -> SdkResult<()>

Register for webhook callbacks at the given webhook_url. Each created swap after registering the webhook will include the webhook_url.

This method should be called every time the application is started and when the webhook_url changes. For example, if the webhook_url contains a push notification token and the token changes after the application was started, then this method should be called to register for callbacks at the new correct webhook_url. To unregister a webhook call LiquidSdk::unregister_webhook.

source

pub async fn unregister_webhook(&self) -> SdkResult<()>

Unregister webhook callbacks. Each swap already created will continue to use the registered webhook_url until complete.

This can be called when callbacks are no longer needed or the webhook_url has changed such that it needs unregistering. For example, the token is valid but the locale changes. To register a webhook call LiquidSdk::register_webhook.

source

pub async fn fetch_fiat_rates(&self) -> Result<Vec<Rate>, SdkError>

Fetch live rates of fiat currencies, sorted by name.

source

pub async fn list_fiat_currencies(&self) -> Result<Vec<FiatCurrency>, SdkError>

List all supported fiat currencies for which there is a known exchange rate. List is sorted by the canonical name of the currency.

source

pub async fn recommended_fees(&self) -> Result<RecommendedFees, SdkError>

Get the recommended BTC fees based on the configured mempool.space instance.

source

pub fn default_config(network: LiquidNetwork) -> Config

Get the full default Config for specific LiquidNetwork.

source

pub async fn parse(input: &str) -> Result<InputType, PaymentError>

Parses a string into an InputType. See input_parser::parse.

source

pub fn parse_invoice(input: &str) -> Result<LNInvoice, PaymentError>

Parses a string into an LNInvoice. See invoice::parse_invoice.

source

pub fn init_logging( log_dir: &str, app_logger: Option<Box<dyn Log>>, ) -> Result<()>

Configures a global SDK logger that will log to file and will forward log events to an optional application-specific logger.

If called, it should be called before any SDK methods (for example, before connect).

It must be called only once in the application lifecycle. Alternatively, If the application already uses a globally-registered logger, this method shouldn’t be called at all.

§Arguments
  • log_dir: Location where the the SDK log file will be created. The directory must already exist.

  • app_logger: Optional application logger.

If the application is to use it’s own logger, but would also like the SDK to log SDK-specific log output to a file in the configured log_dir, then do not register the app-specific logger as a global logger and instead call this method with the app logger as an arg.

§Errors

An error is thrown if the log file cannot be created in the working directory.

An error is thrown if a global logger is already configured.

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

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DartSafe for T

§

impl<T> TaskRetFutTrait for T
where T: Send,