Add Go snippets

This commit is contained in:
Erdem Yerebasmaz
2023-11-06 18:24:04 +03:00
committed by Erdem Yerebasmaz
parent f65bcc1653
commit dc64895b65
31 changed files with 513 additions and 213 deletions

26
snippets/go/.gitignore vendored Normal file
View File

@@ -0,0 +1,26 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
# Ignore Go binaries
**/*
!**/*.go
!**/

18
snippets/go/buy_btc.go Normal file
View File

@@ -0,0 +1,18 @@
package example
import (
"log"
"github.com/breez/breez-sdk-go/breez_sdk"
)
func BuyBitcoin() {
// ANCHOR: buy-btc
buyBitcoinRequest := breez_sdk.BuyBitcoinRequest{
Provider: breez_sdk.BuyBitcoinProviderMoonpay,
}
if buyBitcoinResponse, err := sdk.BuyBitcoin(buyBitcoinRequest); err == nil {
log.Printf("%#v", buyBitcoinResponse)
}
// ANCHOR_END: buy-btc
}

View File

@@ -0,0 +1,27 @@
package example
import (
"log"
)
func GetLspInfo() {
// ANCHOR: get-lsp-info
if lspId, err := sdk.LspId(); lspId != nil && err == nil {
log.Printf("%#v", *lspId)
}
if lspInfo, err := sdk.LspInfo(); err == nil {
log.Printf("%#v", lspInfo)
}
// ANCHOR_END: get-lsp-info
}
func ConnectLsp() {
// ANCHOR: connect-lsp
lspId := "your selected lsp id"
if err := sdk.ConnectLsp(lspId); err != nil {
log.Printf("%#v", err)
}
// ANCHOR_END: connect-lsp
}

View File

@@ -0,0 +1,27 @@
package example
import (
"log"
)
func ListFiatCurrencies() {
// ANCHOR: list-fiat-currencies
if fiatCurrencies, err := sdk.ListFiatCurrencies(); err == nil {
log.Printf("%#v", fiatCurrencies)
}
// ANCHOR_END: list-fiat-currencies
}
func FetchFiatRates() {
// ANCHOR: fetch-fiat-rates
if fiatRates, err := sdk.FetchFiatRates(); err == nil {
log.Printf("%#v", fiatRates)
}
// ANCHOR_END: fetch-fiat-rates
}
func GetFiatCurrenciesAndRates() {
// ANCHOR: get-fiat-currencies-and-rates
// TODO
// ANCHOR_END: get-fiat-currencies-and-rates
}

View File

@@ -0,0 +1,53 @@
package example
import (
"log"
"github.com/breez/breez-sdk-go/breez_sdk"
)
// ANCHOR: init-sdk-requirements
// SDK events listener
type BreezListener struct{}
func (BreezListener) OnEvent(e breez_sdk.BreezEvent) {
log.Printf("received event %#v", e)
}
// ANCHOR_END: init-sdk-requirements
func GettingStarted() {
// ANCHOR: init-sdk
// Create the default config
seed, err := breez_sdk.MnemonicToSeed("<mnemonic words>")
if err != nil {
log.Fatalf("MnemonicToSeed failed: %#v", err)
}
inviteCode := "<invite code>"
apiKey := "<api key>"
nodeConfig := breez_sdk.NodeConfigGreenlight{
Config: breez_sdk.GreenlightNodeConfig{
PartnerCredentials: nil,
InviteCode: &inviteCode,
},
}
config := breez_sdk.DefaultConfig(breez_sdk.EnvironmentTypeProduction, apiKey, nodeConfig)
// Customize the config object according to your needs
config.WorkingDir = "path to an existing directory"
sdk, err := breez_sdk.Connect(config, seed, BreezListener{})
if err != nil {
log.Fatalf("Connect failed: %#v", err)
}
// ANCHOR_END: init-sdk
// ANCHOR: fetch-balance
if nodeInfo, err := sdk.NodeInfo(); err != nil {
lnBalance := nodeInfo.ChannelsBalanceMsat
onchainBalance := nodeInfo.OnchainBalanceMsat
log.Printf("%#v %#v", lnBalance, onchainBalance)
}
// ANCHOR_END: fetch-balance
}

