cmd: add instantout quote

pull/697/head
sputn1ck 3 months ago
parent b3fe9a9c61
commit cf6552944f
No known key found for this signature in database
GPG Key ID: 671103D881A5F0E4

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
@ -97,7 +98,10 @@ func instantOut(ctx *cli.Context) error {
fmt.Scanln(&answer) fmt.Scanln(&answer)
// Parse // Parse
var selectedReservations [][]byte var (
selectedReservations [][]byte
selectedAmt uint64
)
switch answer { switch answer {
case "ALL": case "ALL":
for _, res := range confirmedReservations { for _, res := range confirmedReservations {
@ -105,6 +109,7 @@ func instantOut(ctx *cli.Context) error {
selectedReservations, selectedReservations,
res.ReservationId, res.ReservationId,
) )
selectedAmt += res.Amount
} }
case "": case "":
@ -135,9 +140,33 @@ func instantOut(ctx *cli.Context) error {
) )
selectedIndexMap[idx] = struct{}{} selectedIndexMap[idx] = struct{}{}
selectedAmt += confirmedReservations[idx-1].Amount
} }
} }
// Now that we have the selected reservations we can estimate the
// fee-rates.
quote, err := client.InstantOutQuote(
context.Background(), &looprpc.InstantOutQuoteRequest{
Amt: selectedAmt,
NumReservations: int32(len(selectedReservations)),
},
)
if err != nil {
return err
}
fmt.Println()
fmt.Printf(satAmtFmt, "Estimated on-chain fee:", quote.SweepFeeSat)
fmt.Printf(satAmtFmt, "Service fee:", quote.ServiceFeeSat)
fmt.Println()
fmt.Printf("CONTINUE SWAP? (y/n): ")
fmt.Scanln(&answer)
if answer != "y" {
return errors.New("swap canceled")
}
fmt.Println("Starting instant swap out") fmt.Println("Starting instant swap out")
// Now we can request the instant out swap. // Now we can request the instant out swap.

Loading…
Cancel
Save