mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-17 05:44:20 +01:00
Add max_reverse_swap_amount docs
This commit is contained in:
@@ -28,6 +28,22 @@ public class SendOnchainSnippets
|
||||
// ANCHOR_END: get-current-reverse-swap-min-max
|
||||
}
|
||||
|
||||
public void MaxReverseSwapAmount(BlockingBreezServices sdk)
|
||||
{
|
||||
// ANCHOR: max-reverse-swap-amount
|
||||
try
|
||||
{
|
||||
var maxAmountResponse = sdk.MaxReverseSwapAmount();
|
||||
Console.WriteLine(
|
||||
$"Max reverse swap amount {maxAmountResponse.totalSat}");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Handle error
|
||||
}
|
||||
// ANCHOR_END: max-reverse-swap-amount
|
||||
}
|
||||
|
||||
public void StartReverseSwap(BlockingBreezServices sdk, ReverseSwapPairInfo currentFees, uint feeRate)
|
||||
{
|
||||
// ANCHOR: start-reverse-swap
|
||||
|
||||
@@ -17,6 +17,14 @@ void listCurrentFees({required ReverseSwapPairInfo currentFees}) {
|
||||
// ANCHOR_END: get-current-reverse-swap-min-max
|
||||
}
|
||||
|
||||
Future<MaxReverseSwapAmountResponse> maxReverseSwapAmount() async {
|
||||
// ANCHOR: max-reverse-swap-amount
|
||||
MaxReverseSwapAmountResponse maxAmount = await BreezSDK().maxReverseSwapAmount();
|
||||
print("Max reverse swap amount: ${maxAmount.totalSat}");
|
||||
// ANCHOR_END: max-reverse-swap-amount
|
||||
return maxAmount;
|
||||
}
|
||||
|
||||
Future<SendOnchainResponse> startReverseSwap({
|
||||
required int amountSat,
|
||||
required String onchainRecipientAddress,
|
||||
|
||||
@@ -25,6 +25,14 @@ func ListCurrentFees(currentFees breez_sdk.ReverseSwapPairInfo) {
|
||||
// ANCHOR_END: get-current-reverse-swap-min-max
|
||||
}
|
||||
|
||||
func MaxReverseSwapAmount() {
|
||||
// ANCHOR: max-reverse-swap-amount
|
||||
if maxAmount, err := sdk.MaxReverseSwapAmount(); err == nil {
|
||||
log.Printf("Max reverse swap amount: %v", maxAmount.TotalSat)
|
||||
}
|
||||
// ANCHOR_END: max-reverse-swap-amount
|
||||
}
|
||||
|
||||
func StartReverseSwap() {
|
||||
// ANCHOR: start-reverse-swap
|
||||
destinationAddress := "bc1.."
|
||||
|
||||
@@ -20,6 +20,17 @@ class SendOnchain {
|
||||
// ANCHOR_END: get-current-reverse-swap-min-max
|
||||
}
|
||||
|
||||
fun max_reverse_swap_amount(sdk: BlockingBreezServices) {
|
||||
// ANCHOR: max-reverse-swap-amount
|
||||
try {
|
||||
val maxAmount = sdk.maxReverseSwapAmount()
|
||||
// Log.v("Breez", "Max reverse swap amount: ${maxAmount.totalSat}")
|
||||
} catch (e: Exception) {
|
||||
// handle error
|
||||
}
|
||||
// ANCHOR_END: max-reverse-swap-amount
|
||||
}
|
||||
|
||||
fun start_reverse_swap(sdk: BlockingBreezServices, fees: ReverseSwapPairInfo) {
|
||||
// ANCHOR: start-reverse-swap
|
||||
val address = "bc1.."
|
||||
|
||||
@@ -18,6 +18,17 @@ def list_current_fees(current_fees):
|
||||
print("Maximum amount, in sats: ", current_fees.max)
|
||||
# ANCHOR_END: get-current-reverse-swap-min-max
|
||||
|
||||
def max_reverse_swap_amount(sdk_services):
|
||||
try:
|
||||
# ANCHOR: max-reverse-swap-amount
|
||||
max_amount = sdk_services.max_reverse_swap_amount()
|
||||
print("Max reverse swap amount: ", max_amount.totalSat)
|
||||
# ANCHOR_END: max-reverse-swap-amount
|
||||
return max_amount
|
||||
except Exception as error:
|
||||
print(error)
|
||||
raise
|
||||
|
||||
def start_reverse_swap(sdk_services, current_fees,fee_rate):
|
||||
# ANCHOR: start-reverse-swap
|
||||
destination_address = "bc1.."
|
||||
|
||||
@@ -1,49 +1,60 @@
|
||||
import {
|
||||
type ReverseSwapPairInfo,
|
||||
fetchReverseSwapFees,
|
||||
inProgressReverseSwaps,
|
||||
sendOnchain
|
||||
type ReverseSwapPairInfo,
|
||||
fetchReverseSwapFees,
|
||||
inProgressReverseSwaps,
|
||||
sendOnchain
|
||||
} from '@breeztech/react-native-breez-sdk'
|
||||
|
||||
const exampleFetchReverseSwapFees = async () => {
|
||||
// ANCHOR: estimate-current-reverse-swap-total-fees
|
||||
const currentFees = await fetchReverseSwapFees({ sendAmountSat: 50000 })
|
||||
// ANCHOR: estimate-current-reverse-swap-total-fees
|
||||
const currentFees = await fetchReverseSwapFees({ sendAmountSat: 50000 })
|
||||
|
||||
console.log(
|
||||
console.log(
|
||||
`Total estimated fees for reverse swap: ${currentFees.totalEstimatedFees}`
|
||||
)
|
||||
// ANCHOR_END: estimate-current-reverse-swap-total-fees
|
||||
)
|
||||
// ANCHOR_END: estimate-current-reverse-swap-total-fees
|
||||
}
|
||||
|
||||
const exampleListCurrentFees = (currentFees: ReverseSwapPairInfo) => {
|
||||
// ANCHOR: get-current-reverse-swap-min-max
|
||||
console.log(`Minimum amount, in sats: ${currentFees.min}`)
|
||||
console.log(`Maximum amount, in sats: ${currentFees.max}`)
|
||||
// ANCHOR_END: get-current-reverse-swap-min-max
|
||||
// ANCHOR: get-current-reverse-swap-min-max
|
||||
console.log(`Minimum amount, in sats: ${currentFees.min}`)
|
||||
console.log(`Maximum amount, in sats: ${currentFees.max}`)
|
||||
// ANCHOR_END: get-current-reverse-swap-min-max
|
||||
}
|
||||
|
||||
const exampleSendOnchain = async (currentFees: ReverseSwapPairInfo) => {
|
||||
// ANCHOR: start-reverse-swap
|
||||
const onchainRecipientAddress = 'bc1..'
|
||||
const amountSat = currentFees.min
|
||||
const satPerVbyte = 5
|
||||
const maxReverseSwapAmount = async () => {
|
||||
// ANCHOR: max-reverse-swap-amount
|
||||
const maxAmount = await maxReverseSwapAmount()
|
||||
|
||||
const reverseSwapInfo = await sendOnchain({
|
||||
amountSat,
|
||||
onchainRecipientAddress,
|
||||
pairHash: currentFees.feesHash,
|
||||
satPerVbyte
|
||||
})
|
||||
// ANCHOR_END: start-reverse-swap
|
||||
console.log(
|
||||
`Max reverse swap amount: ${maxAmount.totalSat}`
|
||||
)
|
||||
// ANCHOR_END: max-reverse-swap-amount
|
||||
}
|
||||
|
||||
|
||||
const exampleSendOnchain = async (currentFees: ReverseSwapPairInfo) => {
|
||||
// ANCHOR: start-reverse-swap
|
||||
const onchainRecipientAddress = 'bc1..'
|
||||
const amountSat = currentFees.min
|
||||
const satPerVbyte = 5
|
||||
|
||||
const reverseSwapInfo = await sendOnchain({
|
||||
amountSat,
|
||||
onchainRecipientAddress,
|
||||
pairHash: currentFees.feesHash,
|
||||
satPerVbyte
|
||||
})
|
||||
// ANCHOR_END: start-reverse-swap
|
||||
}
|
||||
|
||||
const exampleInProgressReverseSwaps = async () => {
|
||||
// ANCHOR: check-reverse-swaps-status
|
||||
const swaps = await inProgressReverseSwaps()
|
||||
for (const swap of swaps) {
|
||||
console.log(
|
||||
// ANCHOR: check-reverse-swaps-status
|
||||
const swaps = await inProgressReverseSwaps()
|
||||
for (const swap of swaps) {
|
||||
console.log(
|
||||
`Reverse swap ${swap.id} in progress, status is ${swap.status}`
|
||||
)
|
||||
}
|
||||
// ANCHOR_END: check-reverse-swaps-status
|
||||
)
|
||||
}
|
||||
// ANCHOR_END: check-reverse-swaps-status
|
||||
}
|
||||
|
||||
@@ -30,6 +30,21 @@ async fn list_current_fees(current_fees: ReverseSwapPairInfo) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn max_reverse_swap_amount(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: max-reverse-swap-amount
|
||||
let max_amount = sdk
|
||||
.max_reverse_swap_amount()
|
||||
.await?;
|
||||
|
||||
info!(
|
||||
"Max reverse swap amount: {:?}",
|
||||
max_amount.totalSat
|
||||
);
|
||||
// ANCHOR_END: max-reverse-swap-amount
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn start_reverse_swap(
|
||||
sdk: Arc<BreezServices>,
|
||||
current_fees: ReverseSwapPairInfo,
|
||||
|
||||
@@ -24,6 +24,14 @@ func ListCurrentFees(currentFees: ReverseSwapPairInfo) {
|
||||
// ANCHOR_END: get-current-reverse-swap-min-max
|
||||
}
|
||||
|
||||
func MaxReverseSwapAmount(sdk: BlockingBreezServices) -> MaxReverseSwapAmountResponse? {
|
||||
// ANCHOR: max-reverse-swap-amount
|
||||
let maxAmount = try? sdk.MaxReverseSwapAmount()
|
||||
print("Max reverse swap amount: \(String(describing: maxAmount?.totalSat))")
|
||||
// ANCHOR_END: max-reverse-swap-amount
|
||||
return maxAmount
|
||||
}
|
||||
|
||||
func StartReverseSwap(sdk: BlockingBreezServices, currentFees: ReverseSwapPairInfo) -> SendOnchainResponse? {
|
||||
// ANCHOR: start-reverse-swap
|
||||
let destinationAddress = "bc1.."
|
||||
|
||||
@@ -74,7 +74,7 @@ The reverse swap will involve two on-chain transactions, for which the mining fe
|
||||
automatically once the process is started, but the last two values above are these estimates to help you get a picture
|
||||
of the total costs.
|
||||
|
||||
Fetching the fees also tells you what is the range of amounts you can send:
|
||||
Fetching the fees also tells you what is the range of amounts the service allows:
|
||||
|
||||
<custom-tabs category="lang">
|
||||
<div slot="title">Rust</div>
|
||||
@@ -142,7 +142,75 @@ Fetching the fees also tells you what is the range of amounts you can send:
|
||||
</section>
|
||||
</custom-tabs>
|
||||
|
||||
Once you checked the fees are acceptable, you can start the reverse swap:
|
||||
In case you want to drain your channels you need to know the maximum sendable amount to an on-chain address:
|
||||
|
||||
<custom-tabs category="lang">
|
||||
<div slot="title">Rust</div>
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
{{#include ../../snippets/rust/src/send_onchain.rs:max-reverse-swap-amount}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Swift</div>
|
||||
<section>
|
||||
|
||||
```swift,ignore
|
||||
{{#include ../../snippets/swift/BreezSDKExamples/Sources/SendOnchain.swift:max-reverse-swap-amount}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Kotlin</div>
|
||||
<section>
|
||||
|
||||
```kotlin,ignore
|
||||
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendOnchain.kt:max-reverse-swap-amount}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">React Native</div>
|
||||
<section>
|
||||
|
||||
```typescript
|
||||
{{#include ../../snippets/react-native/send_onchain.ts:max-reverse-swap-amount}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Dart</div>
|
||||
<section>
|
||||
|
||||
```dart,ignore
|
||||
{{#include ../../snippets/dart_snippets/lib/send_onchain.dart:max-reverse-swap-amount}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Python</div>
|
||||
<section>
|
||||
|
||||
```python,ignore
|
||||
{{#include ../../snippets/python/src/send_onchain.py:max-reverse-swap-amount}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Go</div>
|
||||
<section>
|
||||
|
||||
```go,ignore
|
||||
{{#include ../../snippets/go/send_onchain.go:max-reverse-swap-amount}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">C#</div>
|
||||
<section>
|
||||
|
||||
```cs,ignore
|
||||
{{#include ../../snippets/csharp/SendOnchain.cs:max-reverse-swap-amount}}
|
||||
```
|
||||
</section>
|
||||
</custom-tabs>
|
||||
|
||||
Once you decided about the amount and checked the fees are acceptable, you can start the reverse swap:
|
||||
|
||||
<custom-tabs category="lang">
|
||||
<div slot="title">Rust</div>
|
||||
|
||||
Reference in New Issue
Block a user