5
snippets/go/go.mod Normal file
View File

@@ -0,0 +1,5 @@
module main
go 1.19
require github.com/breez/breez-sdk-go v0.2.7

View File

@@ -0,0 +1,30 @@
package example
import (
"log"
"github.com/breez/breez-sdk-go/breez_sdk"
)
func ListPayments() {
// ANCHOR: list-payments
if payments, err := sdk.ListPayments(breez_sdk.ListPaymentsRequest{Filter: breez_sdk.PaymentTypeFilterAll}); err == nil {
log.Printf("%#v", payments)
}
// ANCHOR_END: list-payments
}
func ListPaymentsFiltered() {
// ANCHOR: list-payments-filtered
fromTimestamp := int64(1696880000)
includeFailures := true
listPaymentsRequest := breez_sdk.ListPaymentsRequest{
Filter: breez_sdk.PaymentTypeFilterSent,
FromTimestamp: &fromTimestamp,
IncludeFailures: &includeFailures,
}
if payments, err := sdk.ListPayments(listPaymentsRequest); err == nil {
log.Printf("%#v", payments)
}
// ANCHOR_END: list-payments-filtered
}

28
snippets/go/lnurl_auth.go Normal file
View File

@@ -0,0 +1,28 @@
package example
import (
"log"
"github.com/breez/breez-sdk-go/breez_sdk"
)
func LnurlAuth() {
// ANCHOR: lnurl-auth
// keyauth://domain.com/auth?key=val
lnurlAuthUrl := "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
if input, err := breez_sdk.ParseInput(lnurlAuthUrl); err != nil {
switch inputType := input.(type) {
case breez_sdk.InputTypeLnUrlAuth:
if result, err := sdk.LnurlAuth(inputType.Data); err != nil {
switch result.(type) {
case breez_sdk.LnUrlCallbackStatusOk:
log.Printf("Successfully authenticated")
default:
log.Printf("Failed to authenticate")
}
}
}
}
// ANCHOR_END: lnurl-auth
}

37
snippets/go/lnurl_pay.go Normal file
View File

@@ -0,0 +1,37 @@
package example
import (
"log"
"github.com/breez/breez-sdk-go/breez_sdk"
)
func LnurlPay() {
// ANCHOR: lnurl-pay
// Endpoint can also be of the form:
// lnurlp://domain.com/lnurl-pay?key=val
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
lnurlPayUrl := "lightning@address.com"
if input, err := breez_sdk.ParseInput(lnurlPayUrl); err != nil {
switch inputType := input.(type) {
case breez_sdk.InputTypeLnUrlPay:
amountMsat := inputType.Data.MinSendable
comment := "comment"
lnUrlPayRequest := breez_sdk.LnUrlPayRequest{
Data: inputType.Data,
AmountMsat: amountMsat,
Comment: &comment,
}
if result, err := sdk.PayLnurl(lnUrlPayRequest); err != nil {
switch result.(type) {
case breez_sdk.LnUrlPayResultEndpointSuccess:
log.Printf("Successfully paid")
default:
log.Printf("Failed to pay")
}
}
}
}
// ANCHOR_END: lnurl-pay
}

View File

@@ -0,0 +1,35 @@
package example
import (
"log"
"github.com/breez/breez-sdk-go/breez_sdk"
)
func LnurlWithdraw() {
// ANCHOR: lnurl-withdraw
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
lnurlWithdrawUrl := "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"
if input, err := breez_sdk.ParseInput(lnurlWithdrawUrl); err != nil {
switch inputType := input.(type) {
case breez_sdk.InputTypeLnUrlWithdraw:
amountMsat := inputType.Data.MinWithdrawable
description := "comment"
if result, err := sdk.WithdrawLnurl(breez_sdk.LnUrlWithdrawRequest{
Data: inputType.Data,
AmountMsat: amountMsat,
Description: &description,
}); err != nil {
switch result.(type) {
case breez_sdk.LnUrlCallbackStatusOk:
log.Printf("Successfully withdrawn")
default:
log.Printf("Failed to withdraw")
}
}
}
}
// ANCHOR_END: lnurl-withdraw
}

