mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-18 14:24:19 +01:00
Create Dart snippets and reference them
Co-Authored-By: ok300 <106775972+ok300@users.noreply.github.com>
This commit is contained in:
@@ -58,15 +58,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
BuyBitcoinResponse buyBitcoinResponse = buyBitcoin(
|
||||
reqData: BuyBitcoinRequest(
|
||||
provider: BuyBitcoinProvider.Moonpay,
|
||||
),
|
||||
);
|
||||
} catch {
|
||||
// Handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/buy_btc.dart:buy-btc}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -53,12 +53,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
List<LspInformation> lspList = await listLsps();
|
||||
// Select your desired LSP
|
||||
} catch (e) {
|
||||
// Handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/connecting_lsp.dart:get-lsp-info}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -152,12 +147,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
String lspId = await lspId();
|
||||
await connectLSP(lspId);
|
||||
} catch (e) {
|
||||
// Handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/connecting_lsp.dart:connect-lsp}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -35,11 +35,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
List<FiatCurrency> fiatCurrencyList = await listFiatCurrencies();
|
||||
} catch(e) {
|
||||
// Handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/fiat_currencies.dart:list-fiat-currencies}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -116,13 +112,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
Map<String, Rate> fiatRatesMap = await fetchFiatRates();
|
||||
// print your desired rate
|
||||
print(fiatRatesMap["USD"]?.value);
|
||||
} catch(e) {
|
||||
// Handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/fiat_currencies.dart:fetch-fiat-rates}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -217,31 +207,7 @@ fun fiatCurrenciesAndRate(): Map<FiatCurrency, Rate> = try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
Future<Map<FiatCurrency, Rate>> fiatCurrenciesAndRate() async {
|
||||
try {
|
||||
List<FiatCurrency> fiatCurrencies = await _breezLib.listFiatCurrencies();
|
||||
Map<String, Rate> fiatRates = await _breezLib.fetchFiatRates();
|
||||
|
||||
var sorted = fiatCurrencies.toList();
|
||||
sorted.sort((f1, f2) {
|
||||
return f1.id.compareTo(f2.id);
|
||||
});
|
||||
|
||||
Map<FiatCurrency, Rate> result = {};
|
||||
for (var currency in sorted) {
|
||||
var rate = fiatRates[currency.id];
|
||||
if (rate != null) {
|
||||
result[currency] = rate;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
// Handle error
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
{{#include ../../snippets/dart_snippets/lib/fiat_currencies.dart:get-fiat-currencies-and-rates}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -122,32 +122,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
// SDK events listener
|
||||
breezEventsStream().listen((event) {
|
||||
print("Received Breez event: $event");
|
||||
}
|
||||
|
||||
// SDK logs listener
|
||||
breezLogStream().listen((log) {
|
||||
print("Received Breez log entry: $log");
|
||||
}
|
||||
|
||||
// Create the default config
|
||||
Uint8List seed = await mnemonicToSeed(phrase: "<mnemonic words>");
|
||||
String inviteCode = "<invite code>";
|
||||
String apiKey = "<api key>"
|
||||
NodeConfg nodeConfig = NodeConfig.greenlight(config: GreenlightNodeConfig(partnerCredentials: null, inviteCode: inviteCode));
|
||||
Config config = await defaultConfig(configType: EnvironmentType.Production, apiKey: apiKey, nodeConfig: nodeConfig);
|
||||
|
||||
// Customize the config object according to your needs
|
||||
config.workingDir = "path to an existing directory";
|
||||
|
||||
try {
|
||||
// Connect to the Breez SDK make it ready for use
|
||||
await connect(config: config, seed: seed);
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/getting_started.dart:init-sdk}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -315,13 +290,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
NodeState? nodeInfo = await nodeInfo();
|
||||
int lnBalance = nodeInfo?.channelsBalanceMsat;
|
||||
int onchainBalance = nodeInfo?.onchainBalanceMsat;
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/getting_started.dart:fetch-balance}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -47,13 +47,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
List<Payment> payments = await listPayments(
|
||||
filter: PaymentTypeFilter.All,
|
||||
);
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/list_payments.dart:list-payments}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -147,15 +141,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
List<Payment> payments = await listPayments(
|
||||
filter: PaymentTypeFilter.Sent,
|
||||
fromTimestamp: 1696880000,
|
||||
includeFailures: true
|
||||
);
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/list_payments.dart:list-payments-filtered}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -69,23 +69,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
// Endpoint can also be of the form:
|
||||
// keyauth://domain.com/auth?key=val
|
||||
String lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";
|
||||
|
||||
try {
|
||||
InputType inputType = await parse(s: lnurlAuthUrl);
|
||||
if (inputType is InputType_LnUrlAuth) {
|
||||
LnUrlCallbackStatus result = await lnurlAuth(reqData: inputType.data);
|
||||
if (result is LnUrlCallbackStatus_Ok) {
|
||||
print("Successfully authenticated");
|
||||
} else {
|
||||
print("Failed to authenticate");
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/lnurl_auth.dart:lnurl-auth}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -65,24 +65,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
// Endpoint can also be of the form:
|
||||
// lnurlp://domain.com/lnurl-pay?key=val
|
||||
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
|
||||
String lnurlPayUrl = "lightning@address.com";
|
||||
|
||||
try {
|
||||
InputType inputType = await parseInput(s: lnurlPayUrl);
|
||||
if (inputType is InputType_LnUrlPay) {
|
||||
int amountSats = inputType.data.minSendable;
|
||||
LnUrlCallbackStatus result = await lnurlPay(
|
||||
reqData: inputType.data,
|
||||
userAmountSat: amountSats,
|
||||
comment: "comment",
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/lnurl_pay.dart:lnurl-pay}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -67,23 +67,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
// Endpoint can also be of the form:
|
||||
// lnurlw://domain.com/lnurl-withdraw?key=val
|
||||
String lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";
|
||||
|
||||
try {
|
||||
InputType inputType = await parseInput(s: lnurlWithdrawUrl);
|
||||
if (inputType is InputType_LnUrlWithdraw) {
|
||||
int amountSats = inputType.data.minWithdrawable;
|
||||
LnUrlCallbackStatus result = await lnurlWithdraw(
|
||||
reqData: inputType.data,
|
||||
amountSats: amountSats,
|
||||
description: "comment",
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/lnurl_withdraw.dart:lnurl-withdraw}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -55,16 +55,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
SwapInfo swapInfo = await receiveOnchain(
|
||||
reqData: ReceiveOnchainRequest(),
|
||||
);
|
||||
|
||||
// Send your funds to the below bitcoin address
|
||||
String address = swapInfo.bitcoinAddress;
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/receive_onchain.dart:generate-receive-onchain-address}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -160,11 +151,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
SwapInfo? swapInfo = await inProgressSwap();
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/receive_onchain.dart:in-progress-swap}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -257,11 +244,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
List<SwapInfo> refundables = await listRefundables()
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/receive_onchain.dart:list-refundables}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -358,17 +341,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
String destinationAddress = "..."
|
||||
int satPerVbyte = <refund tx fee rate>
|
||||
try {
|
||||
String result = await refund(
|
||||
swapAddress: refundable.bitcoinAddress,
|
||||
toAddress: destinationAddress,
|
||||
satPerVbyte: satPerVbyte,
|
||||
);
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/receive_onchain.dart:execute-refund}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -470,16 +443,7 @@ do {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
int amountMsats = <amount msats>
|
||||
try {
|
||||
int channelFees = openChannelFee(
|
||||
req: OpenChannelFeeRequest(
|
||||
amountMsats: amountMsats,
|
||||
),
|
||||
);
|
||||
} catch {
|
||||
// Handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/receive_onchain.dart:get-channel-opening-fees}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -54,16 +54,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
ReceivePaymentResponse invoice = await receivePayment(
|
||||
reqData: ReceivePaymentRequest(
|
||||
amountSats: 3000,
|
||||
description: "Invoice for 3000 sats",
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/receive_payment.dart:receive-payment}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -53,17 +53,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
ReverseSwapPairInfo currentFees = await fetchReverseSwapFees(
|
||||
req: ReverseSwapFeesRequest(
|
||||
sendAmountSat: 50000,
|
||||
),
|
||||
);
|
||||
|
||||
print("Total estimated fees for reverse swap: ${currentFees.totalEstimatedFees}");
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/send_onchain.dart:estimate-current-reverse-swap-total-fees}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -157,8 +147,7 @@ Log.v("Breez", "Maximum amount, in sats: ${fees.max}")
|
||||
<section>
|
||||
|
||||
```dart
|
||||
print("Minimum amount, in sats: ${currentFees.min}");
|
||||
print("Maximum amount, in sats: ${currentFees.max}");
|
||||
{{#include ../../snippets/dart_snippets/lib/send_onchain.dart:get-current-reverse-swap-min-max}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -247,20 +236,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
String destinationAddress = "bc1..";
|
||||
int amountSat = <amount>;
|
||||
int satPerVbyte = <fee rate>
|
||||
ReverseSwapPairInfo currentFees = <current reverse swap fees>
|
||||
try {
|
||||
ReverseSwapInfo reverseSwapInfo = await sendOnchain(
|
||||
amountSat: amountSat,
|
||||
onchainRecipientAddress: destinationAddress,
|
||||
pairHash: currentFees.feesHash,
|
||||
satPerVbyte: satPerVbyte,
|
||||
);
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/send_onchain.dart:start-reverse-swap}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -363,14 +339,7 @@ for (rs in sdk.inProgressReverseSwaps()) {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
List<ReverseSwapInfo> swaps = await inProgressReverseSwaps();
|
||||
for (swap in swaps) {
|
||||
print(`Reverse swap ${swap.id} in progress, status is ${swap.status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/send_onchain.dart:check-reverse-swaps-status}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -51,15 +51,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
String bolt11 = "...";
|
||||
try {
|
||||
Payment payment = await sendPayment(
|
||||
bolt11: bolt11,
|
||||
amountSats: 3000,
|
||||
);
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/send_payment.dart:send-payment}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -49,15 +49,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
String nodeId = "...";
|
||||
try {
|
||||
Payment payment = await sendSpontaneousPayment(
|
||||
nodeId: nodeId,
|
||||
amountSats: 3000,
|
||||
);
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/send_spontaneous_payment.dart:send-spontaneous-payment}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -56,15 +56,7 @@ try {
|
||||
<section>
|
||||
|
||||
```dart
|
||||
try {
|
||||
StaticBackupResponse backupData = await staticBackup(
|
||||
request: StaticBackupRequest
|
||||
workingDir: "<working directory>",
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
{{#include ../../snippets/dart_snippets/lib/static_channel_backup.dart:static-channel-backup}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user