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.."
|
||||
|
||||
Reference in New Issue
Block a user