9
snippets/go/main.go Normal file
View File

@@ -0,0 +1,9 @@
package example
import (
"github.com/breez/breez-sdk-go/breez_sdk"
)
var sdk breez_sdk.BlockingBreezServices
func main() {}

View File

@@ -0,0 +1,58 @@
package example
import (
"log"
"github.com/breez/breez-sdk-go/breez_sdk"
)
func GenerateReceiveOnchainAddress() {
// ANCHOR: generate-receive-onchain-address
if swapInfo, err := sdk.ReceiveOnchain(breez_sdk.ReceiveOnchainRequest{}); err != nil {
// Send your funds to the below bitcoin address
address := swapInfo.BitcoinAddress
log.Printf("%v", address)
}
// ANCHOR_END: generate-receive-onchain-address
}
func GetInProgressSwap() {
// ANCHOR: in-progress-swap
if swapInfo, err := sdk.InProgressSwap(); err == nil {
log.Printf("%#v", swapInfo)
}
// ANCHOR_END: in-progress-swap
}
func ListRefundables() {
// ANCHOR: list-refundables
if refundables, err := sdk.ListRefundables(); err == nil {
log.Printf("%#v", refundables)
}
// ANCHOR_END: list-refundables
}
func ExecuteRefund() {
// ANCHOR: execute-refund
if refundables, err := sdk.ListRefundables(); err == nil {
destinationAddress := "..."
satPerVbyte := uint32(5)
refundRequest := breez_sdk.RefundRequest{
SwapAddress: refundables[0].BitcoinAddress,
ToAddress: destinationAddress,
SatPerVbyte: satPerVbyte,
}
if result, err := sdk.Refund(refundRequest); err == nil {
log.Printf("%v", result)
}
}
// ANCHOR_END: execute-refund
}
func GetChannelOpeningFees(amountMsat uint64) {
// ANCHOR: get-channel-opening-fees
if channelFees, err := sdk.OpenChannelFee(breez_sdk.OpenChannelFeeRequest{AmountMsat: amountMsat}); err == nil {
log.Printf("%#v", channelFees)
}
// ANCHOR_END: get-channel-opening-fees
}

View File

@@ -0,0 +1,19 @@
package example
import (
"log"
"github.com/breez/breez-sdk-go/breez_sdk"
)
func ReceivePayment() {
// ANCHOR: receive-payment
receivePaymentRequest := breez_sdk.ReceivePaymentRequest{
AmountMsat: uint64(3_000_000),
Description: "Invoice for 3000 sats",
}
if receivePaymentResponse, err := sdk.ReceivePayment(receivePaymentRequest); err == nil {
log.Printf("%#v", receivePaymentResponse)
}
// ANCHOR_END: receive-payment
}

View File

