diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 452955d..52d71d0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,4 +56,20 @@ jobs: - name: dart-analyze run: | cd snippets/dart_snippets - dart analyze --fatal-infos \ No newline at end of file + 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 diff --git a/snippets/csharp/.gitignore b/snippets/csharp/.gitignore new file mode 100644 index 0000000..9965de2 --- /dev/null +++ b/snippets/csharp/.gitignore @@ -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 diff --git a/snippets/csharp/BuyBtc.cs b/snippets/csharp/BuyBtc.cs new file mode 100644 index 0000000..960ba15 --- /dev/null +++ b/snippets/csharp/BuyBtc.cs @@ -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 + } +} diff --git a/snippets/csharp/ConnectingLsp.cs b/snippets/csharp/ConnectingLsp.cs new file mode 100644 index 0000000..7981e3f --- /dev/null +++ b/snippets/csharp/ConnectingLsp.cs @@ -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 + } +} diff --git a/snippets/csharp/FiatCurrencies.cs b/snippets/csharp/FiatCurrencies.cs new file mode 100644 index 0000000..7ceced3 --- /dev/null +++ b/snippets/csharp/FiatCurrencies.cs @@ -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 + } +} diff --git a/snippets/csharp/GettingStarted.cs b/snippets/csharp/GettingStarted.cs new file mode 100644 index 0000000..6493927 --- /dev/null +++ b/snippets/csharp/GettingStarted.cs @@ -0,0 +1,62 @@ +using Breez.Sdk; + +public class GettingStartedSnippets +{ + // ANCHOR: init-sdk + public void GettingStarted() + { + // Create the default config + var seed = BreezSdkMethods.MnemonicToSeed(""); + var inviteCode = ""; + var apiKey = ""; + 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 + } +} diff --git a/snippets/csharp/ListPayments.cs b/snippets/csharp/ListPayments.cs new file mode 100644 index 0000000..3938bf9 --- /dev/null +++ b/snippets/csharp/ListPayments.cs @@ -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 + } +} diff --git a/snippets/csharp/LnurlAuth.cs b/snippets/csharp/LnurlAuth.cs new file mode 100644 index 0000000..408b0b1 --- /dev/null +++ b/snippets/csharp/LnurlAuth.cs @@ -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 + } +} diff --git a/snippets/csharp/LnurlPay.cs b/snippets/csharp/LnurlPay.cs new file mode 100644 index 0000000..c63d71c --- /dev/null +++ b/snippets/csharp/LnurlPay.cs @@ -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 + } +} diff --git a/snippets/csharp/LnurlWithdraw.cs b/snippets/csharp/LnurlWithdraw.cs new file mode 100644 index 0000000..3463912 --- /dev/null +++ b/snippets/csharp/LnurlWithdraw.cs @@ -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 + } +} diff --git a/snippets/csharp/ReceiveOnchain.cs b/snippets/csharp/ReceiveOnchain.cs new file mode 100644 index 0000000..c987847 --- /dev/null +++ b/snippets/csharp/ReceiveOnchain.cs @@ -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 + } +} diff --git a/snippets/csharp/ReceivePayment.cs b/snippets/csharp/ReceivePayment.cs new file mode 100644 index 0000000..52c2845 --- /dev/null +++ b/snippets/csharp/ReceivePayment.cs @@ -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 + } +} diff --git a/snippets/csharp/SendOnchain.cs b/snippets/csharp/SendOnchain.cs new file mode 100644 index 0000000..bc97cd9 --- /dev/null +++ b/snippets/csharp/SendOnchain.cs @@ -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 + } +} diff --git a/snippets/csharp/SendPayment.cs b/snippets/csharp/SendPayment.cs new file mode 100644 index 0000000..ac393a5 --- /dev/null +++ b/snippets/csharp/SendPayment.cs @@ -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 + } +} diff --git a/snippets/csharp/SendSpontaneousPayment.cs b/snippets/csharp/SendSpontaneousPayment.cs new file mode 100644 index 0000000..6bc32b2 --- /dev/null +++ b/snippets/csharp/SendSpontaneousPayment.cs @@ -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 + } +} diff --git a/snippets/csharp/Snippets.csproj b/snippets/csharp/Snippets.csproj new file mode 100644 index 0000000..a8a9c3f --- /dev/null +++ b/snippets/csharp/Snippets.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + enable + + + + + + + diff --git a/snippets/csharp/StaticChannelBackup.cs b/snippets/csharp/StaticChannelBackup.cs new file mode 100644 index 0000000..e918d5f --- /dev/null +++ b/snippets/csharp/StaticChannelBackup.cs @@ -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("")); + } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: static-channel-backup + } +} diff --git a/src/guide/buy_btc.md b/src/guide/buy_btc.md index c33345c..4238db8 100644 --- a/src/guide/buy_btc.md +++ b/src/guide/buy_btc.md @@ -93,15 +93,7 @@ if buyBitcoinResponse, err := sdk.BuyBitcoin(buyBitcoinRequest); err == nil {
```cs -try -{ - var buyBitcoinResponse = sdk.BuyBitcoin( - new BuyBitcoinRequest(BuyBitcoinProvider.MOONPAY)); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/BuyBtc.cs:buy-btc}} ```
\ No newline at end of file diff --git a/src/guide/connecting_lsp.md b/src/guide/connecting_lsp.md index 6c4e833..73ccf46 100644 --- a/src/guide/connecting_lsp.md +++ b/src/guide/connecting_lsp.md @@ -87,15 +87,7 @@ if lspInfo, err := sdk.LspInfo(); err == nil {
```cs -try -{ - var lspId = sdk.LspId(); - var lspInfo = sdk.LspInfo(); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/ConnectingLsp.cs:get-lsp-info}} ```
@@ -177,14 +169,7 @@ if err := sdk.ConnectLsp(lspId); err != nil {
```cs -try -{ - sdk.ConnectLsp(lspId!); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/ConnectingLsp.cs:connect-lsp}} ```
diff --git a/src/guide/fiat_currencies.md b/src/guide/fiat_currencies.md index 7717901..8fe25a3 100644 --- a/src/guide/fiat_currencies.md +++ b/src/guide/fiat_currencies.md @@ -65,14 +65,7 @@ if fiatCurrencies, err := sdk.ListFiatCurrencies(); err == nil {
```cs -try -{ - var fiatCurrencies = sdk.ListFiatCurrencies(); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/FiatCurrencies.cs:list-fiat-currencies}} ```
@@ -142,14 +135,7 @@ if fiatRates, err := sdk.FetchFiatRates(); err == nil {
```cs -try -{ - var fiatRates = sdk.FetchFiatRates(); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/FiatCurrencies.cs:fetch-fiat-rates}} ```
@@ -231,7 +217,7 @@ fun fiatCurrenciesAndRate(): Map = try {
```cs -// TODO +{{#include ../../snippets/csharp/FiatCurrencies.cs:get-fiat-currencies-and-rates}} ```
\ No newline at end of file diff --git a/src/guide/getting_started.md b/src/guide/getting_started.md index 70d16ef..a212443 100644 --- a/src/guide/getting_started.md +++ b/src/guide/getting_started.md @@ -203,42 +203,7 @@ if err != nil {
```cs -using Breez.Sdk; - -// Create the default config -var seed = BreezSdkMethods.MnemonicToSeed(""); -var inviteCode = ""; -var apiKey = ""; -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}"); - } -} +{{#include ../../snippets/csharp/GettingStarted.cs:init-sdk}} ```
@@ -326,15 +291,7 @@ if nodeInfo, err := sdkServices.NodeInfo(); err != nil {
```cs -try -{ - var nodeInfo = sdk.NodeInfo(); - var lnBalance = nodeInfo?.channelsBalanceMsat; - var onchainBalance = nodeInfo?.onchainBalanceMsat; -} -catch (Exception) { - // Handle error -} +{{#include ../../snippets/csharp/GettingStarted.cs:fetch-balance}} ```
diff --git a/src/guide/list_payments.md b/src/guide/list_payments.md index 000067f..0f161be 100644 --- a/src/guide/list_payments.md +++ b/src/guide/list_payments.md @@ -76,14 +76,7 @@ if payments, err := sdk.ListPayments(breez_sdk.ListPaymentsRequest{Filter: breez
```cs -try -{ - var payments = sdk.ListPayments(new ListPaymentsRequest(PaymentTypeFilter.ALL)); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/ListPayments.cs:list-payments}} ```
@@ -181,14 +174,7 @@ if payments, err := sdk.ListPayments(listPaymentsRequest); err == nil {
```cs -try -{ - var payments = sdk.ListPayments(new ListPaymentsRequest(PaymentTypeFilter.SENT, fromTimestamp=1696880000, includeFailures=true)); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/ListPayments.cs:list-payments-filtered}} ```
diff --git a/src/guide/lnurl_auth.md b/src/guide/lnurl_auth.md index c113552..83626e4 100644 --- a/src/guide/lnurl_auth.md +++ b/src/guide/lnurl_auth.md @@ -121,26 +121,7 @@ if input, err := breez_sdk.ParseInput(lnurlAuthUrl); err != nil {
```cs -// 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 -} +{{#include ../../snippets/csharp/LnurlAuth.cs:lnurl-auth}} ```
diff --git a/src/guide/lnurl_pay.md b/src/guide/lnurl_pay.md index 1fb66a6..6ddbf9b 100644 --- a/src/guide/lnurl_pay.md +++ b/src/guide/lnurl_pay.md @@ -130,23 +130,7 @@ if input, err := breez_sdk.ParseInput(lnurlPayUrl); err != nil {
```cs -// 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 -} +{{#include ../../snippets/csharp/LnurlPay.cs:lnurl-pay}} ```
diff --git a/src/guide/lnurl_withdraw.md b/src/guide/lnurl_withdraw.md index 900550a..e0c3a61 100644 --- a/src/guide/lnurl_withdraw.md +++ b/src/guide/lnurl_withdraw.md @@ -127,27 +127,7 @@ if input, err := breez_sdk.ParseInput(lnurlWithdrawUrl); err != nil {
```cs -// 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 -} +{{#include ../../snippets/csharp/LnurlWithdraw.cs:lnurl-withdraw}} ```
diff --git a/src/guide/receive_onchain.md b/src/guide/receive_onchain.md index 27c5188..134fd9f 100644 --- a/src/guide/receive_onchain.md +++ b/src/guide/receive_onchain.md @@ -89,17 +89,7 @@ if swapInfo, err := sdk.ReceiveOnchain(breez_sdk.ReceiveOnchainRequest{}); err !
```cs -try -{ - var swapInfo = sdk.ReceiveOnchain(new ReceiveOnchainRequest()); - - // Send your funds to the below bitcoin address - var address = swapInfo.bitcoinAddress; -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/ReceiveOnchain.cs:generate-receive-onchain-address}} ```
@@ -180,14 +170,7 @@ if swapInfo, err := sdk.InProgressSwap(); err == nil {
```cs -try -{ - var swapInfo = sdk.InProgressSwap(); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/ReceiveOnchain.cs:in-progress-swap}} ```
@@ -273,14 +256,7 @@ if refundables, err := sdk.ListRefundables(); err == nil {
```cs -try -{ - var refundables = sdk.ListRefundables(); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/ReceiveOnchain.cs:list-refundables}} ```
@@ -380,16 +356,7 @@ if refundables, err := sdk.ListRefundables(); err == nil {
```cs -var destinationAddress = "..."; -var satPerVbyte = ; -try -{ - var result = sdk.Refund(refundable.bitcoinAddress, destinationAddress, satPerVbyte); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/ReceiveOnchain.cs:execute-refund}} ```
@@ -476,8 +443,7 @@ if channelFees, err := sdk.OpenChannelFee(breez_sdk.OpenChannelFeeRequest{Amount
```cs -ulong amountMsat = ; -var channelFees = sdk.OpenChannelFee(new OpenChannelFeeRequest(amountMsat)); +{{#include ../../snippets/csharp/ReceiveOnchain.cs:get-channel-opening-fees}} ```
diff --git a/src/guide/receive_payment.md b/src/guide/receive_payment.md index 6e677c2..f7063e6 100644 --- a/src/guide/receive_payment.md +++ b/src/guide/receive_payment.md @@ -90,15 +90,7 @@ if receivePaymentResponse, err := sdk.ReceivePayment(receivePaymentRequest); err
```cs -try -{ - var invoice = sdk.ReceivePayment( - new ReceivePaymentRequest(3_000_000, "Invoice for 3000 sats")); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/ReceivePayment.cs:receive-payment}} ```
diff --git a/src/guide/send_onchain.md b/src/guide/send_onchain.md index 673357f..30aebe1 100644 --- a/src/guide/send_onchain.md +++ b/src/guide/send_onchain.md @@ -88,16 +88,7 @@ if currentFees, err := sdk.FetchReverseSwapFees(reverseSwapFeesRequest); err ==
```cs -try -{ - var currentFees = sdk.FetchReverseSwapFees( - new ReverseSwapFeesRequest(50000)); - Console.WriteLine($"Total estimated fees for reverse swap: {currentFees.totalEstimatedFees}"); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/SendOnchain.cs:estimate-current-reverse-swap-total-fees}} ```
@@ -173,8 +164,7 @@ log.Printf("Maximum amount, in sats: %v", currentFees.Max)
```cs -Console.WriteLine($"Minimum amount, in sats: {currentFees.min}"); -Console.WriteLine($"Maximum amount, in sats: {currentFees.max}"); +{{#include ../../snippets/csharp/SendOnchain.cs:get-current-reverse-swap-min-max}} ```
@@ -276,18 +266,7 @@ if currentFees, err := sdk.FetchReverseSwapFees(breez_sdk.ReverseSwapFeesRequest
```cs -var destinationAddress = "bc1.."; -var amountSat = currentFees.min; -var satPerVbyte = ; -try -{ - var reverseSwapInfo = sdk.SendOnchain( - amountSat, destinationAddress, currentFees.feesHash, satPerVbyte); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/SendOnchain.cs:start-reverse-swap}} ```
@@ -372,17 +351,7 @@ if swaps, err := sdk.InProgressReverseSwaps(); err == nil {
```cs -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 -} +{{#include ../../snippets/csharp/SendOnchain.cs:check-reverse-swaps-status}} ```
diff --git a/src/guide/send_payment.md b/src/guide/send_payment.md index b90868f..83b070f 100644 --- a/src/guide/send_payment.md +++ b/src/guide/send_payment.md @@ -96,18 +96,7 @@ if response, err := sdk.SendPayment(sendPaymentRequest); err == nil {
```cs -var bolt11 = "..."; -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 -} +{{#include ../../snippets/csharp/SendPayment.cs:send-payment}} ```
diff --git a/src/guide/send_spontaneous_payment.md b/src/guide/send_spontaneous_payment.md index ed6065c..874616b 100644 --- a/src/guide/send_spontaneous_payment.md +++ b/src/guide/send_spontaneous_payment.md @@ -90,16 +90,7 @@ if response, err := sdk.SendSpontaneousPayment(sendSpontaneousPaymentRequest); e
```cs -var nodeId = "..."; -var amountMsat = 3000000; -try -{ - var response = sdk.SendSpontaneousPayment(new SendSpontaneousPaymentRequest(nodeId, amountMsat)); -} -catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/SendSpontaneousPayment.cs:send-spontaneous-payment}} ```
diff --git a/src/guide/static_channel_backup.md b/src/guide/static_channel_backup.md index ef63fb2..42dc287 100644 --- a/src/guide/static_channel_backup.md +++ b/src/guide/static_channel_backup.md @@ -86,15 +86,7 @@ if staticBackupResponse, err := breez_sdk.StaticBackup(breez_sdk.StaticBackupReq
```cs -using Breez.Sdk; - -try -{ - var backupData = BreezSdkMethods.StaticBackup(new StaticBackupRequest("")); -} catch (Exception) -{ - // Handle error -} +{{#include ../../snippets/csharp/StaticChannelBackup.cs:static-channel-backup}} ```