Merge branch 'jssdwt-snippets-csharp' into ok300-snippets-rust

This commit is contained in:
Jesse de Wit
2023-11-03 18:55:36 +01:00
31 changed files with 1058 additions and 277 deletions

View File

@@ -57,3 +57,19 @@ jobs:
run: | run: |
cd snippets/dart_snippets cd snippets/dart_snippets
dart analyze --fatal-infos dart analyze --fatal-infos
check-csharp:
name: Check C# snippets
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
- name: Build the csharp project
working-directory: snippets/csharp
run: dotnet build

477
snippets/csharp/.gitignore vendored Normal file
View File

@@ -0,0 +1,477 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET
project.lock.json
project.fragment.lock.json
artifacts/
# Tye
.tye/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml
##
## Visual studio for Mac
##
# globs
Makefile.in
*.userprefs
*.usertasks
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.tar.gz
tarballs/
test-results/
# Mac bundle stuff
*.dmg
*.app
# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk

19
snippets/csharp/BuyBtc.cs Normal file
View File

@@ -0,0 +1,19 @@
using Breez.Sdk;
public class BuyBtcSnippets
{
public void BuyBtc(BlockingBreezServices sdk)
{
// ANCHOR: buy-btc
try
{
var buyBitcoinResponse = sdk.BuyBitcoin(
new BuyBitcoinRequest(BuyBitcoinProvider.MOONPAY));
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: buy-btc
}
}

View File

@@ -0,0 +1,33 @@
using Breez.Sdk;
public class ConnectingLspSnippets
{
public void GetLspInfo(BlockingBreezServices sdk)
{
// ANCHOR: get-lsp-info
try
{
var lspId = sdk.LspId();
var lspInfo = sdk.LspInfo();
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: get-lsp-info
}
public void ConnectLsp(BlockingBreezServices sdk, string? lspId)
{
// ANCHOR: connect-lsp
try
{
sdk.ConnectLsp(lspId!);
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: connect-lsp
}
}

View File

@@ -0,0 +1,39 @@
using Breez.Sdk;
public class FiatCurrenciesSnippets
{
public void ListFiatCurrencies(BlockingBreezServices sdk)
{
// ANCHOR: list-fiat-currencies
try
{
var fiatCurrencies = sdk.ListFiatCurrencies();
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: list-fiat-currencies
}
public void FetchFiatRates(BlockingBreezServices sdk)
{
// ANCHOR: fetch-fiat-rates
try
{
var fiatRates = sdk.FetchFiatRates();
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: fetch-fiat-rates
}
public void GetFiatCurrenciesAndRates(BlockingBreezServices sdk)
{
// ANCHOR: get-fiat-currencies-and-rates
// TODO
// ANCHOR_END: get-fiat-currencies-and-rates
}
}

View File

@@ -0,0 +1,62 @@
using Breez.Sdk;
public class GettingStartedSnippets
{
// ANCHOR: init-sdk
public void GettingStarted()
{
// Create the default config
var seed = BreezSdkMethods.MnemonicToSeed("<mnemonic words>");
var inviteCode = "<invite code>";
var apiKey = "<api key>";
var nodeConfig = new NodeConfig.Greenlight(
new GreenlightNodeConfig(null, inviteCode)
);
var config = BreezSdkMethods.DefaultConfig(
EnvironmentType.PRODUCTION,
apiKey,
nodeConfig
) with
{
// Customize the config object according to your needs
workingDir = "path to an existing directory"
};
BlockingBreezServices sdk;
try
{
// Connect to the Breez SDK make it ready for use
sdk = BreezSdkMethods.Connect(config, seed, new SdkListener());
}
catch (Exception)
{
// Handle error
}
}
// SDK event listener
class SdkListener : EventListener
{
public void OnEvent(BreezEvent e)
{
Console.WriteLine($"Received Breez event type {e.GetType().Name}");
}
}
// ANCHOR_END: init-sdk
public void FetchNodeInfo(BlockingBreezServices sdk)
{
// ANCHOR: fetch-balance
try
{
var nodeInfo = sdk.NodeInfo();
var lnBalance = nodeInfo?.channelsBalanceMsat;
var onchainBalance = nodeInfo?.onchainBalanceMsat;
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: fetch-balance
}
}

View File

@@ -0,0 +1,37 @@
using Breez.Sdk;
public class ListPaymentsSnippets
{
public void ListPayments(BlockingBreezServices sdk)
{
// ANCHOR: list-payments
try
{
var payments = sdk.ListPayments(
new ListPaymentsRequest(PaymentTypeFilter.ALL));
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: list-payments
}
public void ListPaymentsFiltered(BlockingBreezServices sdk)
{
// ANCHOR: list-payments-filtered
try
{
var payments = sdk.ListPayments(
new ListPaymentsRequest(
PaymentTypeFilter.SENT,
fromTimestamp: 1696880000,
includeFailures: true));
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: list-payments-filtered
}
}

View File

@@ -0,0 +1,34 @@
using Breez.Sdk;
public class LnurlAuthSnippets
{
public void LnurlAuth(BlockingBreezServices sdk)
{
// ANCHOR: lnurl-auth
// Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val
var lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";
try
{
var input = BreezSdkMethods.ParseInput(lnurlAuthUrl);
if (input is InputType.LnUrlAuth lnurla)
{
var result = sdk.LnurlAuth(lnurla.data);
if (result is LnUrlCallbackStatus.Ok)
{
Console.WriteLine("Successfully authenticated");
}
else
{
Console.WriteLine("Failed to authenticate");
}
}
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: lnurl-auth
}
}

View File

@@ -0,0 +1,29 @@
using Breez.Sdk;
public class LnurlPaySnippets
{
public void LnurlPay(BlockingBreezServices sdk)
{
// ANCHOR: lnurl-pay
// Endpoint can also be of the form:
// lnurlp://domain.com/lnurl-pay?key=val
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
var lnurlPayUrl = "lightning@address.com";
try
{
var input = BreezSdkMethods.ParseInput(lnurlPayUrl);
if (input is InputType.LnUrlPay lnurlp)
{
var amountMsat = lnurlp.data.minSendable;
var result = sdk.PayLnurl(
new LnUrlPayRequest(lnurlp.data, amountMsat, "comment"));
}
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: lnurl-pay
}
}

View File

@@ -0,0 +1,31 @@
using Breez.Sdk;
public class LnurlWithdrawSnippets
{
public void LnurlWithdraw(BlockingBreezServices sdk)
{
// ANCHOR: lnurl-withdraw
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
var lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";
try
{
var input = BreezSdkMethods.ParseInput(lnurlWithdrawUrl);
if (input is InputType.LnUrlWithdraw lnurlw)
{
var amountMsat = lnurlw.data.minWithdrawable;
var result = sdk.WithdrawLnurl(
new LnUrlWithdrawRequest(
lnurlw.data,
amountMsat,
"comment"));
}
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: lnurl-withdraw
}
}

View File

@@ -0,0 +1,84 @@
using Breez.Sdk;
public class ReceiveOnchainSnippets
{
public void ReceiveOnchain(BlockingBreezServices sdk)
{
// ANCHOR: generate-receive-onchain-address
try
{
var swapInfo = sdk.ReceiveOnchain(new ReceiveOnchainRequest());
// Send your funds to the below bitcoin address
var address = swapInfo.bitcoinAddress;
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: generate-receive-onchain-address
}
public void GetInProgressSwap(BlockingBreezServices sdk)
{
// ANCHOR: in-progress-swap
try
{
var swapInfo = sdk.InProgressSwap();
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: in-progress-swap
}
public void ListRefundables(BlockingBreezServices sdk)
{
// ANCHOR: list-refundables
try
{
var refundables = sdk.ListRefundables();
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: list-refundables
}
public void ExecuteRefund(BlockingBreezServices sdk, uint refundTxFeeRate, SwapInfo refundable)
{
// ANCHOR: execute-refund
var destinationAddress = "...";
var satPerVbyte = refundTxFeeRate;
try
{
var result = sdk.Refund(
new RefundRequest(
refundable.bitcoinAddress,
destinationAddress,
satPerVbyte));
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: execute-refund
}
public void GetChannelOpeningFees(BlockingBreezServices sdk, ulong amountMsat)
{
// ANCHOR: get-channel-opening-fees
try
{
var channelFees = sdk.OpenChannelFee(
new OpenChannelFeeRequest(amountMsat));
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: get-channel-opening-fees
}
}

View File

@@ -0,0 +1,19 @@
using Breez.Sdk;
public class ReceivePaymentSnippets
{
public void ReceivePayment(BlockingBreezServices sdk)
{
// ANCHOR: receive-payment
try
{
var invoice = sdk.ReceivePayment(
new ReceivePaymentRequest(3_000_000, "Invoice for 3000 sats"));
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: receive-payment
}
}

View File

@@ -0,0 +1,72 @@
using Breez.Sdk;
public class SendOnchainSnippets
{
public void GetCurrentFees(BlockingBreezServices sdk)
{
// ANCHOR: estimate-current-reverse-swap-total-fees
try
{
var currentFees = sdk.FetchReverseSwapFees(
new ReverseSwapFeesRequest(50000));
Console.WriteLine(
$"Total estimated fees for reverse " +
$"swap: {currentFees.totalEstimatedFees}");
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: estimate-current-reverse-swap-total-fees
}
public void ListCurrentFees(BlockingBreezServices sdk, ReverseSwapPairInfo currentFees)
{
// 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
}
public void StartReverseSwap(BlockingBreezServices sdk, ReverseSwapPairInfo currentFees, uint feeRate)
{
// 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));
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: start-reverse-swap
}
public void CheckReverseSwapStatus(BlockingBreezServices sdk)
{
// ANCHOR: check-reverse-swaps-status
try
{
var swaps = sdk.InProgressReverseSwaps();
foreach (var swap in swaps)
{
Console.WriteLine(
$"Reverse swap {swap.id} in progress, " +
$"status is {swap.status}`");
}
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: check-reverse-swaps-status
}
}

View File

@@ -0,0 +1,26 @@
using Breez.Sdk;
public class SendPaymentSnippets
{
public void SendPayment(BlockingBreezServices sdk)
{
// ANCHOR: send-payment
var bolt11 = "...";
ulong amountMsat = 3_000_000;
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));
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: send-payment
}
}

View File

@@ -0,0 +1,21 @@
using Breez.Sdk;
public class SendSpontaneousPaymentSnippets
{
public void SendSpontaneousPayment(BlockingBreezServices sdk)
{
// ANCHOR: send-spontaneous-payment
var nodeId = "...";
ulong amountMsat = 3_000_000;
try
{
var response = sdk.SendSpontaneousPayment(
new SendSpontaneousPaymentRequest(nodeId, amountMsat));
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: send-spontaneous-payment
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Breez.Sdk" Version="0.2.7" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,19 @@
using Breez.Sdk;
public class StaticChannelBackupSnippets
{
public void StaticChannelBackup(BlockingBreezServices sdk)
{
// ANCHOR: static-channel-backup
try
{
var backupData = BreezSdkMethods.StaticBackup(
new StaticBackupRequest("<working directory>"));
}
catch (Exception)
{
// Handle error
}
// ANCHOR_END: static-channel-backup
}
}

View File

@@ -93,15 +93,7 @@ if buyBitcoinResponse, err := sdk.BuyBitcoin(buyBitcoinRequest); err == nil {
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/BuyBtc.cs:buy-btc}}
{
var buyBitcoinResponse = sdk.BuyBitcoin(
new BuyBitcoinRequest(BuyBitcoinProvider.MOONPAY));
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -87,15 +87,7 @@ if lspInfo, err := sdk.LspInfo(); err == nil {
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/ConnectingLsp.cs:get-lsp-info}}
{
var lspId = sdk.LspId();
var lspInfo = sdk.LspInfo();
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>
@@ -177,14 +169,7 @@ if err := sdk.ConnectLsp(lspId); err != nil {
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/ConnectingLsp.cs:connect-lsp}}
{
sdk.ConnectLsp(lspId!);
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -65,14 +65,7 @@ if fiatCurrencies, err := sdk.ListFiatCurrencies(); err == nil {
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/FiatCurrencies.cs:list-fiat-currencies}}
{
var fiatCurrencies = sdk.ListFiatCurrencies();
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>
@@ -142,14 +135,7 @@ if fiatRates, err := sdk.FetchFiatRates(); err == nil {
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/FiatCurrencies.cs:fetch-fiat-rates}}
{
var fiatRates = sdk.FetchFiatRates();
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>
@@ -231,7 +217,7 @@ fun fiatCurrenciesAndRate(): Map<FiatCurrency, Rate> = try {
<section> <section>
```cs ```cs
// TODO {{#include ../../snippets/csharp/FiatCurrencies.cs:get-fiat-currencies-and-rates}}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -203,42 +203,7 @@ if err != nil {
<section> <section>
```cs ```cs
using Breez.Sdk; {{#include ../../snippets/csharp/GettingStarted.cs:init-sdk}}
// Create the default config
var seed = BreezSdkMethods.MnemonicToSeed("<mnemonic words>");
var inviteCode = "<invite code>";
var apiKey = "<api key>";
var nodeConfig = new NodeConfig.Greenlight(
new GreenlightNodeConfig(null, inviteCode)
);
var config = BreezSdkMethods.DefaultConfig(
EnvironmentType.PRODUCTION,
apiKey,
nodeConfig
) with {
// Customize the config object according to your needs
workingDir = "path to an existing directory"
};
BlockingBreezServices sdk;
try
{
// Connect to the Breez SDK make it ready for use
sdk = BreezSdkMethods.Connect(config, seed, new SdkListener());
} catch (Exception)
{
// Handle error
}
// SDK event listener
class SdkListener : EventListener
{
public void OnEvent(BreezEvent e)
{
Console.WriteLine($"Received Breez event type {e.GetType().Name}");
}
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>
@@ -326,15 +291,7 @@ if nodeInfo, err := sdkServices.NodeInfo(); err != nil {
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/GettingStarted.cs:fetch-balance}}
{
var nodeInfo = sdk.NodeInfo();
var lnBalance = nodeInfo?.channelsBalanceMsat;
var onchainBalance = nodeInfo?.onchainBalanceMsat;
}
catch (Exception) {
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -76,14 +76,7 @@ if payments, err := sdk.ListPayments(breez_sdk.ListPaymentsRequest{Filter: breez
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/ListPayments.cs:list-payments}}
{
var payments = sdk.ListPayments(new ListPaymentsRequest(PaymentTypeFilter.ALL));
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>
@@ -181,14 +174,7 @@ if payments, err := sdk.ListPayments(listPaymentsRequest); err == nil {
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/ListPayments.cs:list-payments-filtered}}
{
var payments = sdk.ListPayments(new ListPaymentsRequest(PaymentTypeFilter.SENT, fromTimestamp=1696880000, includeFailures=true));
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -121,26 +121,7 @@ if input, err := breez_sdk.ParseInput(lnurlAuthUrl); err != nil {
<section> <section>
```cs ```cs
// Endpoint can also be of the form: {{#include ../../snippets/csharp/LnurlAuth.cs:lnurl-auth}}
// keyauth://domain.com/auth?key=val
var lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";
try
{
var input = BreezSdkMethods.ParseInput(lnurlAuthUrl);
if (input is InputType.LnUrlAuth lnurla) {
var result = sdk.LnurlAuth(lnurla.data);
if (result is LnUrlCallbackStatus.Ok) {
Console.WriteLine("Successfully authenticated");
} else {
Console.WriteLine("Failed to authenticate");
}
}
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -130,23 +130,7 @@ if input, err := breez_sdk.ParseInput(lnurlPayUrl); err != nil {
<section> <section>
```cs ```cs
// Endpoint can also be of the form: {{#include ../../snippets/csharp/LnurlPay.cs:lnurl-pay}}
// lnurlp://domain.com/lnurl-pay?key=val
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
var lnurlPayUrl = "lightning@address.com";
try
{
var input = BreezSdkMethods.ParseInput(lnurlPayUrl);
if (input is InputType.LnUrlPay lnurlp) {
var amountMsat = lnurlp.data.minSendable;
var result = sdk.PayLnurl(new LnUrlPayRequest(lnurlp.data, amountMsat, "comment"));
}
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -127,27 +127,7 @@ if input, err := breez_sdk.ParseInput(lnurlWithdrawUrl); err != nil {
<section> <section>
```cs ```cs
// Endpoint can also be of the form: {{#include ../../snippets/csharp/LnurlWithdraw.cs:lnurl-withdraw}}
// lnurlw://domain.com/lnurl-withdraw?key=val
var lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";
try
{
var input = BreezSdkMethods.ParseInput(lnurlWithdrawUrl);
if (input is InputType.LnUrlWithdraw lnurlw)
{
var amountMsat = lnurlw.data.minWithdrawable;
var result = sdk.WithdrawLnurl(
new LnUrlWithdrawRequest(
lnurlw.data,
amountMsat,
"comment"));
}
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -89,17 +89,7 @@ if swapInfo, err := sdk.ReceiveOnchain(breez_sdk.ReceiveOnchainRequest{}); err !
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/ReceiveOnchain.cs:generate-receive-onchain-address}}
{
var swapInfo = sdk.ReceiveOnchain(new ReceiveOnchainRequest());
// Send your funds to the below bitcoin address
var address = swapInfo.bitcoinAddress;
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>
@@ -180,14 +170,7 @@ if swapInfo, err := sdk.InProgressSwap(); err == nil {
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/ReceiveOnchain.cs:in-progress-swap}}
{
var swapInfo = sdk.InProgressSwap();
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>
@@ -273,14 +256,7 @@ if refundables, err := sdk.ListRefundables(); err == nil {
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/ReceiveOnchain.cs:list-refundables}}
{
var refundables = sdk.ListRefundables();
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>
@@ -380,16 +356,7 @@ if refundables, err := sdk.ListRefundables(); err == nil {
<section> <section>
```cs ```cs
var destinationAddress = "..."; {{#include ../../snippets/csharp/ReceiveOnchain.cs:execute-refund}}
var satPerVbyte = <refund tx fee rate>;
try
{
var result = sdk.Refund(refundable.bitcoinAddress, destinationAddress, satPerVbyte);
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>
@@ -476,8 +443,7 @@ if channelFees, err := sdk.OpenChannelFee(breez_sdk.OpenChannelFeeRequest{Amount
<section> <section>
```cs ```cs
ulong amountMsat = <amount msat>; {{#include ../../snippets/csharp/ReceiveOnchain.cs:get-channel-opening-fees}}
var channelFees = sdk.OpenChannelFee(new OpenChannelFeeRequest(amountMsat));
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -90,15 +90,7 @@ if receivePaymentResponse, err := sdk.ReceivePayment(receivePaymentRequest); err
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/ReceivePayment.cs:receive-payment}}
{
var invoice = sdk.ReceivePayment(
new ReceivePaymentRequest(3_000_000, "Invoice for 3000 sats"));
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -88,16 +88,7 @@ if currentFees, err := sdk.FetchReverseSwapFees(reverseSwapFeesRequest); err ==
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/SendOnchain.cs:estimate-current-reverse-swap-total-fees}}
{
var currentFees = sdk.FetchReverseSwapFees(
new ReverseSwapFeesRequest(50000));
Console.WriteLine($"Total estimated fees for reverse swap: {currentFees.totalEstimatedFees}");
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>
@@ -173,8 +164,7 @@ log.Printf("Maximum amount, in sats: %v", currentFees.Max)
<section> <section>
```cs ```cs
Console.WriteLine($"Minimum amount, in sats: {currentFees.min}"); {{#include ../../snippets/csharp/SendOnchain.cs:get-current-reverse-swap-min-max}}
Console.WriteLine($"Maximum amount, in sats: {currentFees.max}");
``` ```
</section> </section>
</custom-tabs> </custom-tabs>
@@ -276,18 +266,7 @@ if currentFees, err := sdk.FetchReverseSwapFees(breez_sdk.ReverseSwapFeesRequest
<section> <section>
```cs ```cs
var destinationAddress = "bc1.."; {{#include ../../snippets/csharp/SendOnchain.cs:start-reverse-swap}}
var amountSat = currentFees.min;
var satPerVbyte = <fee rate>;
try
{
var reverseSwapInfo = sdk.SendOnchain(
amountSat, destinationAddress, currentFees.feesHash, satPerVbyte);
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>
@@ -372,17 +351,7 @@ if swaps, err := sdk.InProgressReverseSwaps(); err == nil {
<section> <section>
```cs ```cs
try {{#include ../../snippets/csharp/SendOnchain.cs:check-reverse-swaps-status}}
{
var swaps = sdk.InProgressReverseSwaps();
foreach (var swap in swaps) {
Console.WriteLine($"Reverse swap {swap.id} in progress, status is {swap.status}`");
}
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -96,18 +96,7 @@ if response, err := sdk.SendPayment(sendPaymentRequest); err == nil {
<section> <section>
```cs ```cs
var bolt11 = "..."; {{#include ../../snippets/csharp/SendPayment.cs:send-payment}}
var amountMsat = 3000000;
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));
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -90,16 +90,7 @@ if response, err := sdk.SendSpontaneousPayment(sendSpontaneousPaymentRequest); e
<section> <section>
```cs ```cs
var nodeId = "..."; {{#include ../../snippets/csharp/SendSpontaneousPayment.cs:send-spontaneous-payment}}
var amountMsat = 3000000;
try
{
var response = sdk.SendSpontaneousPayment(new SendSpontaneousPaymentRequest(nodeId, amountMsat));
}
catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>

View File

@@ -86,15 +86,7 @@ if staticBackupResponse, err := breez_sdk.StaticBackup(breez_sdk.StaticBackupReq
<section> <section>
```cs ```cs
using Breez.Sdk; {{#include ../../snippets/csharp/StaticChannelBackup.cs:static-channel-backup}}
try
{
var backupData = BreezSdkMethods.StaticBackup(new StaticBackupRequest("<working directory>"));
} catch (Exception)
{
// Handle error
}
``` ```
</section> </section>
</custom-tabs> </custom-tabs>