@@ -0,0 +1,55 @@
package example
import (
"log"
"github.com/breez/breez-sdk-go/breez_sdk"
)
func GetCurrentFees() {
// ANCHOR: estimate-current-reverse-swap-total-fees
sendAmountSat := uint64(50_000)
reverseSwapFeesRequest := breez_sdk.ReverseSwapFeesRequest{
SendAmountSat: &sendAmountSat,
}
if currentFees, err := sdk.FetchReverseSwapFees(reverseSwapFeesRequest); err == nil {
log.Printf("Total estimated fees for reverse swap: %v", currentFees.TotalEstimatedFees)
}
// ANCHOR_END: estimate-current-reverse-swap-total-fees
}
func ListCurrentFees(currentFees breez_sdk.ReverseSwapPairInfo) {
// ANCHOR: get-current-reverse-swap-min-max
log.Printf("Minimum amount, in sats: %v", currentFees.Min)
log.Printf("Maximum amount, in sats: %v", currentFees.Max)
// ANCHOR_END: get-current-reverse-swap-min-max
}
func StartReverseSwap() {
// ANCHOR: start-reverse-swap
destinationAddress := "bc1.."
sendAmountSat := uint64(50_000)
satPerVbyte := uint32(5)
if currentFees, err := sdk.FetchReverseSwapFees(breez_sdk.ReverseSwapFeesRequest{SendAmountSat: &sendAmountSat}); err == nil {
sendOnchainRequest := breez_sdk.SendOnchainRequest{
AmountSat: sendAmountSat,
OnchainRecipientAddress: destinationAddress,
PairHash: currentFees.FeesHash,
SatPerVbyte: satPerVbyte,
}
if reverseSwapInfo, err := sdk.SendOnchain(sendOnchainRequest); err == nil {
log.Printf("%#v", reverseSwapInfo)
}
}
// ANCHOR_END: start-reverse-swap
}
func CheckReverseSwapStatus() {
// ANCHOR: check-reverse-swaps-status
if swaps, err := sdk.InProgressReverseSwaps(); err == nil {
for _, swap := range swaps {
log.Printf("Reverse swap %v in progress, status is %v", swap.Id, swap.Status)
}
}
// ANCHOR_END: check-reverse-swaps-status
}

View File

@@ -0,0 +1,23 @@
package example
import (
"log"
"github.com/breez/breez-sdk-go/breez_sdk"
)
func SendPayment() {
// ANCHOR: send-payment
bolt11 := "bolt11 invoice"
// 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'.
amountMsat := uint64(3_000_000)
sendPaymentRequest := breez_sdk.SendPaymentRequest{
Bolt11: bolt11,
AmountMsat: &amountMsat,
}
if response, err := sdk.SendPayment(sendPaymentRequest); err == nil {
log.Printf("%#v", response)
}
// ANCHOR_END: send-payment
}

View File

@@ -0,0 +1,19 @@
package example
import (
"log"
"github.com/breez/breez-sdk-go/breez_sdk"
)
func SendSpontaneousPayment() {
// ANCHOR: send-spontaneous-payment
sendSpontaneousPaymentRequest := breez_sdk.SendSpontaneousPaymentRequest{
NodeId: "...",
AmountMsat: uint64(3_000_000),
}
if response, err := sdk.SendSpontaneousPayment(sendSpontaneousPaymentRequest); err == nil {
log.Printf("%#v", response)
}
// ANCHOR_END: send-spontaneous-payment
}

View File

@@ -0,0 +1,16 @@
package example
import (
"log"
"github.com/breez/breez-sdk-go/breez_sdk"
)
func RetrieveBackupFiles() {
// ANCHOR: static-channel-backup
workingDir := "<working directory>"
if staticBackupResponse, err := breez_sdk.StaticBackup(breez_sdk.StaticBackupRequest{WorkingDir: workingDir}); err == nil {
log.Printf("%#v", staticBackupResponse)
}
// ANCHOR_END: static-channel-backup
}

View File

@@ -79,12 +79,7 @@ except Exception as error:
<section>
```go
buyBitcoinRequest := breez_sdk.BuyBitcoinRequest{
Provider: breez_sdk.BuyBitcoinProviderMoonpay,
}
if buyBitcoinResponse, err := sdk.BuyBitcoin(buyBitcoinRequest); err == nil {
log.Printf("%#v", buyBitcoinResponse)
}
{{#include ../../snippets/go/buy_btc.go:buy-btc}}
```
</section>

View File

@@ -74,12 +74,7 @@ except Exception as error:
<section>
```go
if lspId, err := sdk.LspId(); lspId != nil && err == nil {
log.Printf("%#v", *lspId)
}
if lspInfo, err := sdk.LspInfo(); err == nil {
log.Printf("%#v", lspInfo)
}
{{#include ../../snippets/go/connecting_lsp.go:get-lsp-info}}
```
</section>
@@ -158,10 +153,7 @@ except Exception as error:
<section>
```go
lspId := "your selected lsp id"
if err := sdk.ConnectLsp(lspId); err != nil {
log.Printf("%#v", err)
}
{{#include ../../snippets/go/connecting_lsp.go:connect-lsp}}
```
</section>

