From 78b91e93738aa1a94874ffa0287199c56d2e8f56 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Tue, 12 Dec 2023 17:29:31 +0200 Subject: [PATCH 1/4] Document swap limits --- snippets/csharp/ReceiveOnchain.cs | 133 +++++++++--------- .../dart_snippets/lib/receive_onchain.dart | 2 + snippets/go/receive_onchain.go | 3 + .../example/kotlinmpplib/ReceiveOnchain.kt | 2 + snippets/python/src/receive_onchain.py | 2 + snippets/react-native/receive_onchain.ts | 2 + snippets/rust/src/receive_onchain.rs | 2 + .../Sources/ReceiveOnchain.swift | 2 + src/guide/receive_onchain.md | 2 + 9 files changed, 84 insertions(+), 66 deletions(-) diff --git a/snippets/csharp/ReceiveOnchain.cs b/snippets/csharp/ReceiveOnchain.cs index c987847..8ad18dd 100644 --- a/snippets/csharp/ReceiveOnchain.cs +++ b/snippets/csharp/ReceiveOnchain.cs @@ -2,83 +2,84 @@ using Breez.Sdk; public class ReceiveOnchainSnippets { - public void ReceiveOnchain(BlockingBreezServices sdk) + public void ReceiveOnchain(BlockingBreezServices sdk) + { + // ANCHOR: generate-receive-onchain-address + try { - // 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 + var swapInfo = sdk.ReceiveOnchain(new ReceiveOnchainRequest()); + // Send your funds to the below bitcoin address + var address = swapInfo.bitcoinAddress; + Console.WriteLine($"Minimum amount allowed to deposit in sats: {swapInfo.minAllowedDeposit}"); + Console.WriteLine($"Maximum amount allowed to deposit in sats: {swapInfo.maxAllowedDeposit}"); } - - public void GetInProgressSwap(BlockingBreezServices sdk) + catch (Exception) { - // ANCHOR: in-progress-swap - try - { - var swapInfo = sdk.InProgressSwap(); - } - catch (Exception) - { - // Handle error - } - // ANCHOR_END: in-progress-swap + // Handle error } + // ANCHOR_END: generate-receive-onchain-address + } - public void ListRefundables(BlockingBreezServices sdk) + public void GetInProgressSwap(BlockingBreezServices sdk) + { + // ANCHOR: in-progress-swap + try { - // ANCHOR: list-refundables - try - { - var refundables = sdk.ListRefundables(); - } - catch (Exception) - { - // Handle error - } - // ANCHOR_END: list-refundables + var swapInfo = sdk.InProgressSwap(); } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: in-progress-swap + } - public void ExecuteRefund(BlockingBreezServices sdk, uint refundTxFeeRate, SwapInfo refundable) + public void ListRefundables(BlockingBreezServices sdk) + { + // ANCHOR: list-refundables + try { - // 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 + var refundables = sdk.ListRefundables(); } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: list-refundables + } - public void GetChannelOpeningFees(BlockingBreezServices sdk, ulong amountMsat) + public void ExecuteRefund(BlockingBreezServices sdk, uint refundTxFeeRate, SwapInfo refundable) + { + // ANCHOR: execute-refund + var destinationAddress = "..."; + var satPerVbyte = refundTxFeeRate; + try { - // ANCHOR: get-channel-opening-fees - try - { - var channelFees = sdk.OpenChannelFee( - new OpenChannelFeeRequest(amountMsat)); - } - catch (Exception) - { - // Handle error - } - // ANCHOR_END: get-channel-opening-fees + 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/dart_snippets/lib/receive_onchain.dart b/snippets/dart_snippets/lib/receive_onchain.dart index 7511190..1cbc1ba 100644 --- a/snippets/dart_snippets/lib/receive_onchain.dart +++ b/snippets/dart_snippets/lib/receive_onchain.dart @@ -9,6 +9,8 @@ Future generateReceiveOnchainAddress() async { // Send your funds to the below bitcoin address String address = swapInfo.bitcoinAddress; print(address); + print("Minimum amount allowed to deposit in sats: ${swapInfo.minAllowedDeposit}"); + print("Maximum amount allowed to deposit in sats: ${swapInfo.maxAllowedDeposit}"); return swapInfo; // ANCHOR_END: generate-receive-onchain-address } diff --git a/snippets/go/receive_onchain.go b/snippets/go/receive_onchain.go index cbff426..9e0f229 100644 --- a/snippets/go/receive_onchain.go +++ b/snippets/go/receive_onchain.go @@ -12,6 +12,9 @@ func GenerateReceiveOnchainAddress() { // Send your funds to the below bitcoin address address := swapInfo.BitcoinAddress log.Printf("%v", address) + + log.Printf("Minimum amount allowed to deposit in sats: %v", swapInfo.minAllowedDeposit) + log.Printf("Maximum amount allowed to deposit in sats: %v", swapInfo.maxAllowedDeposit) } // ANCHOR_END: generate-receive-onchain-address } diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt index aaf3f45..7d6c6e6 100644 --- a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt @@ -8,6 +8,8 @@ class ReceiveOnchain { val swapInfo = sdk.receiveOnchain(ReceiveOnchainRequest()) // Send your funds to the bellow bitcoin address val address = swapInfo.bitcoinAddress + // Log.v("Breez", "Minimum amount allowed to deposit in sats: ${swapInfo.minAllowedDeposit}") + // Log.v("Breez", "Maximum amount allowed to deposit in sats: ${swapInfo.maxAllowedDeposit}") } catch (e: Exception) { // handle error } diff --git a/snippets/python/src/receive_onchain.py b/snippets/python/src/receive_onchain.py index 57ec2a8..fd4042a 100644 --- a/snippets/python/src/receive_onchain.py +++ b/snippets/python/src/receive_onchain.py @@ -7,6 +7,8 @@ def generate_receive_onchain_address(sdk_services): # Send your funds to the below bitcoin address address = swap_info.bitcoin_address + print("Minimum amount allowed to deposit in sats: {}", swap_info.min_allowed_deposit); + print("Maximum amount allowed to deposit in sats: {}", swap_info.max_allowed_deposit); # ANCHOR_END: generate-receive-onchain-address except Exception as error: print(error) diff --git a/snippets/react-native/receive_onchain.ts b/snippets/react-native/receive_onchain.ts index 37ad498..03e8e9d 100644 --- a/snippets/react-native/receive_onchain.ts +++ b/snippets/react-native/receive_onchain.ts @@ -12,6 +12,8 @@ const exampleReceiveOnchain = async () => { // Send your funds to the below bitcoin address const address = swapInfo.bitcoinAddress + console.log("Minimum amount allowed to deposit in sats: {}", swapInfo.minAllowedDeposit); + console.log("Maximum amount allowed to deposit in sats: {}", swapInfo.maxAllowedDeposit); // ANCHOR_END: generate-receive-onchain-address } diff --git a/snippets/rust/src/receive_onchain.rs b/snippets/rust/src/receive_onchain.rs index e689019..7ce00e3 100644 --- a/snippets/rust/src/receive_onchain.rs +++ b/snippets/rust/src/receive_onchain.rs @@ -11,6 +11,8 @@ async fn generate_receive_onchain_address(sdk: Arc) -> Result<()> // Send your funds to the below bitcoin address let address = swap_info.bitcoin_address; + info!("Minimum amount allowed to deposit in sats: {}", swap_info.min_allowed_deposit); + info!("Maximum amount allowed to deposit in sats: {}", swap_info.max_allowed_deposit); // ANCHOR_END: generate-receive-onchain-address Ok(()) diff --git a/snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift b/snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift index ebffdc9..9c9d1f9 100644 --- a/snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift +++ b/snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift @@ -14,6 +14,8 @@ func generateReceiveOnchainAddress(sdk: BlockingBreezServices) -> String? { // Send your funds to the bellow bitcoin address let address = swapInfo?.bitcoinAddress + print("Minimum amount allowed to deposit in sats: \(swapInfo.minAllowedDeposit)") + print("Maximum amount allowed to deposit in sats: \(swapInfo.maxAllowedDeposit)") // ANCHOR_END: generate-receive-onchain-address return address diff --git a/src/guide/receive_onchain.md b/src/guide/receive_onchain.md index 47092f1..d3dcaaa 100644 --- a/src/guide/receive_onchain.md +++ b/src/guide/receive_onchain.md @@ -72,6 +72,8 @@ In order to receive funds you first have to be connected to an [LSP](connecting_ +It's important to be aware that the swap information provided includes maximum and minimum limits. Users must be informed of these limits because if the amount transferred to the swap address falls outside this valid range, the funds will not be successfully received via lightning. In such cases, a refund will be necessary. + ## Get the in-progress Swap Once you've sent the funds to the above address, the SDK will monitor this address for unspent confirmed outputs and use a trustless submarine swap to receive these into your Lightning node. You can always monitor the status of the current in-progress swap using the following code: From c1a70165a75afd147fe21271b5777eb330862272 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Tue, 12 Dec 2023 18:11:22 +0200 Subject: [PATCH 2/4] fix snippets --- snippets/go/receive_onchain.go | 4 ++-- snippets/python/src/receive_onchain.py | 4 ++-- snippets/react-native/receive_onchain.ts | 4 ++-- snippets/rust/src/receive_onchain.rs | 1 + snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/snippets/go/receive_onchain.go b/snippets/go/receive_onchain.go index 9e0f229..a8941a4 100644 --- a/snippets/go/receive_onchain.go +++ b/snippets/go/receive_onchain.go @@ -13,8 +13,8 @@ func GenerateReceiveOnchainAddress() { address := swapInfo.BitcoinAddress log.Printf("%v", address) - log.Printf("Minimum amount allowed to deposit in sats: %v", swapInfo.minAllowedDeposit) - log.Printf("Maximum amount allowed to deposit in sats: %v", swapInfo.maxAllowedDeposit) + log.Printf("Minimum amount allowed to deposit in sats: %v", swapInfo.MinAllowedDeposit) + log.Printf("Maximum amount allowed to deposit in sats: %v", swapInfo.MaxAllowedDeposit) } // ANCHOR_END: generate-receive-onchain-address } diff --git a/snippets/python/src/receive_onchain.py b/snippets/python/src/receive_onchain.py index fd4042a..34ba3b2 100644 --- a/snippets/python/src/receive_onchain.py +++ b/snippets/python/src/receive_onchain.py @@ -7,8 +7,8 @@ def generate_receive_onchain_address(sdk_services): # Send your funds to the below bitcoin address address = swap_info.bitcoin_address - print("Minimum amount allowed to deposit in sats: {}", swap_info.min_allowed_deposit); - print("Maximum amount allowed to deposit in sats: {}", swap_info.max_allowed_deposit); + print("Minimum amount allowed to deposit in sats: {}", swap_info.min_allowed_deposit) + print("Maximum amount allowed to deposit in sats: {}", swap_info.max_allowed_deposit) # ANCHOR_END: generate-receive-onchain-address except Exception as error: print(error) diff --git a/snippets/react-native/receive_onchain.ts b/snippets/react-native/receive_onchain.ts index 03e8e9d..6272bff 100644 --- a/snippets/react-native/receive_onchain.ts +++ b/snippets/react-native/receive_onchain.ts @@ -12,8 +12,8 @@ const exampleReceiveOnchain = async () => { // Send your funds to the below bitcoin address const address = swapInfo.bitcoinAddress - console.log("Minimum amount allowed to deposit in sats: {}", swapInfo.minAllowedDeposit); - console.log("Maximum amount allowed to deposit in sats: {}", swapInfo.maxAllowedDeposit); + console.log(`Minimum amount allowed to deposit in sats: {}`, swapInfo.minAllowedDeposit) + console.log(`Maximum amount allowed to deposit in sats: {}`, swapInfo.maxAllowedDeposit) // ANCHOR_END: generate-receive-onchain-address } diff --git a/snippets/rust/src/receive_onchain.rs b/snippets/rust/src/receive_onchain.rs index 7ce00e3..452c321 100644 --- a/snippets/rust/src/receive_onchain.rs +++ b/snippets/rust/src/receive_onchain.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use anyhow::Result; use breez_sdk_core::*; +use log::info; async fn generate_receive_onchain_address(sdk: Arc) -> Result<()> { // ANCHOR: generate-receive-onchain-address diff --git a/snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift b/snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift index 9c9d1f9..1e553ae 100644 --- a/snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift +++ b/snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift @@ -14,8 +14,8 @@ func generateReceiveOnchainAddress(sdk: BlockingBreezServices) -> String? { // Send your funds to the bellow bitcoin address let address = swapInfo?.bitcoinAddress - print("Minimum amount allowed to deposit in sats: \(swapInfo.minAllowedDeposit)") - print("Maximum amount allowed to deposit in sats: \(swapInfo.maxAllowedDeposit)") + print("Minimum amount allowed to deposit in sats: \(swapInfo!.minAllowedDeposit)") + print("Maximum amount allowed to deposit in sats: \(swapInfo!.maxAllowedDeposit)") // ANCHOR_END: generate-receive-onchain-address return address From 9c78f98320a40037442875c634d515de62f56a3a Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Tue, 12 Dec 2023 18:24:29 +0200 Subject: [PATCH 3/4] fix react native snippet --- snippets/react-native/receive_onchain.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/react-native/receive_onchain.ts b/snippets/react-native/receive_onchain.ts index 6272bff..79a6ef7 100644 --- a/snippets/react-native/receive_onchain.ts +++ b/snippets/react-native/receive_onchain.ts @@ -12,8 +12,8 @@ const exampleReceiveOnchain = async () => { // Send your funds to the below bitcoin address const address = swapInfo.bitcoinAddress - console.log(`Minimum amount allowed to deposit in sats: {}`, swapInfo.minAllowedDeposit) - console.log(`Maximum amount allowed to deposit in sats: {}`, swapInfo.maxAllowedDeposit) + console.log(`Minimum amount allowed to deposit in sats: ${swapInfo.minAllowedDeposit}`) + console.log(`Maximum amount allowed to deposit in sats: ${swapInfo.maxAllowedDeposit}`) // ANCHOR_END: generate-receive-onchain-address } From db739dd3e833d86b259a4cac644b3dcbe24cd9da Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Wed, 13 Dec 2023 11:04:22 +0200 Subject: [PATCH 4/4] fix formatting --- snippets/csharp/ReceiveOnchain.cs | 132 ++++++++++++------------- snippets/python/src/receive_onchain.py | 4 +- 2 files changed, 68 insertions(+), 68 deletions(-) diff --git a/snippets/csharp/ReceiveOnchain.cs b/snippets/csharp/ReceiveOnchain.cs index 8ad18dd..5110ad1 100644 --- a/snippets/csharp/ReceiveOnchain.cs +++ b/snippets/csharp/ReceiveOnchain.cs @@ -2,84 +2,84 @@ using Breez.Sdk; public class ReceiveOnchainSnippets { - public void ReceiveOnchain(BlockingBreezServices sdk) - { - // ANCHOR: generate-receive-onchain-address - try + public void ReceiveOnchain(BlockingBreezServices sdk) { - var swapInfo = sdk.ReceiveOnchain(new ReceiveOnchainRequest()); - // Send your funds to the below bitcoin address - var address = swapInfo.bitcoinAddress; - Console.WriteLine($"Minimum amount allowed to deposit in sats: {swapInfo.minAllowedDeposit}"); - Console.WriteLine($"Maximum amount allowed to deposit in sats: {swapInfo.maxAllowedDeposit}"); + // ANCHOR: generate-receive-onchain-address + try + { + var swapInfo = sdk.ReceiveOnchain(new ReceiveOnchainRequest()); + // Send your funds to the below bitcoin address + var address = swapInfo.bitcoinAddress; + Console.WriteLine($"Minimum amount allowed to deposit in sats: {swapInfo.minAllowedDeposit}"); + Console.WriteLine($"Maximum amount allowed to deposit in sats: {swapInfo.maxAllowedDeposit}"); + } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: generate-receive-onchain-address } - catch (Exception) - { - // Handle error - } - // ANCHOR_END: generate-receive-onchain-address - } - public void GetInProgressSwap(BlockingBreezServices sdk) - { - // ANCHOR: in-progress-swap - try + public void GetInProgressSwap(BlockingBreezServices sdk) { - var swapInfo = sdk.InProgressSwap(); + // ANCHOR: in-progress-swap + try + { + var swapInfo = sdk.InProgressSwap(); + } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: in-progress-swap } - catch (Exception) - { - // Handle error - } - // ANCHOR_END: in-progress-swap - } - public void ListRefundables(BlockingBreezServices sdk) - { - // ANCHOR: list-refundables - try + public void ListRefundables(BlockingBreezServices sdk) { - var refundables = sdk.ListRefundables(); + // ANCHOR: list-refundables + try + { + var refundables = sdk.ListRefundables(); + } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: list-refundables } - 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 + public void ExecuteRefund(BlockingBreezServices sdk, uint refundTxFeeRate, SwapInfo refundable) { - var result = sdk.Refund( - new RefundRequest( - refundable.bitcoinAddress, - destinationAddress, - satPerVbyte)); + // 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 } - catch (Exception) - { - // Handle error - } - // ANCHOR_END: execute-refund - } - public void GetChannelOpeningFees(BlockingBreezServices sdk, ulong amountMsat) - { - // ANCHOR: get-channel-opening-fees - try + public void GetChannelOpeningFees(BlockingBreezServices sdk, ulong amountMsat) { - var channelFees = sdk.OpenChannelFee( - new OpenChannelFeeRequest(amountMsat)); + // ANCHOR: get-channel-opening-fees + try + { + var channelFees = sdk.OpenChannelFee( + new OpenChannelFeeRequest(amountMsat)); + } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: get-channel-opening-fees } - catch (Exception) - { - // Handle error - } - // ANCHOR_END: get-channel-opening-fees - } } diff --git a/snippets/python/src/receive_onchain.py b/snippets/python/src/receive_onchain.py index 34ba3b2..4922e06 100644 --- a/snippets/python/src/receive_onchain.py +++ b/snippets/python/src/receive_onchain.py @@ -7,8 +7,8 @@ def generate_receive_onchain_address(sdk_services): # Send your funds to the below bitcoin address address = swap_info.bitcoin_address - print("Minimum amount allowed to deposit in sats: {}", swap_info.min_allowed_deposit) - print("Maximum amount allowed to deposit in sats: {}", swap_info.max_allowed_deposit) + print("Minimum amount allowed to deposit in sats:", swap_info.min_allowed_deposit) + print("Maximum amount allowed to deposit in sats:", swap_info.max_allowed_deposit) # ANCHOR_END: generate-receive-onchain-address except Exception as error: print(error)