Skip to content

Commit 7f49ed9

Browse files
committed
cmd/loopout: add asset flags
1 parent e22f15a commit 7f49ed9

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

cmd/loop/loopout.go

Lines changed: 44 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,20 @@ 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 " +
109+
"require a connection to a taproot assets " +
110+
"daemon",
111+
},
112+
cli.StringFlag{
113+
Name: "asset_edge_node",
114+
Usage: "the pubkey of the edge node of the asset to " +
115+
"loop out, this is required if the taproot " +
116+
"assets daemon has multiple channels of the " +
117+
"given asset id with different edge nodes",
118+
},
104119
forceFlag,
105120
labelFlag,
106121
verboseFlag,
@@ -186,6 +201,33 @@ func loopOut(ctx *cli.Context) error {
186201
}
187202
}
188203

204+
var assetLoopOutInfo *looprpc.AssetLoopOutInfo
205+
206+
var assetId []byte
207+
if ctx.IsSet("asset_id") {
208+
if !ctx.IsSet("asset_edge_node") {
209+
return fmt.Errorf("asset edge node is required when " +
210+
"assetid is set")
211+
}
212+
213+
assetId, err = hex.DecodeString(ctx.String("asset_id"))
214+
if err != nil {
215+
return err
216+
}
217+
218+
assetEdgeNode, err := hex.DecodeString(
219+
ctx.String("asset_edge_node"),
220+
)
221+
if err != nil {
222+
return err
223+
}
224+
225+
assetLoopOutInfo = &looprpc.AssetLoopOutInfo{
226+
AssetId: assetId,
227+
AssetEdgeNode: assetEdgeNode,
228+
}
229+
}
230+
189231
client, cleanup, err := getClient(ctx)
190232
if err != nil {
191233
return err
@@ -210,6 +252,7 @@ func loopOut(ctx *cli.Context) error {
210252
Amt: int64(amt),
211253
ConfTarget: sweepConfTarget,
212254
SwapPublicationDeadline: uint64(swapDeadline.Unix()),
255+
AssetInfo: assetLoopOutInfo,
213256
}
214257
quote, err := client.LoopOutQuote(context.Background(), quoteReq)
215258
if err != nil {
@@ -281,6 +324,7 @@ func loopOut(ctx *cli.Context) error {
281324
Label: label,
282325
Initiator: defaultInitiator,
283326
PaymentTimeout: uint32(paymentTimeout),
327+
AssetInfo: assetLoopOutInfo,
284328
})
285329
if err != nil {
286330
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.AssetInfo != 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)