Skip to content

Commit

Permalink
Merge pull request #50 from breez/savage-send-payment-drain
Browse files Browse the repository at this point in the history
Add docs for Liquid drain and list payments details
  • Loading branch information
dangeross authored Nov 26, 2024
2 parents d004d93 + 6a17e08 commit f460303
Show file tree
Hide file tree
Showing 39 changed files with 875 additions and 88 deletions.
10 changes: 5 additions & 5 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-rc1'
description: 'sdk commit/tag/branch reference. Defaults to 0.5.0-rc8'
required: false
type: string
default: 0.5.0-rc1
default: 0.5.0-rc8

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-rc1' }}
sdk-ref: ${{ inputs.sdk-ref || '0.5.0-rc8' }}
# Used for RN and Flutter snippets
package-version: '0.5.0-rc1'
package-version: '0.5.0-rc8'
steps:
- run: echo "set pre-setup output variables"

Expand Down Expand Up @@ -281,7 +281,7 @@ jobs:

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "16.1-beta"
xcode-version: "latest-stable"

- name: Build
working-directory: snippets/swift/BreezSDKExamples
Expand Down
2 changes: 1 addition & 1 deletion examples/python/cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.8.1"
breez-sdk-liquid = "0.5.0-rc1"
breez-sdk-liquid = "0.5.0-rc8"
argparse = "^1.4.0"
qrcode = "^7.4.2"
colorama = "^0.4.6"
Expand Down
36 changes: 36 additions & 0 deletions snippets/csharp/ListPayments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,40 @@ public void ListPaymentsFiltered(BindingLiquidSdk sdk)
}
// ANCHOR_END: list-payments-filtered
}