View File

@@ -55,9 +55,7 @@ except Exception as error:
<section>
```go
if fiatCurrencies, err := sdk.ListFiatCurrencies(); err == nil {
log.Printf("%#v", fiatCurrencies)
}
{{#include ../../snippets/go/fiat_currencies.go:list-fiat-currencies}}
```
</section>
@@ -125,9 +123,7 @@ except Exception as error:
<section>
```go
if fiatRates, err := sdk.FetchFiatRates(); err == nil {
log.Printf("%#v", fiatRates)
}
{{#include ../../snippets/go/fiat_currencies.go:fetch-fiat-rates}}
```
</section>
@@ -209,7 +205,7 @@ fun fiatCurrenciesAndRate(): Map<FiatCurrency, Rate> = try {
<section>
```go
// TODO
{{#include ../../snippets/go/fiat_currencies.go:get-fiat-currencies-and-rates}}
```
</section>

View File

@@ -161,41 +161,8 @@ except Exception as error:
<section>
```go
// SDK events listener
type BreezListener struct{}
func (BreezListener) OnEvent(e breez_sdk.BreezEvent) {
log.Printf("received event %#v", e)
}
// Create the default config
seed, err := breez_sdk.MnemonicToSeed("<mnemonic words>")
if err != nil {
log.Fatalf("MnemonicToSeed failed: %#v", err)
}
inviteCode := "<invite code>"
apiKey := "<api key>"
nodeConfig := breez_sdk.NodeConfigGreenlight{
Config: breez_sdk.GreenlightNodeConfig{
PartnerCredentials: nil,
InviteCode: &inviteCode,
},
}
config, err := breez_sdk.DefaultConfig(breez_sdk.EnvironmentTypeProduction, apiKey, nodeConfig)
if err != nil {
log.Fatalf("DefaultConfig failed: %#v", err)
}
// Customize the config object according to your needs
config.workingDir = "path to an existing directory"
sdk, err := breez_sdk.Connect(config, seed, BreezListener{})
if err != nil {
log.Fatalf("Connect failed: %#v", err)
}
{{#include ../../snippets/go/getting_started.go:init-sdk-requirements}}
{{#include ../../snippets/go/getting_started.go:init-sdk}}
```
</section>
@@ -280,10 +247,7 @@ except Exception as error:
<section>
```go
if nodeInfo, err := sdkServices.NodeInfo(); err != nil {
lnBalance := nodeInfo.ChannelsBalanceMsat
onchainBalance := nodeInfo.OnchainBalanceMsat
}
{{#include ../../snippets/go/getting_started.go:fetch-balance}}
```
</section>

View File

@@ -66,9 +66,7 @@ except Exception as error:
<section>
```go
if payments, err := sdk.ListPayments(breez_sdk.ListPaymentsRequest{Filter: breez_sdk.PaymentTypeFilterAll}); err == nil {
log.Printf("%#v", payments)
}
{{#include ../../snippets/go/list_payments.go:list-payments}}
```
</section>
@@ -157,16 +155,7 @@ except Exception as error:
<section>
```go
fromTimestamp := int64(1696880000)
includeFailures := true
listPaymentsRequest := breez_sdk.ListPaymentsRequest{
Filter: breez_sdk.PaymentTypeFilterSent,
FromTimestamp: &fromTimestamp,
IncludeFailures: &includeFailures,
}
if payments, err := sdk.ListPayments(listPaymentsRequest); err == nil {
log.Printf("%#v", payments)
}
{{#include ../../snippets/go/list_payments.go:list-payments-filtered}}
```
</section>

View File

@@ -98,22 +98,7 @@ except Exception as error:
<section>
```go
// Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val
lnurlAuthUrl := "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
if input, err := breez_sdk.ParseInput(lnurlAuthUrl); err != nil {
switch inputType := input.(type) {
case breez_sdk.InputTypeLnUrlAuth:
if result, err := sdk.LnurlAuth(inputType.Data); err != nil {
switch result.(type) {
case breez_sdk.LnUrlCallbackStatusOk:
log.Printf("Successfully authenticated")
default:
log.Printf("Failed to authenticate")
}
}
}
{{#include ../../snippets/go/lnurl_auth.go:lnurl-auth}}
```
</section>

View File

@@ -98,31 +98,7 @@ except Exception as error:
<section>
```go
// Endpoint can also be of the form:
// lnurlp://domain.com/lnurl-pay?key=val
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
lnurlPayUrl := "lightning@address.com"
if input, err := breez_sdk.ParseInput(lnurlPayUrl); err != nil {
switch inputType := input.(type) {
case breez_sdk.InputTypeLnUrlPay:
amountMsat := inputType.Data.MinSendable
comment := "comment"
lnUrlPayRequest := breez_sdk.LnUrlPayRequest{
Data: inputType.Data,
AmountMsat: amountMsat,
Comment: &comment,
}
if result, err := sdk.PayLnurl(lnUrlPayRequest); err != nil {
switch result.(type) {
case breez_sdk.LnUrlPayResultEndpointSuccess:
log.Printf("Successfully paid")
default:
log.Printf("Failed to pay")
}
}
}
}
{{#include ../../snippets/go/lnurl_pay.go:lnurl-pay}}
```
</section>

View File

@@ -97,29 +97,7 @@ except Exception as error:
<section>
```go
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
lnurlWithdrawUrl := "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"
if input, err := breez_sdk.ParseInput(lnurlWithdrawUrl); err != nil {
switch inputType := input.(type) {
case breez_sdk.InputTypeLnUrlWithdraw:
amountMsat := inputType.Data.MinWithdrawable
description := "comment"
if result, err := sdk.WithdrawLnurl(breez_sdk.LnUrlWithdrawRequest{
Data: inputType.Data,
AmountMsat: amountMsat,
Description: &description,
}); err != nil {
switch result.(type) {
case breez_sdk.LnUrlCallbackStatusOk:
log.Printf("Successfully withdrawn")
default:
log.Printf("Failed to withdraw")
}
}
}
}
{{#include ../../snippets/go/lnurl_withdraw.go:lnurl-withdraw}}
```
</section>

View File

@@ -77,11 +77,7 @@ except Exception as error:
<section>
```go
if swapInfo, err := sdk.ReceiveOnchain(breez_sdk.ReceiveOnchainRequest{}); err != nil {
// Send your funds to the below bitcoin address
address := swapInfo.BitcoinAddress
log.Printf("%v", address)
}
{{#include ../../snippets/go/receive_onchain.go:generate-receive-onchain-address}}
```
</section>
@@ -160,9 +156,8 @@ except Exception as error:
<section>
```go
if swapInfo, err := sdk.InProgressSwap(); err == nil {
log.Printf("%#v", swapInfo)
}
{{#include ../../snippets/go/receive_onchain.go:in-progress-swap}}
```
</section>
@@ -246,9 +241,7 @@ except Exception as error:
<section>
```go
if refundables, err := sdk.ListRefundables(); err == nil {
log.Printf("%#v", refundables)
}
{{#include ../../snippets/go/receive_onchain.go:list-refundables}}
```
</section>
@@ -341,14 +334,7 @@ except Exception as error:
<section>
```go
if refundables, err := sdk.ListRefundables(); err == nil {
destinationAddress := "..."
satPerVbyte := uint32(5)
if result, err := sdk.Refund(refundables[0].BitcoinAddress, destinationAddress, satPerVbyte); err == nil {
log.Printf("%v", result)
}
}
{{#include ../../snippets/go/receive_onchain.go:execute-refund}}
```
</section>
@@ -432,10 +418,7 @@ except Exception as error:
<section>
```go
amountMsat := uint64(10000)
if channelFees, err := sdk.OpenChannelFee(breez_sdk.OpenChannelFeeRequest{AmountMsat: amountMsat}); err == nil {
log.Printf("%#v", channelFees)
}
{{#include ../../snippets/go/receive_onchain.go:get-channel-opening-fees}}
```
</section>

View File

@@ -76,13 +76,7 @@ except Exception as error:
<section>
```go
receivePaymentRequest := breez_sdk.ReceivePaymentRequest{
AmountMsat: 3_000_000,
Description: "Invoice for 3000 sats",
}
if receivePaymentResponse, err := sdk.ReceivePayment(receivePaymentRequest); err == nil {
log.Printf("%#v", receivePaymentResponse)
}
{{#include ../../snippets/go/receive_payment.go:receive-payment}}
```
</section>

View File

@@ -74,13 +74,7 @@ except Exception as error:
<section>
```go
sendAmountSat := uint64(50000)
reverseSwapFeesRequest := breez_sdk.ReverseSwapFeesRequest{
SendAmountSat: &sendAmountSat,
}
if currentFees, err := sdk.FetchReverseSwapFees(reverseSwapFeesRequest); err == nil {
log.Printf("Total estimated fees for reverse swap: %v", currentFees.TotalEstimatedFees)
}
{{#include ../../snippets/go/send_onchain.go:estimate-current-reverse-swap-total-fees}}
```
</section>
@@ -155,8 +149,7 @@ print("Maximum amount, in sats: ", current_fees.max)
<section>
```go
log.Printf("Minimum amount, in sats: %v", currentFees.Min)
log.Printf("Maximum amount, in sats: %v", currentFees.Max)
{{#include ../../snippets/go/send_onchain.go:get-current-reverse-swap-min-max}}
```
</section>
@@ -251,14 +244,7 @@ except Exception as error:
<section>
```go
destinationAddress := "bc1.."
sendAmountSat := uint64(50000)
satPerVbyte := uint64(5)
if currentFees, err := sdk.FetchReverseSwapFees(breez_sdk.ReverseSwapFeesRequest{SendAmountSat: &sendAmountSat}); err == nil {
if reverseSwapInfo, err := sdk.SendOnchain(sendAmountSat, destinationAddress, currentFees.FeesHash, satPerVbyte); err == nil {
log.Printf("%#v", reverseSwapInfo)
}
}
{{#include ../../snippets/go/send_onchain.go:start-reverse-swap}}
```
</section>
@@ -339,11 +325,7 @@ except Exception as error:
<section>
```go
if swaps, err := sdk.InProgressReverseSwaps(); err == nil {
for _, swap := range swaps {
log.Printf("Reverse swap %v in progress, status is %v", swap.Id, swap.Status)
}
}
{{#include ../../snippets/go/send_onchain.go:check-reverse-swaps-status}}
```
</section>

View File

@@ -78,17 +78,7 @@ except Exception as error:
<section>
```go
bolt11 := "bolt11 invoice"
// 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'.
amountMsat := uint64(3000000)
sendPaymentRequest := breez_sdk.SendPaymentRequest{
Bolt11: bolt11,
AmountMsat: amountMsat,
}
if response, err := sdk.SendPayment(sendPaymentRequest); err == nil {
log.Printf("%#v", response)
}
{{#include ../../snippets/go/send_payment.go:send-payment}}
```
</section>

View File

@@ -76,13 +76,7 @@ except Exception as error:
<section>
```go
sendSpontaneousPaymentRequest := breez_sdk.SendSpontaneousPaymentRequest{
NodeId: "...",
AmountMsat: uint64(3000000),
}
if response, err := sdk.SendSpontaneousPayment(sendSpontaneousPaymentRequest); err == nil {
log.Printf("%#v", response)
}
{{#include ../../snippets/go/send_spontaneous_payment.go:send-spontaneous-payment}}
```
</section>

View File

@@ -75,10 +75,7 @@ except Exception as error:
<section>
```go
workingDir := "<working directory>"
if staticBackupResponse, err := breez_sdk.StaticBackup(breez_sdk.StaticBackupRequest{WorkingDir: workingDir}); err == nil {
log.Printf("%#v", staticBackupResponse)
}
{{#include ../../snippets/go/static_channel_backup.go:static-channel-backup}}
```
</section>