Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document amountless swaps #57

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ on:
workflow_dispatch:
inputs:
sdk-ref:
description: 'sdk commit/tag/branch reference. Defaults to 0.5.0-rc8'
description: 'sdk commit/tag/branch reference. Defaults to 0.6.0-dev1'
required: false
type: string
default: 0.5.0-rc8
default: 0.6.0-dev1

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -26,9 +26,9 @@ jobs:
runs-on: ubuntu-latest
outputs:
# Used only for Rust snippets
sdk-ref: ${{ inputs.sdk-ref || '0.5.0-rc8' }}
sdk-ref: ${{ inputs.sdk-ref || '0.6.0-dev1' }}
# Used for RN and Flutter snippets
package-version: '0.5.0-rc8'
package-version: '0.6.0-dev1'
steps:
- run: echo "set pre-setup output variables"

Expand Down
15 changes: 8 additions & 7 deletions snippets/csharp/GettingStarted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ public void FetchBalance(BindingLiquidSdk sdk)
try
{
var info = sdk.GetInfo();
var balanceSat = info?.balanceSat;
var pendingSendSat = info?.pendingSendSat;
var pendingReceiveSat = info?.pendingReceiveSat;
var balanceSat = info?.walletInfo?.balanceSat;
var pendingSendSat = info?.walletInfo?.pendingSendSat;
var pendingReceiveSat = info?.walletInfo?.pendingReceiveSat;
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: fetch-balance
}

// ANCHOR: logging
public class SdkLogger : Logger
{
Expand All @@ -55,7 +55,8 @@ public void Log(LogEntry l)
}
}

