Skip to content

Commit 8696132

Browse files
committed
cmd/loopout: add asset flags
1 parent 2e7f1e5 commit 8696132

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

cmd/loop/loopout.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"encoding/hex"
56
"fmt"
67
"math"
78
"strconv"
@@ -101,6 +102,18 @@ var loopOutCommand = cli.Command{
101102
"payment might be retried, the actual total " +
102103
"time may be longer",
103104
},
105+
cli.StringFlag{
106+
Name: "asset_id",
107+
Usage: "the asset ID of the asset to loop out, " +
108+
"if this is set, the loop daemon will require a connection " +
109+
"to a taproot assets daemon",
110+
},
111+
cli.StringFlag{
112+
Name: "asset_edge_node",
113+
Usage: "the pubkey of the edge node of the asset to loop out, " +
114+
"this is required if the taproot assets daemon has multiple " +
115+
"channels of the given asset id with different edge nodes",
116+
},
104117
forceFlag,
105118
labelFlag,
106119
verboseFlag,
@@ -186,6 +199,26 @@ func loopOut(ctx *cli.Context) error {
186199
}
187200
}
188201

202+
var assetId []byte
203+
if ctx.IsSet("asset_id") {
204+
assetId, err = hex.DecodeString(ctx.String("asset_id"))
205+
if err != nil {
206+
return err
207+
}
208+
if !ctx.IsSet("asset_edge_node") {
209+
return fmt.Errorf("asset edge node is required when " +
210+
"assetid is set")
211+
}
212+
}
213+
214+
var assetEdgeNode []byte
215+
if ctx.IsSet("asset_edge_node") {
216+
assetEdgeNode, err = hex.DecodeString(ctx.String("asset_edge_node"))
217+
if err != nil {
218+
return err
219+
}
220+
}
221+
189222
client, cleanup, err := getClient(ctx)
190223
if err != nil {
191224
return err
@@ -210,6 +243,8 @@ func loopOut(ctx *cli.Context) error {
210243
Amt: int64(amt),
211244
ConfTarget: sweepConfTarget,
212245
SwapPublicationDeadline: uint64(swapDeadline.Unix()),
246+
AssetId: assetId,
247+
AssetEdgeNode: assetEdgeNode,
213248
}
214249
quote, err := client.LoopOutQuote(context.Background(), quoteReq)
215250
if err != nil {
@@ -281,6 +316,8 @@ func loopOut(ctx *cli.Context) error {
281316
Label: label,
282317
Initiator: defaultInitiator,
283318
PaymentTimeout: uint32(paymentTimeout),
319+
AssetId: assetId,
320+
AssetEdgeNode: assetEdgeNode,
284321
})
285322
if err != nil {
286323
return err

cmd/loop/quote.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,15 @@ func printQuoteOutResp(req *looprpc.QuoteRequest,
267267

268268
totalFee := resp.HtlcSweepFeeSat + resp.SwapFeeSat
269269

270-
fmt.Printf(satAmtFmt, "Send off-chain:", req.Amt)
271-
fmt.Printf(satAmtFmt, "Receive on-chain:", req.Amt-totalFee)
270+
if req.AssetId != nil {
271+
fmt.Printf("%-36s %12d assets\n",
272+
"Assets Send off-chain:", req.Amt)
273+
fmt.Printf(satAmtFmt, "Sats Send off-chain:",
274+
resp.InvoiceAmtSat)
275+
} else {
276+
fmt.Printf(satAmtFmt, "Send off-chain:", resp.InvoiceAmtSat)
277+
}
278+
fmt.Printf(satAmtFmt, "Receive on-chain:", resp.InvoiceAmtSat-totalFee)
272279

273280
if !verbose {
274281
fmt.Printf(satAmtFmt, "Estimated total fee:", totalFee)

0 commit comments

Comments
 (0)