Skip to content

Commit

Permalink
Merge pull request #161 from breez/pre-release
Browse files Browse the repository at this point in the history
Release v0.4.0 docs
  • Loading branch information
dangeross authored May 6, 2024
2 parents 53999b6 + 35e6410 commit e177766
Show file tree
Hide file tree
Showing 107 changed files with 2,539 additions and 913 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
name: setup
runs-on: ubuntu-latest
outputs:
sdk-ref: ${{ inputs.sdk-ref || '474ac7d4b5d19633dc851439b9ff7e159286fbd8' }}
package-version: '0.3.1'
sdk-ref: ${{ inputs.sdk-ref || '0.4.0' }}
package-version: '0.4.0'
steps:
- run: echo "set pre-setup output variables"

Expand Down Expand Up @@ -151,7 +151,7 @@ jobs:
- name: Add nuget dependency
working-directory: snippets/csharp
run: |
dotnet add package Breez.Sdk -s ./packages
dotnet add package Breez.Sdk -s ./packages --prerelease
- name: Build the csharp project
working-directory: snippets/csharp
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

The SDK docs are live at [https://sdk-doc.breez.technology](https://sdk-doc.breez.technology).


## Contributions

For syntax and supported features, see [https://rust-lang.github.io/mdBook](https://rust-lang.github.io/mdBook).
Expand Down
83 changes: 83 additions & 0 deletions snippets/csharp/CommunicatingFees.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using Breez.Sdk;

public class CommunicatingFeesSnippets
{
public void getFeeInfoBeforeInvoiceCreated(BlockingBreezServices sdk)
{
// ANCHOR: get-fee-info-before-receiving-payment
try
{
var nodeInfo = sdk.NodeInfo();

var inboundLiquiditySat = nodeInfo?.inboundLiquidityMsats / 1_000;

var openingFeeResponse = sdk.OpenChannelFee(new OpenChannelFeeRequest(null));
var openingFees = openingFeeResponse?.feeParams;
if (openingFees != null)
{
var feePercentage = (openingFees.proportional * 100) / 1_000_000.0;
var minFeeSat = openingFees.minMsat / 1_000;

if (inboundLiquiditySat == 0)
{
Console.WriteLine(
$"A setup fee of {feePercentage}% with a minimum of {minFeeSat} sats will be applied."
);
}
else
{
Console.WriteLine(
$"A setup fee of {feePercentage}% with a minimum of {minFeeSat} sats will be applied " +
$"for receiving more than {inboundLiquiditySat} sats."
);
}
}
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: get-fee-info-before-receiving-payment
}

public void GetFeeInfoAfterInvoiceCreated(ReceivePaymentResponse receivePaymentResponse)
{
// ANCHOR: get-fee-info-after-invoice-created
var openingFeeSat = receivePaymentResponse.openingFeeMsat.GetValueOrDefault() / 1000;
Console.WriteLine($"A setup fee of {openingFeeSat} sats is applied to this invoice.");
// ANCHOR_END: get-fee-info-after-invoice-created
}

public void getFeeInfoReceiveOnchain(BlockingBreezServices sdk)
{
// ANCHOR: get-fee-info-receive-onchain
try
{
var swapInfo = sdk.ReceiveOnchain(new ReceiveOnchainRequest());

var minDepositSat = swapInfo?.minAllowedDeposit;
var maxDepositSat = swapInfo?.maxAllowedDeposit;

var nodeInfo = sdk.NodeInfo();
var inboundLiquiditySat = nodeInfo?.inboundLiquidityMsats / 1_000;

var swapOpeningFees = swapInfo?.channelOpeningFees;
if (swapOpeningFees != null)
{
var feePercentage = (swapOpeningFees.proportional * 100) / 1_000_000.0;
var minFeeSat = swapOpeningFees.minMsat / 1_000;

Console.WriteLine(
$"Send more than {minDepositSat} sats and up to {maxDepositSat} sats to this address. " +
$"A setup fee of {feePercentage}% with a minimum of {minFeeSat} sats will be applied " +
$"for sending more than {inboundLiquiditySat} sats. This address can only be used once."
);
}
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: get-fee-info-receive-onchain
}
}
6 changes: 4 additions & 2 deletions snippets/csharp/LnurlPay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public void LnurlPay(BlockingBreezServices sdk)
if (input is InputType.LnUrlPay lnurlp)
{
var amountMsat = lnurlp.data.minSendable;
var result = sdk.PayLnurl(
new LnUrlPayRequest(lnurlp.data, amountMsat, "comment"));
var optionalComment = "<comment>";
var optionalPaymentLabel = "<label>";
var req = new LnUrlPayRequest(lnurlp.data, amountMsat, optionalComment, optionalPaymentLabel);
var result = sdk.PayLnurl(req);
}
}
catch (Exception)
Expand Down
57 changes: 25 additions & 32 deletions snippets/csharp/SendOnchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,55 @@

public class SendOnchainSnippets
{
public void GetCurrentFees(BlockingBreezServices sdk)
public void GetCurrentLimits(BlockingBreezServices sdk)
{
// ANCHOR: estimate-current-reverse-swap-total-fees
// ANCHOR: get-current-reverse-swap-limits
try
{
var currentFees = sdk.FetchReverseSwapFees(
new ReverseSwapFeesRequest(50000));
Console.WriteLine(
$"Total estimated fees for reverse " +
$"swap: {currentFees.totalFees}");
var currentLimits = sdk.OnchainPaymentLimits();
Console.WriteLine($"Minimum amount, in sats: {currentLimits.minSat}");
Console.WriteLine($"Maximum amount, in sats: {currentLimits.maxSat}");
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: estimate-current-reverse-swap-total-fees
// ANCHOR_END: get-current-reverse-swap-limits
}

public void ListCurrentFees(BlockingBreezServices sdk, ReverseSwapPairInfo currentFees)
public void PreparePayOnchain(BlockingBreezServices sdk, OnchainPaymentLimitsResponse currentLimits, uint feeRate)
{
// ANCHOR: get-current-reverse-swap-min-max
Console.WriteLine($"Minimum amount, in sats: {currentFees.min}");
Console.WriteLine($"Maximum amount, in sats: {currentFees.max}");
// ANCHOR_END: get-current-reverse-swap-min-max
}
// ANCHOR: prepare-pay-onchain
var amountSat = currentLimits.minSat;
var claimTxFeerate = feeRate;

public void MaxReverseSwapAmount(BlockingBreezServices sdk)
{
// ANCHOR: max-reverse-swap-amount
try
{
var maxAmountResponse = sdk.MaxReverseSwapAmount();
Console.WriteLine(
$"Max reverse swap amount {maxAmountResponse.totalSat}");
var prepareRes = sdk.PrepareOnchainPayment(
new PrepareOnchainPaymentRequest(
amountSat,
SwapAmountType.SEND,
claimTxFeerate));

Console.WriteLine($"Sender amount, in sats: {prepareRes.senderAmountSat}");
Console.WriteLine($"Recipient amount, in sats: {prepareRes.recipientAmountSat}");
Console.WriteLine($"Total fees, in sats: {prepareRes.totalFees}");
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: max-reverse-swap-amount
// ANCHOR_END: prepare-pay-onchain
}

public void StartReverseSwap(BlockingBreezServices sdk, ReverseSwapPairInfo currentFees, uint feeRate)
public void StartReverseSwap(BlockingBreezServices sdk, PrepareOnchainPaymentResponse prepareRes)
{
// ANCHOR: start-reverse-swap
var destinationAddress = "bc1..";
var amountSat = currentFees.min;
var satPerVbyte = feeRate;
try
{
var reverseSwapInfo = sdk.SendOnchain(
new SendOnchainRequest(
amountSat,
destinationAddress,
currentFees.feesHash,
satPerVbyte));
var reverseSwapInfo = sdk.PayOnchain(
new PayOnchainRequest(destinationAddress, prepareRes));
}
catch (Exception)
{
Expand All @@ -71,11 +64,11 @@ public void CheckReverseSwapStatus(BlockingBreezServices sdk)
// ANCHOR: check-reverse-swaps-status
try
{
var swaps = sdk.InProgressReverseSwaps();
var swaps = sdk.InProgressOnchainPayments();
foreach (var swap in swaps)
{
Console.WriteLine(
$"Reverse swap {swap.id} in progress, " +
$"Onchain payment {swap.id} in progress, " +
$"status is {swap.status}`");
}
}
Expand Down
7 changes: 4 additions & 3 deletions snippets/csharp/SendPayment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ public void SendPayment(BlockingBreezServices sdk)
{
// ANCHOR: send-payment
var bolt11 = "...";
ulong amountMsat = 3_000_000;

ulong optionalAmountMsat = 3_000_000;
var optionalLabel = "<label>";

try
{
// The `amountMsat` param is optional and should only passed if the
// bolt11 doesn't specify an amount.
// The amountMsat is required in case an amount is not specified in
// the bolt11 invoice.
var response = sdk.SendPayment(
new SendPaymentRequest(bolt11, amountMsat));
new SendPaymentRequest(bolt11, optionalAmountMsat, optionalLabel));
}
catch (Exception)
{
Expand Down
8 changes: 5 additions & 3 deletions snippets/csharp/SendSpontaneousPayment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ public void SendSpontaneousPayment(BlockingBreezServices sdk)
// ANCHOR: send-spontaneous-payment
var nodeId = "...";
ulong amountMsat = 3_000_000;
var optionalLabel = "<label>";

try
{
var response = sdk.SendSpontaneousPayment(
new SendSpontaneousPaymentRequest(nodeId, amountMsat));
new SendSpontaneousPaymentRequest(nodeId, amountMsat, label: optionalLabel));
}
catch (Exception)
{
Expand All @@ -26,14 +28,14 @@ public void SendSpontaneousPaymentWithTlvs(BlockingBreezServices sdk)
// ANCHOR: send-spontaneous-payment-with-tlvs
var nodeId = "...";
ulong amountMsat = 3_000_000;
var extraTlvs = new List<TlvEntry>{
var optionalExtraTlvs = new List<TlvEntry>{
new TlvEntry(34349334, Encoding.ASCII.GetBytes("Hello world!").ToList())
};

try
{
var response = sdk.SendSpontaneousPayment(
new SendSpontaneousPaymentRequest(nodeId, amountMsat, extraTlvs));
new SendSpontaneousPaymentRequest(nodeId, amountMsat, optionalExtraTlvs));
}
catch (Exception)
{
Expand Down
2 changes: 1 addition & 1 deletion snippets/csharp/ServiceStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public void HealthCheckStatus(BlockingBreezServices sdk)
// ANCHOR: health-check-status
try
{
var healthCheck = sdk.ServiceHealthCheck();
var healthCheck = BreezSdkMethods.ServiceHealthCheck("<api key>");
Console.WriteLine($"Current service status is: {healthCheck.status}");
}
catch (Exception)
Expand Down
52 changes: 52 additions & 0 deletions snippets/dart_snippets/lib/communicating_fees.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';

Future<void> getFeeInfoBeforeInvoiceCreated() async {
// ANCHOR: get-fee-info-before-receiving-payment
NodeState? nodeInfo = await BreezSDK().nodeInfo();
if (nodeInfo != null) {
int inboundLiquiditySat = nodeInfo.inboundLiquidityMsats ~/ 1000;

OpenChannelFeeResponse openingFeeResponse = await BreezSDK().openChannelFee(req: OpenChannelFeeRequest());

OpeningFeeParams openingFees = openingFeeResponse.feeParams;
double feePercentage = (openingFees.proportional * 100) / 1000000;
int minFeeSat = openingFees.minMsat ~/ 1000;

if (inboundLiquiditySat == 0) {
print("A setup fee of $feePercentage% with a minimum of $minFeeSat sats will be applied.");
} else {
print("A setup fee of $feePercentage% with a minimum of $minFeeSat sats will be applied for receiving more than $inboundLiquiditySat sats.");
}
}
// ANCHOR_END: get-fee-info-before-receiving-payment
}

Future<void> getFeeInfoAfterInvoiceCreated({required ReceivePaymentResponse receivePaymentResponse}) async {
// ANCHOR: get-fee-info-after-invoice-created
int openingFeeSat = (receivePaymentResponse.openingFeeMsat ?? 0) / 1000 as int;
print("A setup fee of $openingFeeSat sats is applied to this invoice.");
// ANCHOR_END: get-fee-info-after-invoice-created
}

Future<void> getFeeInfoReceiveOnchain() async {
// ANCHOR: get-fee-info-receive-onchain
SwapInfo swapInfo = await BreezSDK().receiveOnchain(req: ReceiveOnchainRequest());

int minDepositSat = swapInfo.minAllowedDeposit;
int maxDepositSat = swapInfo.maxAllowedDeposit;

NodeState? nodeInfo = await BreezSDK().nodeInfo();
if (nodeInfo != null) {
int inboundLiquiditySat = nodeInfo.inboundLiquidityMsats ~/ 1000;

OpeningFeeParams? swapOpeningFees = swapInfo.channelOpeningFees;
if (swapOpeningFees != null) {
double feePercentage = (swapOpeningFees.proportional * 100) / 1000000;
int minFeeSat = swapOpeningFees.minMsat ~/ 1000;

print("Send more than $minDepositSat sats and up to $maxDepositSat sats to this address. A setup fee of $feePercentage% with a minimum of $minFeeSat sats will be applied for sending more than $inboundLiquiditySat sats. This address can only be used once.");
}
}
// ANCHOR_END: get-fee-info-receive-onchain
}
5 changes: 4 additions & 1 deletion snippets/dart_snippets/lib/lnurl_pay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ Future<void> lnurlPay() async {
InputType inputType = await BreezSDK().parseInput(input: lnurlPayUrl);
if (inputType is InputType_LnUrlPay) {
int amountMsat = inputType.data.minSendable;
String optionalComment = "<comment>";
String optionalPaymentLabel = "<label>";
LnUrlPayRequest req = LnUrlPayRequest(
data: inputType.data,
amountMsat: amountMsat,
comment: "<comment>",
comment: optionalComment,
paymentLabel: optionalPaymentLabel,
);
LnUrlPayResult result = await BreezSDK().lnurlPay(req: req);
print(result.data);
Expand Down
Loading

0 comments on commit e177766

Please sign in to comment.