diff --git a/snippets/go/.gitignore b/snippets/go/.gitignore new file mode 100644 index 0000000..8867f65 --- /dev/null +++ b/snippets/go/.gitignore @@ -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 +!**/ \ No newline at end of file diff --git a/snippets/go/buy_btc.go b/snippets/go/buy_btc.go new file mode 100644 index 0000000..4e2714d --- /dev/null +++ b/snippets/go/buy_btc.go @@ -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 +} diff --git a/snippets/go/connecting_lsp.go b/snippets/go/connecting_lsp.go new file mode 100644 index 0000000..852aff3 --- /dev/null +++ b/snippets/go/connecting_lsp.go @@ -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 +} diff --git a/snippets/go/fiat_currencies.go b/snippets/go/fiat_currencies.go new file mode 100644 index 0000000..28ee688 --- /dev/null +++ b/snippets/go/fiat_currencies.go @@ -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 +} diff --git a/snippets/go/getting_started.go b/snippets/go/getting_started.go new file mode 100644 index 0000000..062894e --- /dev/null +++ b/snippets/go/getting_started.go @@ -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("") + if err != nil { + log.Fatalf("MnemonicToSeed failed: %#v", err) + } + + inviteCode := "" + apiKey := "" + 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 +} diff --git a/snippets/go/go.mod b/snippets/go/go.mod new file mode 100644 index 0000000..1547ad9 --- /dev/null +++ b/snippets/go/go.mod @@ -0,0 +1,5 @@ +module main + +go 1.19 + +require github.com/breez/breez-sdk-go v0.2.7 diff --git a/snippets/go/list_payments.go b/snippets/go/list_payments.go new file mode 100644 index 0000000..e55c4e1 --- /dev/null +++ b/snippets/go/list_payments.go @@ -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 +} diff --git a/snippets/go/lnurl_auth.go b/snippets/go/lnurl_auth.go new file mode 100644 index 0000000..9ce0d84 --- /dev/null +++ b/snippets/go/lnurl_auth.go @@ -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 +} diff --git a/snippets/go/lnurl_pay.go b/snippets/go/lnurl_pay.go new file mode 100644 index 0000000..80a09ff --- /dev/null +++ b/snippets/go/lnurl_pay.go @@ -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 +} diff --git a/snippets/go/lnurl_withdraw.go b/snippets/go/lnurl_withdraw.go new file mode 100644 index 0000000..33cac29 --- /dev/null +++ b/snippets/go/lnurl_withdraw.go @@ -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 +} diff --git a/snippets/go/main.go b/snippets/go/main.go new file mode 100644 index 0000000..a2cc683 --- /dev/null +++ b/snippets/go/main.go @@ -0,0 +1,9 @@ +package example + +import ( + "github.com/breez/breez-sdk-go/breez_sdk" +) + +var sdk breez_sdk.BlockingBreezServices + +func main() {} diff --git a/snippets/go/receive_onchain.go b/snippets/go/receive_onchain.go new file mode 100644 index 0000000..cbff426 --- /dev/null +++ b/snippets/go/receive_onchain.go @@ -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 +} diff --git a/snippets/go/receive_payment.go b/snippets/go/receive_payment.go new file mode 100644 index 0000000..8733ab5 --- /dev/null +++ b/snippets/go/receive_payment.go @@ -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 +} diff --git a/snippets/go/send_onchain.go b/snippets/go/send_onchain.go new file mode 100644 index 0000000..a98fdd4 --- /dev/null +++ b/snippets/go/send_onchain.go @@ -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 +} diff --git a/snippets/go/send_payment.go b/snippets/go/send_payment.go new file mode 100644 index 0000000..3f3aeeb --- /dev/null +++ b/snippets/go/send_payment.go @@ -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 +} diff --git a/snippets/go/send_spontaneous_payment.go b/snippets/go/send_spontaneous_payment.go new file mode 100644 index 0000000..a4930b5 --- /dev/null +++ b/snippets/go/send_spontaneous_payment.go @@ -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 +} diff --git a/snippets/go/static_channel_backup.go b/snippets/go/static_channel_backup.go new file mode 100644 index 0000000..d2cf245 --- /dev/null +++ b/snippets/go/static_channel_backup.go @@ -0,0 +1,16 @@ +package example + +import ( + "log" + + "github.com/breez/breez-sdk-go/breez_sdk" +) + +func RetrieveBackupFiles() { + // ANCHOR: static-channel-backup + workingDir := "" + if staticBackupResponse, err := breez_sdk.StaticBackup(breez_sdk.StaticBackupRequest{WorkingDir: workingDir}); err == nil { + log.Printf("%#v", staticBackupResponse) + } + // ANCHOR_END: static-channel-backup +} diff --git a/src/guide/buy_btc.md b/src/guide/buy_btc.md index 4238db8..d9e6cfc 100644 --- a/src/guide/buy_btc.md +++ b/src/guide/buy_btc.md @@ -79,12 +79,7 @@ except Exception as error:
```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}} ```
diff --git a/src/guide/connecting_lsp.md b/src/guide/connecting_lsp.md index 73ccf46..3ce6517 100644 --- a/src/guide/connecting_lsp.md +++ b/src/guide/connecting_lsp.md @@ -74,12 +74,7 @@ except Exception as error:
```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}} ```
@@ -158,10 +153,7 @@ except Exception as error:
```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}} ```
diff --git a/src/guide/fiat_currencies.md b/src/guide/fiat_currencies.md index 8fe25a3..31fbf5e 100644 --- a/src/guide/fiat_currencies.md +++ b/src/guide/fiat_currencies.md @@ -55,9 +55,7 @@ except Exception as error:
```go -if fiatCurrencies, err := sdk.ListFiatCurrencies(); err == nil { - log.Printf("%#v", fiatCurrencies) -} +{{#include ../../snippets/go/fiat_currencies.go:list-fiat-currencies}} ```
@@ -125,9 +123,7 @@ except Exception as error:
```go -if fiatRates, err := sdk.FetchFiatRates(); err == nil { - log.Printf("%#v", fiatRates) -} +{{#include ../../snippets/go/fiat_currencies.go:fetch-fiat-rates}} ```
@@ -209,7 +205,7 @@ fun fiatCurrenciesAndRate(): Map = try {
```go -// TODO +{{#include ../../snippets/go/fiat_currencies.go:get-fiat-currencies-and-rates}} ```
diff --git a/src/guide/getting_started.md b/src/guide/getting_started.md index a212443..aa9c241 100644 --- a/src/guide/getting_started.md +++ b/src/guide/getting_started.md @@ -161,41 +161,8 @@ except Exception as error:
```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("") -if err != nil { - log.Fatalf("MnemonicToSeed failed: %#v", err) -} - -inviteCode := "" -apiKey := "" -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}} ```
@@ -280,10 +247,7 @@ except Exception as error:
```go -if nodeInfo, err := sdkServices.NodeInfo(); err != nil { - lnBalance := nodeInfo.ChannelsBalanceMsat - onchainBalance := nodeInfo.OnchainBalanceMsat -} +{{#include ../../snippets/go/getting_started.go:fetch-balance}} ```
diff --git a/src/guide/list_payments.md b/src/guide/list_payments.md index 0f161be..df6b663 100644 --- a/src/guide/list_payments.md +++ b/src/guide/list_payments.md @@ -66,9 +66,7 @@ except Exception as error:
```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}} ```
@@ -157,16 +155,7 @@ except Exception as error:
```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}} ```
diff --git a/src/guide/lnurl_auth.md b/src/guide/lnurl_auth.md index 83626e4..ee6ab6c 100644 --- a/src/guide/lnurl_auth.md +++ b/src/guide/lnurl_auth.md @@ -98,22 +98,7 @@ except Exception as error:
```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}} ```
diff --git a/src/guide/lnurl_pay.md b/src/guide/lnurl_pay.md index 6ddbf9b..31c558f 100644 --- a/src/guide/lnurl_pay.md +++ b/src/guide/lnurl_pay.md @@ -98,31 +98,7 @@ except Exception as error:
```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}} ```
diff --git a/src/guide/lnurl_withdraw.md b/src/guide/lnurl_withdraw.md index e0c3a61..65d6ab8 100644 --- a/src/guide/lnurl_withdraw.md +++ b/src/guide/lnurl_withdraw.md @@ -97,29 +97,7 @@ except Exception as error:
```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}} ```
diff --git a/src/guide/receive_onchain.md b/src/guide/receive_onchain.md index 134fd9f..f9f99e6 100644 --- a/src/guide/receive_onchain.md +++ b/src/guide/receive_onchain.md @@ -77,11 +77,7 @@ except Exception as error:
```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}} ```
@@ -160,9 +156,8 @@ except Exception as error:
```go -if swapInfo, err := sdk.InProgressSwap(); err == nil { - log.Printf("%#v", swapInfo) -} + +{{#include ../../snippets/go/receive_onchain.go:in-progress-swap}} ```
@@ -246,9 +241,7 @@ except Exception as error:
```go -if refundables, err := sdk.ListRefundables(); err == nil { - log.Printf("%#v", refundables) -} +{{#include ../../snippets/go/receive_onchain.go:list-refundables}} ```
@@ -341,14 +334,7 @@ except Exception as error:
```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}} ```
@@ -432,10 +418,7 @@ except Exception as error:
```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}} ```
diff --git a/src/guide/receive_payment.md b/src/guide/receive_payment.md index f7063e6..19c6e0e 100644 --- a/src/guide/receive_payment.md +++ b/src/guide/receive_payment.md @@ -76,13 +76,7 @@ except Exception as error:
```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}} ```
diff --git a/src/guide/send_onchain.md b/src/guide/send_onchain.md index 30aebe1..1e6fb47 100644 --- a/src/guide/send_onchain.md +++ b/src/guide/send_onchain.md @@ -74,13 +74,7 @@ except Exception as error:
```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}} ```
@@ -155,8 +149,7 @@ print("Maximum amount, in sats: ", current_fees.max)
```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}} ```
@@ -251,14 +244,7 @@ except Exception as error:
```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}} ```
@@ -339,11 +325,7 @@ except Exception as error:
```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}} ```
diff --git a/src/guide/send_payment.md b/src/guide/send_payment.md index 83b070f..6a63e4e 100644 --- a/src/guide/send_payment.md +++ b/src/guide/send_payment.md @@ -78,17 +78,7 @@ except Exception as error:
```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}} ```
diff --git a/src/guide/send_spontaneous_payment.md b/src/guide/send_spontaneous_payment.md index 874616b..22a84d1 100644 --- a/src/guide/send_spontaneous_payment.md +++ b/src/guide/send_spontaneous_payment.md @@ -76,13 +76,7 @@ except Exception as error:
```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}} ```
diff --git a/src/guide/static_channel_backup.md b/src/guide/static_channel_backup.md index 42dc287..cdca95c 100644 --- a/src/guide/static_channel_backup.md +++ b/src/guide/static_channel_backup.md @@ -75,10 +75,7 @@ except Exception as error:
```go -workingDir := "" -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}} ```