public void SetLogger(SdkLogger logger) {
public void SetLogger(SdkLogger logger)
{
try
{
BreezSdkLiquidMethods.SetLogger(logger);
Expand All @@ -70,7 +71,7 @@ public void SetLogger(SdkLogger logger) {
// ANCHOR: add-event-listener
public class SdkListener : EventListener
{
public void OnEvent(SdkEvent e)
public void OnEvent(SdkEvent e)
{
Console.WriteLine($"Received event {e}");
}
Expand Down Expand Up @@ -104,7 +105,7 @@ public void RemoveEventListener(BindingLiquidSdk sdk, String listenerId)
}
}
// ANCHOR_END: remove-event-listener

// ANCHOR: disconnect
public void Disconnect(BindingLiquidSdk sdk)
{
Expand Down
35 changes: 33 additions & 2 deletions snippets/csharp/ReceiveOnchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public void ExecuteRefund(BindingLiquidSdk sdk, uint refundTxFeeRate, Refundable
{
sdk.Refund(
new RefundRequest(
refundable.swapAddress,
destinationAddress,
refundable.swapAddress,
destinationAddress,
feeRateSatPerVbyte));
}
catch (Exception)
Expand Down Expand Up @@ -63,4 +63,35 @@ public void RecommendedFees(BindingLiquidSdk sdk)
}
// ANCHOR_END: recommended-fees
}

public void HandlePaymentsWaitingFeeAcceptance(BindingLiquidSdk sdk)
{
// ANCHOR: handle-payments-waiting-fee-acceptance
// Payments on hold waiting for fee acceptance have the state WaitingFeeAcceptance
var paymentsWaitingFeeAcceptance = sdk.ListPayments(
new ListPaymentsRequest()
{
states = new List<PaymentState>() { PaymentState.WaitingFeeAcceptance }
});

foreach (var payment in paymentsWaitingFeeAcceptance)
{
if (payment.details is not PaymentDetails.Bitcoin bitcoinDetails)
{
// Only Bitcoin payments can be `WaitingFeeAcceptance`
continue;
}

var fetchFeesResponse = sdk.FetchPaymentProposedFees(
new FetchPaymentProposedFeesRequest(bitcoinDetails.swapId));

Console.WriteLine(
$"Payer sent {fetchFeesResponse.payerAmountSat} and currently proposed fees are {fetchFeesResponse.feesSat}");

// If the user is ok with the fees, accept them, allowing the payment to proceed
sdk.AcceptPaymentProposedFees(
new AcceptPaymentProposedFeesRequest(fetchFeesResponse));
}
// ANCHOR_END: handle-payments-waiting-fee-acceptance
}
}
2 changes: 1 addition & 1 deletion snippets/csharp/Snippets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
<PackageReference Include="Breez.Sdk.Liquid" Version="*" />
</ItemGroup>

</Project>
</Project>
6 changes: 3 additions & 3 deletions snippets/dart_snippets/lib/getting_started.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Future<void> initializeSDK() async {
Future<void> fetchBalance(String lspId) async {
// ANCHOR: fetch-balance
GetInfoResponse? info = await breezSDKLiquid.instance!.getInfo();
BigInt balanceSat = info.balanceSat;
BigInt pendingSendSat = info.pendingSendSat;
BigInt pendingReceiveSat = info.pendingReceiveSat;
BigInt balanceSat = info.walletInfo.balanceSat;
BigInt pendingSendSat = info.walletInfo.pendingSendSat;
BigInt pendingReceiveSat = info.walletInfo.pendingReceiveSat;
// ANCHOR_END: fetch-balance
print(balanceSat);
print(pendingSendSat);
Expand Down
37 changes: 37 additions & 0 deletions snippets/dart_snippets/lib/receive_onchain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,40 @@ Future recommendedFees() async {
// ANCHOR_END: recommended-fees
print(fees);
}

Future<void> handlePaymentsWaitingFeeAcceptance() async {
// ANCHOR: handle-payments-waiting-fee-acceptance
// Payments on hold waiting for fee acceptance have the state WaitingFeeAcceptance
List<Payment> paymentsWaitingFeeAcceptance = await breezSDKLiquid.instance!.listPayments(
req: ListPaymentsRequest(
states: [PaymentState.waitingFeeAcceptance],
),
);

for (Payment payment in paymentsWaitingFeeAcceptance) {
if (payment.details is! PaymentDetails_Bitcoin) {
// Only Bitcoin payments can be `WaitingFeeAcceptance`
continue;
}

PaymentDetails_Bitcoin details = payment.details as PaymentDetails_Bitcoin;
FetchPaymentProposedFeesResponse fetchFeesResponse =
await breezSDKLiquid.instance!.fetchPaymentProposedFees(
req: FetchPaymentProposedFeesRequest(
swapId: details.swapId,
),
);

print(
"Payer sent ${fetchFeesResponse.payerAmountSat} and currently proposed fees are ${fetchFeesResponse.feesSat}",
);

// If the user is ok with the fees, accept them, allowing the payment to proceed
await breezSDKLiquid.instance!.acceptPaymentProposedFees(
req: AcceptPaymentProposedFeesRequest(
response: fetchFeesResponse,
),
);
}
// ANCHOR_END: handle-payments-waiting-fee-acceptance
}
4 changes: 4 additions & 0 deletions snippets/dart_snippets/lib/sdk_instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ extension ConfigCopyWith on liquid_sdk.Config {
liquid_sdk.LiquidNetwork? network,
BigInt? paymentTimeoutSec,
int? zeroConfMinFeeRateMsat,
String? syncServiceUrl,
List<liquid_sdk.ExternalInputParser>? externalInputParsers,
bool? useDefaultExternalInputParsers,
}) {
return liquid_sdk.Config(
liquidElectrumUrl: liquidElectrumUrl ?? this.liquidElectrumUrl,
Expand All @@ -195,6 +197,8 @@ extension ConfigCopyWith on liquid_sdk.Config {
network: network ?? this.network,
paymentTimeoutSec: paymentTimeoutSec ?? this.paymentTimeoutSec,
zeroConfMinFeeRateMsat: zeroConfMinFeeRateMsat ?? this.zeroConfMinFeeRateMsat,
syncServiceUrl: syncServiceUrl ?? this.syncServiceUrl,
useDefaultExternalInputParsers: useDefaultExternalInputParsers ?? this.useDefaultExternalInputParsers,
externalInputParsers: externalInputParsers ?? this.externalInputParsers,
);
}
Expand Down
28 changes: 14 additions & 14 deletions snippets/dart_snippets/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ packages:
description:
path: "."
ref: HEAD
resolved-ref: 619a9b23256820b291ddf97f3fee7224c5b084fd
resolved-ref: "0c419e0703d5f37e13a96113e71618afc5c50fd3"
url: "https://github.com/breez/breez-sdk-liquid-dart"
source: git
version: "0.5.0-rc8"
version: "0.6.0-dev1"
build_cli_annotations:
dependency: transitive
description:
Expand Down Expand Up @@ -78,10 +78,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.19.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -140,18 +140,18 @@ packages:
description:
path: "."
ref: HEAD
resolved-ref: a0ee25c652159a0c99faaf55f8b21becc5b32999
resolved-ref: "751cd4525f325b69c0652513b86170cfce480e40"
url: "https://github.com/breez/breez-sdk-liquid-flutter"
source: git
version: "0.5.0-rc8"
version: "0.6.0-dev1"
flutter_rust_bridge:
dependency: transitive
description:
name: flutter_rust_bridge
sha256: b0271cc147d5afccf9774809e4eef52b7357babe1a1a31db649df6f02dd27580
sha256: a43a6649385b853bc836ef2bc1b056c264d476c35e131d2d69c38219b5e799f1
url: "https://pub.dev"
source: hosted
version: "2.3.0"
version: "2.4.0"
freezed_annotation:
dependency: transitive
description:
Expand Down Expand Up @@ -244,18 +244,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.8.0"
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
url: "https://pub.dev"
source: hosted
version: "1.12.0"
version: "1.15.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -356,7 +356,7 @@ packages:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
version: "0.0.0"
source_map_stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -511,4 +511,4 @@ packages:
version: "2.2.1"
sdks:
dart: ">=3.4.0 <4.0.0"
flutter: ">=3.22.0"
flutter: ">=3.24.0"
4 changes: 2 additions & 2 deletions snippets/dart_snippets/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ dependencies:
breez_liquid:
git:
url: https://github.com/breez/breez-sdk-liquid-dart
tag: 0.5.0-rc8
tag: 0.6.0-dev1
flutter_breez_liquid:
git:
url: https://github.com/breez/breez-sdk-liquid-flutter
tag: 0.5.0-rc8
tag: 0.6.0-dev1
rxdart: ^0.28.0

dependency_overrides:
Expand Down
6 changes: 3 additions & 3 deletions snippets/go/getting_started.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func Start() (*breez_sdk_liquid.BindingLiquidSdk, error) {
func FetchBalance(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR: fetch-balance
if info, err := sdk.GetInfo(); err == nil {
balanceSat := info.BalanceSat
pendingSendSat := info.PendingSendSat
pendingReceiveSat := info.PendingReceiveSat
balanceSat := info.WalletInfo.BalanceSat
pendingSendSat := info.WalletInfo.PendingSendSat
pendingReceiveSat := info.WalletInfo.PendingReceiveSat
log.Printf("Balance: %v sats", balanceSat)
log.Printf("Pending: send %v sats, receive %v sats", pendingSendSat, pendingReceiveSat)
}
Expand Down
2 changes: 1 addition & 1 deletion snippets/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module main

go 1.19

require github.com/breez/breez-sdk-liquid-go v0.5.0-rc8
require github.com/breez/breez-sdk-liquid-go v0.6.0-dev1

//replace github.com/breez/breez-sdk-liquid-go => ./packages/breez-sdk-liquid-go
40 changes: 40 additions & 0 deletions snippets/go/receive_onchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,43 @@ func RecommendedFees(sdk *breez_sdk_liquid.BindingLiquidSdk) {
}
// ANCHOR_END: recommended-fees
}

func HandlePaymentsWaitingFeeAcceptance(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR: handle-payments-waiting-fee-acceptance
// Payments on hold waiting for fee acceptance have the state WaitingFeeAcceptance
request := breez_sdk_liquid.ListPaymentsRequest{
States: &[]breez_sdk_liquid.PaymentState{breez_sdk_liquid.PaymentStateWaitingFeeAcceptance},
}

paymentsWaitingFeeAcceptance, err := sdk.ListPayments(request)
if err != nil {
return
}

for _, payment := range paymentsWaitingFeeAcceptance {
bitcoinPayment, ok := payment.Details.(breez_sdk_liquid.PaymentDetailsBitcoin)
if !ok {
// Only Bitcoin payments can be `WaitingFeeAcceptance`
continue
}

fetchFeesRequest := breez_sdk_liquid.FetchPaymentProposedFeesRequest{
SwapId: bitcoinPayment.SwapId,
}

fetchFeesResponse, err := sdk.FetchPaymentProposedFees(fetchFeesRequest)
if err != nil {
continue
}

log.Printf("Payer sent %d and currently proposed fees are %d",
fetchFeesResponse.PayerAmountSat, fetchFeesResponse.FeesSat)

// If the user is ok with the fees, accept them, allowing the payment to proceed
acceptFeesRequest := breez_sdk_liquid.AcceptPaymentProposedFeesRequest{
Response: fetchFeesResponse,
}
sdk.AcceptPaymentProposedFees(acceptFeesRequest)
}
// ANCHOR_END: handle-payments-waiting-fee-acceptance
}
2 changes: 1 addition & 1 deletion snippets/kotlin_mpp_lib/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ kotlin {
}
val commonMain by getting {
dependencies {
implementation("technology.breez.liquid:breez-sdk-liquid-kmp:0.5.0-rc8")
implementation("technology.breez.liquid:breez-sdk-liquid-kmp:0.6.0-dev1")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class GettingStarted {
// ANCHOR: fetch-balance
try {
val info = sdk.getInfo()
val balanceSat = info?.balanceSat
val pendingSendSat = info?.pendingSendSat
val pendingReceiveSat = info?.pendingReceiveSat
val balanceSat = info?.walletInfo?.balanceSat
val pendingSendSat = info?.walletInfo?.pendingSendSat
val pendingReceiveSat = info?.walletInfo?.pendingReceiveSat
} catch (e: Exception) {
// handle error
}
Expand Down
Loading
Loading