mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-18 06:14:21 +01:00
Switch types and pass comments by reference
This commit is contained in:
@@ -83,9 +83,9 @@ try {
|
||||
lnurlAuthUrl := "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
|
||||
|
||||
if input, err := breez_sdk.ParseInput(lnurlAuthUrl); err != nil {
|
||||
switch input.Type {
|
||||
switch inputType := input.(type) {
|
||||
case breez_sdk.InputTypeLnUrlAuth:
|
||||
if result, err := sdkServices.LnurlAuth(input.Data); err != nil {
|
||||
if result, err := sdkServices.LnurlAuth(inputType.Data); err != nil {
|
||||
if (result.Status === "ok") {
|
||||
log.Printf("Successfully authenticated")
|
||||
} else {
|
||||
|
||||
@@ -71,10 +71,11 @@ try {
|
||||
lnurlPayUrl := "lightning@address.com"
|
||||
|
||||
if input, err := breez_sdk.ParseInput(lnurlPayUrl); err != nil {
|
||||
switch input.Type {
|
||||
switch inputType := input.(type) {
|
||||
case breez_sdk.InputTypeLnUrlPay:
|
||||
amountsSats := input.MinSendable
|
||||
result, err := sdkServices.PayLnurl(input.Data, amountsSats, "comment")
|
||||
amountsSats := inputType.Data.MinSendable
|
||||
comment := "comment"
|
||||
result, err := sdkServices.PayLnurl(inputType.Data, amountsSats, &comment)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -69,11 +69,12 @@ try {
|
||||
// lnurlw://domain.com/lnurl-withdraw?key=val
|
||||
lnurlWithdrawUrl := "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"
|
||||
|
||||
if input, err := breez_sdk.ParseInput(lnurlAuthUrl); err != nil {
|
||||
switch input.Type {
|
||||
if input, err := breez_sdk.ParseInput(lnurlWithdrawUrl); err != nil {
|
||||
switch inputType := input.(type) {
|
||||
case breez_sdk.InputTypeLnUrlWithdraw:
|
||||
amountsSats := input.MinWithdrawable
|
||||
result, err := sdkServices.WithdrawLnurl(input.Data, amountsSats, "comment")
|
||||
amountsSats := inputType.Data.MinWithdrawable
|
||||
description := "comment"
|
||||
result, err := sdkServices.WithdrawLnurl(inputType.Data, amountsSats, &description)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -44,7 +44,7 @@ You can check its status with:
|
||||
|
||||
```rust,no_run
|
||||
for rs in sdk.in_progress_reverse_swaps().await? {
|
||||
info!("Reverse swap {} in progress, status is {}", rs.id, rs.breez_status);
|
||||
info!("Reverse swap {} in progress, status is {}", rs.id, rs.status);
|
||||
}
|
||||
```
|
||||
</section>
|
||||
@@ -95,7 +95,7 @@ You can check its status with:
|
||||
|
||||
```swift
|
||||
for rs in sdk.inProgressReverseSwaps() {
|
||||
println("Reverse swap \(rs.id) in progress, status is \(rs.breezStatus)")
|
||||
println("Reverse swap \(rs.id) in progress, status is \(rs.status)")
|
||||
}
|
||||
```
|
||||
</section>
|
||||
@@ -121,8 +121,8 @@ of the total costs.
|
||||
Fetching the fees also tells you what is the range of amounts you can send:
|
||||
|
||||
```typescript
|
||||
console.log(`Minimum amount, in sats: ${current_fees.min}`);
|
||||
console.log(`Maximum amount, in sats: ${current_fees.max}`);
|
||||
console.log(`Minimum amount, in sats: ${currentFees.min}`);
|
||||
console.log(`Maximum amount, in sats: ${currentFees.max}`);
|
||||
```
|
||||
|
||||
Once you checked the fees are acceptable, you can start the reverse swap:
|
||||
@@ -148,13 +148,59 @@ You can check its status with:
|
||||
try {
|
||||
const swaps = await inProgressReverseSwaps()
|
||||
for (const swap in swaps) {
|
||||
println(`Reverse swap ${swap.id} in progress, status is ${swap.breezStatus}`);
|
||||
println(`Reverse swap ${swap.id} in progress, status is ${swap.status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
```
|
||||
</section>
|
||||
<div slot="title">Go</div>
|
||||
<section>
|
||||
|
||||
```go
|
||||
if currentFees, err := sdkServices.FetchReverseSwapFees(); err != nil {
|
||||
log.Printf("Percentage fee for the reverse swap service: %v", currentFees.FeesPercentage)
|
||||
log.Printf("Estimated miner fees in sats for locking up funds: %v", currentFees.FeesLockup)
|
||||
log.Printf("Estimated miner fees in sats for claiming funds: %v", currentFees.FeesClaim)
|
||||
}
|
||||
```
|
||||
|
||||
The reverse swap will involve two on-chain transactions, for which the mining fees can only be estimated. They will happen
|
||||
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:
|
||||
|
||||
```go
|
||||
log.Printf("Minimum amount, in sats: %v", currentFees.Min)
|
||||
log.Printf("Maximum amount, in sats: %v", currentFees.Max)
|
||||
```
|
||||
|
||||
Once you checked the fees are acceptable, you can start the reverse swap:
|
||||
|
||||
```go
|
||||
destinationAddress := "bc1.."
|
||||
amountSat := currentFees.Min
|
||||
satPerVbyte := <fee rate>
|
||||
|
||||
reverseSwapInfo, err := sdkServices.SendOnchain(amountSat, destinationAddress, currentFees.FeesHash, satPerVbyte)
|
||||
```
|
||||
|
||||
Starting the reverse swap will trigger a HODL invoice payment, which will only be settled if the entire swap completes.
|
||||
This means you will see an outgoing pending payment in your list of payments, which locks those funds until the invoice
|
||||
is either settled or cancelled. This will happen automatically at the end of the reverse swap.
|
||||
|
||||
You can check its status with:
|
||||
|
||||
```go
|
||||
if swaps, err := sdkServices.InProgressReverseSwaps(); err != nil {
|
||||
for _, swap := range swaps {
|
||||
log.Printf("Reverse swap %v in progress, status is %v", swap.Id, swap.Status)
|
||||
}
|
||||
}
|
||||
```
|
||||
</section>
|
||||
</custom-tabs>
|
||||
If the reverse swap is successful, you'll get the on-chain payment on your destination address and the HODL invoice will
|
||||
change from pending to settled.
|
||||
|
||||
Reference in New Issue
Block a user