Liquid/Lightning drain (#553)

* Attempt drain using liquid or lightning payment

* Optimize estimation handling, use address in drain estimation

* Add drain option to PrepareSendRequest

* Block draining while there are pending payments

* Apply suggestions from code review

* Rename PayOnchainAmount to PayAmount
This commit is contained in:
Ross Savage
2024-11-11 21:50:18 +01:00
committed by GitHub
parent 2c70315125
commit 4da57e3fe2
18 changed files with 503 additions and 291 deletions

View File

@@ -476,16 +476,16 @@ class OnchainPaymentLimitsResponse {
}
@freezed
sealed class PayOnchainAmount with _$PayOnchainAmount {
const PayOnchainAmount._();
sealed class PayAmount with _$PayAmount {
const PayAmount._();
/// The amount in satoshi that will be received
const factory PayOnchainAmount.receiver({
const factory PayAmount.receiver({
required BigInt amountSat,
}) = PayOnchainAmount_Receiver;
}) = PayAmount_Receiver;
/// Indicates that all available funds should be sent
const factory PayOnchainAmount.drain() = PayOnchainAmount_Drain;
const factory PayAmount.drain() = PayAmount_Drain;
}
/// An argument when calling [crate::sdk::LiquidSdk::pay_onchain].
@@ -849,7 +849,7 @@ class PrepareLnUrlPayResponse {
/// An argument when calling [crate::sdk::LiquidSdk::prepare_pay_onchain].
class PreparePayOnchainRequest {
final PayOnchainAmount amount;
final PayAmount amount;
/// The optional fee rate of the Bitcoin claim transaction in sat/vB. Defaults to the swapper estimated claim fee.
final int? feeRateSatPerVbyte;
@@ -1005,16 +1005,16 @@ class PrepareSendRequest {
final String destination;
/// Should only be set when paying directly onchain or to a BIP21 URI
/// where no amount is specified
final BigInt? amountSat;
/// where no amount is specified, or when the caller wishes to drain
final PayAmount? amount;
const PrepareSendRequest({
required this.destination,
this.amountSat,
this.amount,
});
@override
int get hashCode => destination.hashCode ^ amountSat.hashCode;
int get hashCode => destination.hashCode ^ amount.hashCode;
@override
bool operator ==(Object other) =>
@@ -1022,7 +1022,7 @@ class PrepareSendRequest {
other is PrepareSendRequest &&
runtimeType == other.runtimeType &&
destination == other.destination &&
amountSat == other.amountSat;
amount == other.amount;
}
/// Returned when calling [crate::sdk::LiquidSdk::prepare_send_payment].