public void ListPaymentsDetailsAddress(BindingLiquidSdk sdk)
{
// ANCHOR: list-payments-details-address
try
{
var address = "<Bitcoin address>";
var payments = sdk.ListPayments(
new ListPaymentsRequest(
details: new ListPaymentDetails.Bitcoin(address)
));
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: list-payments-details-address
}

public void ListPaymentsDetailsDestination(BindingLiquidSdk sdk)
{
// ANCHOR: list-payments-details-destination
try
{
var destination = "<Liquid BIP21 or address>";
var payments = sdk.ListPayments(
new ListPaymentsRequest(
details: new ListPaymentDetails.Liquid(destination)
));
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: list-payments-details-destination
}
}
6 changes: 3 additions & 3 deletions snippets/csharp/PayOnchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void PreparePayOnchain(BindingLiquidSdk sdk)
// ANCHOR: prepare-pay-onchain
try
{
var amount = new PayOnchainAmount.Receiver(5000);
var amount = new PayAmount.Receiver(5000);
var prepareRequest = new PreparePayOnchainRequest(amount);
var prepareResponse = sdk.PreparePayOnchain(prepareRequest);

Expand All @@ -42,7 +42,7 @@ public void PreparePayOnchainDrain(BindingLiquidSdk sdk)
// ANCHOR: prepare-pay-onchain-drain
try
{
var amount = new PayOnchainAmount.Drain();
var amount = new PayAmount.Drain();
var prepareRequest = new PreparePayOnchainRequest(amount);
var prepareResponse = sdk.PreparePayOnchain(prepareRequest);

Expand All @@ -61,7 +61,7 @@ public void PreparePayOnchainFeeRate(BindingLiquidSdk sdk)
// ANCHOR: prepare-pay-onchain-fee-rate
try
{
var amount = new PayOnchainAmount.Receiver(5000);
var amount = new PayAmount.Receiver(5000);
uint optionalSatPerVbyte = 21;

var prepareRequest = new PreparePayOnchainRequest(amount, optionalSatPerVbyte);
Expand Down
25 changes: 23 additions & 2 deletions snippets/csharp/SendPayment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public void PrepareSendPaymentLiquid(BindingLiquidSdk sdk)
var destination = "<Liquid BIP21 or address>";
try
{
ulong optionalAmountSat = 5000;
var prepareResponse = sdk.PrepareSendPayment(new PrepareSendRequest(destination, optionalAmountSat));
var optionalAmount = new PayAmount.Receiver(5000);
var prepareResponse = sdk.PrepareSendPayment(new PrepareSendRequest(destination, optionalAmount));

// If the fees are acceptable, continue to create the Send Payment
var sendFeesSat = prepareResponse.feesSat;
Expand All @@ -43,6 +43,27 @@ public void PrepareSendPaymentLiquid(BindingLiquidSdk sdk)
// ANCHOR_END: prepare-send-payment-liquid
}

public void PrepareSendPaymentLiquidDrain(BindingLiquidSdk sdk)
{
// ANCHOR: prepare-send-payment-liquid-drain
// Set the Liquid BIP21 or address you wish to pay
var destination = "<Liquid BIP21 or address>";
try
{
var optionalAmount = new PayAmount.Drain();
var prepareResponse = sdk.PrepareSendPayment(new PrepareSendRequest(destination, optionalAmount));

// If the fees are acceptable, continue to create the Send Payment
var sendFeesSat = prepareResponse.feesSat;
Console.WriteLine($"Fees: {sendFeesSat} sats");
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: prepare-send-payment-liquid-drain
}

public void SendPayment(BindingLiquidSdk sdk, PrepareSendResponse prepareResponse)
{
// ANCHOR: send-payment
Expand Down
22 changes: 22 additions & 0 deletions snippets/dart_snippets/lib/list_payments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,25 @@ Future<List<Payment>> listPaymentsFiltered() async {
// ANCHOR_END: list-payments-filtered
return paymentsList;
}

Future<List<Payment>> listPaymentsDetailsAddress() async {
// ANCHOR: list-payments-details-address
String address = "<Bitcoin address>";
ListPaymentsRequest req = ListPaymentsRequest(
details: ListPaymentDetails_Bitcoin(address: address),
);
List<Payment> paymentsList = await breezSDKLiquid.instance!.listPayments(req: req);
// ANCHOR_END: list-payments-details-address
return paymentsList;
}

Future<List<Payment>> listPaymentsDetailsDestination() async {
// ANCHOR: list-payments-details-destination
String destination = "<Liquid BIP21 or address>";
ListPaymentsRequest req = ListPaymentsRequest(
details: ListPaymentDetails_Liquid(destination: destination),
);
List<Payment> paymentsList = await breezSDKLiquid.instance!.listPayments(req: req);
// ANCHOR_END: list-payments-details-destination
return paymentsList;
}
6 changes: 3 additions & 3 deletions snippets/dart_snippets/lib/pay_onchain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Future<OnchainPaymentLimitsResponse> getCurrentLimits() async {
Future<PreparePayOnchainResponse> preparePayOnchain() async {
// ANCHOR: prepare-pay-onchain
PreparePayOnchainRequest preparePayOnchainRequest = PreparePayOnchainRequest(
amount: PayOnchainAmount_Receiver(amountSat: 5000 as BigInt),
amount: PayAmount_Receiver(amountSat: 5000 as BigInt),
);
PreparePayOnchainResponse prepareRes = await breezSDKLiquid.instance!.preparePayOnchain(
req: preparePayOnchainRequest,
Expand All @@ -29,7 +29,7 @@ Future<PreparePayOnchainResponse> preparePayOnchain() async {
Future<PreparePayOnchainResponse> preparePayOnchainDrain() async {
// ANCHOR: prepare-pay-onchain-drain
PreparePayOnchainRequest preparePayOnchainRequest = PreparePayOnchainRequest(
amount: PayOnchainAmount_Drain(),
amount: PayAmount_Drain(),
);
PreparePayOnchainResponse prepareRes = await breezSDKLiquid.instance!.preparePayOnchain(
req: preparePayOnchainRequest,
Expand All @@ -47,7 +47,7 @@ Future<PreparePayOnchainResponse> preparePayOnchainFeeRate() async {
int optionalSatPerVbyte = 21;

PreparePayOnchainRequest preparePayOnchainRequest = PreparePayOnchainRequest(
amount: PayOnchainAmount_Receiver(amountSat: 5000 as BigInt),
amount: PayAmount_Receiver(amountSat: 5000 as BigInt),
feeRateSatPerVbyte: optionalSatPerVbyte,
);
PreparePayOnchainResponse prepareRes = await breezSDKLiquid.instance!.preparePayOnchain(
Expand Down
28 changes: 26 additions & 2 deletions snippets/dart_snippets/lib/send_payment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ Future<PrepareSendResponse> prepareSendPaymentLightning() async {
Future<PrepareSendResponse> prepareSendPaymentLiquid() async {
// ANCHOR: prepare-send-payment-liquid
// Set the Liquid BIP21 or Liquid address you wish to pay
BigInt optionalAmountSat = BigInt.from(5000);
PayAmount_Receiver optionalAmount = PayAmount_Receiver(amountSat: 5000 as BigInt);
PrepareSendRequest prepareSendRequest = PrepareSendRequest(
destination: "<Liquid BIP21 or address>",
amount: optionalAmount,
);

PrepareSendResponse prepareSendResponse = await breezSDKLiquid.instance!.prepareSendPayment(
req: PrepareSendRequest(destination: "<Liquid BIP21 or address>", amountSat: optionalAmountSat),
req: prepareSendRequest,
);

// If the fees are acceptable, continue to create the Send Payment
Expand All @@ -31,6 +35,26 @@ Future<PrepareSendResponse> prepareSendPaymentLiquid() async {
return prepareSendResponse;
}

Future<PrepareSendResponse> prepareSendPaymentLiquidDrain() async {
// ANCHOR: prepare-send-payment-liquid-drain
// Set the Liquid BIP21 or Liquid address you wish to pay
PayAmount_Drain optionalAmount = PayAmount_Drain();
PrepareSendRequest prepareSendRequest = PrepareSendRequest(
destination: "<Liquid BIP21 or address>",
amount: optionalAmount,
);

PrepareSendResponse prepareSendResponse = await breezSDKLiquid.instance!.prepareSendPayment(
req: prepareSendRequest,
);

// If the fees are acceptable, continue to create the Send Payment
BigInt sendFeesSat = prepareSendResponse.feesSat;
print("Fees: $sendFeesSat sats");
// ANCHOR_END: prepare-send-payment-liquid-drain
return prepareSendResponse;
}

Future<SendPaymentResponse> sendPayment({required PrepareSendResponse prepareResponse}) async {
// ANCHOR: send-payment
SendPaymentResponse sendPaymentResponse = await breezSDKLiquid.instance!.sendPayment(
Expand Down
8 changes: 4 additions & 4 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: fb8cb1082d80ba3219a03e2af40857ce2348f8d0
resolved-ref: 619a9b23256820b291ddf97f3fee7224c5b084fd
url: "https://github.com/breez/breez-sdk-liquid-dart"
source: git
version: "0.5.0-rc1"
version: "0.5.0-rc8"
build_cli_annotations:
dependency: transitive
description:
Expand Down Expand Up @@ -140,10 +140,10 @@ packages:
description:
path: "."
ref: HEAD
resolved-ref: b63b3061ffdf1df2af95f0393c169262d66a2236
resolved-ref: a0ee25c652159a0c99faaf55f8b21becc5b32999
url: "https://github.com/breez/breez-sdk-liquid-flutter"
source: git
version: "0.5.0-rc1"
version: "0.5.0-rc8"
flutter_rust_bridge:
dependency: transitive
description:
Expand Down
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-rc1
tag: 0.5.0-rc8
flutter_breez_liquid:
git:
url: https://github.com/breez/breez-sdk-liquid-flutter
tag: 0.5.0-rc1
tag: 0.5.0-rc8
rxdart: ^0.28.0

dependency_overrides:
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-rc1
require github.com/breez/breez-sdk-liquid-go v0.5.0-rc8

//replace github.com/breez/breez-sdk-liquid-go => ./packages/breez-sdk-liquid-go
30 changes: 30 additions & 0 deletions snippets/go/list_payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,33 @@ func ListPaymentsFiltered(sdk *breez_sdk_liquid.BindingLiquidSdk) {
}
// ANCHOR_END: list-payments-filtered
}

func ListPaymentsDetailsAddress(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR: list-payments-details-address
address := "<Bitcoin address>"
var details breez_sdk_liquid.ListPaymentDetails = breez_sdk_liquid.ListPaymentDetailsBitcoin{
Address: address,
}
listPaymentsRequest := breez_sdk_liquid.ListPaymentsRequest{
Details: &details,
}
if payments, err := sdk.ListPayments(listPaymentsRequest); err == nil {
log.Printf("%#v", payments)
}
// ANCHOR_END: list-payments-details-address
}

func ListPaymentsDetailsDestination(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR: list-payments-details-destination
destination := "<Liquid BIP21 or address>"
var details breez_sdk_liquid.ListPaymentDetails = breez_sdk_liquid.ListPaymentDetailsLiquid{
Destination: destination,
}
listPaymentsRequest := breez_sdk_liquid.ListPaymentsRequest{
Details: &details,
}
if payments, err := sdk.ListPayments(listPaymentsRequest); err == nil {
log.Printf("%#v", payments)
}
// ANCHOR_END: list-payments-details-destination
}
6 changes: 3 additions & 3 deletions snippets/go/pay_onchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func GetCurrentRevSwapLimits(sdk *breez_sdk_liquid.BindingLiquidSdk) {

func PreparePayOnchain(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR: prepare-pay-onchain
amount := breez_sdk_liquid.PayOnchainAmountReceiver{AmountSat: 5_000}
amount := breez_sdk_liquid.PayAmountReceiver{AmountSat: 5_000}
prepareRequest := breez_sdk_liquid.PreparePayOnchainRequest{
Amount: amount,
}
Expand All @@ -32,7 +32,7 @@ func PreparePayOnchain(sdk *breez_sdk_liquid.BindingLiquidSdk) {

func PreparePayOnchainDrain(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR: prepare-pay-onchain-drain
amount := breez_sdk_liquid.PayOnchainAmountDrain{}
amount := breez_sdk_liquid.PayAmountDrain{}
prepareRequest := breez_sdk_liquid.PreparePayOnchainRequest{
Amount: amount,
}
Expand All @@ -47,7 +47,7 @@ func PreparePayOnchainDrain(sdk *breez_sdk_liquid.BindingLiquidSdk) {

func PreparePayOnchainFeeRate(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR: prepare-pay-onchain-fee-rate
amount := breez_sdk_liquid.PayOnchainAmountReceiver{AmountSat: 5_000}
amount := breez_sdk_liquid.PayAmountReceiver{AmountSat: 5_000}
optionalSatPerVbyte := uint32(21)
prepareRequest := breez_sdk_liquid.PreparePayOnchainRequest{
Amount: amount,
Expand Down
26 changes: 24 additions & 2 deletions snippets/go/send_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ func PrepareSendPaymentLiquid(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR: prepare-send-payment-liquid
// Set the Liquid BIP21 or Liquid address you wish to pay
destination := "<Liquid BIP21 or address>"
optionalAmountSat := uint64(5_000)
var optionalAmount breez_sdk_liquid.PayAmount = breez_sdk_liquid.PayAmountReceiver{AmountSat: uint64(5_000)}

prepareRequest := breez_sdk_liquid.PrepareSendRequest{
Destination: destination,
AmountSat: &optionalAmountSat,
Amount: &optionalAmount,
}
prepareResponse, err := sdk.PrepareSendPayment(prepareRequest)
if err != nil {
Expand All @@ -44,6 +45,27 @@ func PrepareSendPaymentLiquid(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR_END: prepare-send-payment-liquid
}

func PrepareSendPaymentLiquidDrain(sdk *breez_sdk_liquid.BindingLiquidSdk) {
// ANCHOR: prepare-send-payment-liquid-drain
// Set the Liquid BIP21 or Liquid address you wish to pay
destination := "<Liquid BIP21 or address>"
var optionalAmount breez_sdk_liquid.PayAmount = breez_sdk_liquid.PayAmountDrain{}

prepareRequest := breez_sdk_liquid.PrepareSendRequest{
Destination: destination,
Amount: &optionalAmount,
}
prepareResponse, err := sdk.PrepareSendPayment(prepareRequest)
if err != nil {
log.Printf("Error: %#v", err)
return
}

sendFeesSat := prepareResponse.FeesSat
log.Printf("Fees: %v sats", sendFeesSat)
// ANCHOR_END: prepare-send-payment-liquid-drain
}

func SendPayment(sdk *breez_sdk_liquid.BindingLiquidSdk, prepareResponse breez_sdk_liquid.PrepareSendResponse) {
// ANCHOR: send-payment
req := breez_sdk_liquid.SendPaymentRequest{
Expand Down
Loading

0 comments on commit f460303

Please sign in to comment.