Skip to content

Commit dfa58d4

Browse files
committed
cmd/loopout: add asset flags
1 parent 40614a2 commit dfa58d4

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

cmd/loop/loopout.go

Lines changed: 49 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,
@@ -134,6 +149,10 @@ func loopOut(ctx *cli.Context) error {
134149
// element.
135150
var outgoingChanSet []uint64
136151
if ctx.IsSet("channel") {
152+
if ctx.IsSet("asset_id") {
153+
return fmt.Errorf("channel flag is not supported when " +
154+
"looping out assets")
155+
}
137156
chanStrings := strings.Split(ctx.String("channel"), ",")
138157
for _, chanString := range chanStrings {
139158
chanID, err := strconv.ParseUint(chanString, 10, 64)
@@ -186,6 +205,33 @@ func loopOut(ctx *cli.Context) error {
186205
}
187206
}
188207

208+
var assetLoopOutInfo *looprpc.AssetLoopOutRequest
209+
210+
var assetId []byte
211+
if ctx.IsSet("asset_id") {
212+
if !ctx.IsSet("asset_edge_node") {
213+
return fmt.Errorf("asset edge node is required when " +
214+
"assetid is set")
215+
}
216+
217+
assetId, err = hex.DecodeString(ctx.String("asset_id"))
218+
if err != nil {
219+
return err
220+
}
221+
222+
assetEdgeNode, err := hex.DecodeString(
223+
ctx.String("asset_edge_node"),
224+
)
225+
if err != nil {
226+
return err
227+
}
228+
229+
assetLoopOutInfo = &looprpc.AssetLoopOutRequest{
230+
AssetId: assetId,
231+
AssetEdgeNode: assetEdgeNode,
232+
}
233+
}
234+
189235
client, cleanup, err := getClient(ctx)
190236
if err != nil {
191237
return err
@@ -210,6 +256,7 @@ func loopOut(ctx *cli.Context) error {
210256
Amt: int64(amt),
211257
ConfTarget: sweepConfTarget,
212258
SwapPublicationDeadline: uint64(swapDeadline.Unix()),
259+
AssetInfo: assetLoopOutInfo,
213260
}
214261
quote, err := client.LoopOutQuote(context.Background(), quoteReq)
215262
if err != nil {
@@ -281,6 +328,8 @@ func loopOut(ctx *cli.Context) error {
281328
Label: label,
282329
Initiator: defaultInitiator,
283330
PaymentTimeout: uint32(paymentTimeout),
331+
AssetInfo: assetLoopOutInfo,
332+
AssetRfqInfo: quote.AssetRfqInfo,
284333
})
285334
if err != nil {
286335
return err

cmd/loop/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ const (
9696
// Estimated on-chain fee: 7262 sat
9797
satAmtFmt = "%-36s %12d sat\n"
9898

99+
// assetAmtFormat formats a value into a one line string, intended to
100+
// prettify the terminal output. For Instance,
101+
// fmt.Printf(f, "Amount:", amt, "USD")
102+
// prints out as,
103+
// Amount: 50 USD
104+
assetAmtFmt = "%-36s %12d %s\n"
105+
99106
// blkFmt formats the number of blocks into a one line string, intended
100107
// to prettify the terminal output. For Instance,
101108
// fmt.Printf(f, "Conf target", target)

cmd/loop/quote.go

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

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

270-
fmt.Printf(satAmtFmt, "Send off-chain:", req.Amt)
270+
if resp.AssetRfqInfo != nil {
271+
fmt.Printf(assetAmtFmt, "Send off-chain:",
272+
resp.AssetRfqInfo.SwapAssetAmt,
273+
resp.AssetRfqInfo.AssetName)
274+
} else {
275+
fmt.Printf(satAmtFmt, "Send off-chain:", req.Amt)
276+
}
277+
271278
fmt.Printf(satAmtFmt, "Receive on-chain:", req.Amt-totalFee)
272279

273280
if !verbose {
@@ -280,7 +287,14 @@ func printQuoteOutResp(req *looprpc.QuoteRequest,
280287
fmt.Printf(satAmtFmt, "Loop service fee:", resp.SwapFeeSat)
281288
fmt.Printf(satAmtFmt, "Estimated total fee:", totalFee)
282289
fmt.Println()
283-
fmt.Printf(satAmtFmt, "No show penalty (prepay):", resp.PrepayAmtSat)
290+
if resp.AssetRfqInfo != nil {
291+
fmt.Printf(assetAmtFmt, "No show penalty (prepay):",
292+
resp.AssetRfqInfo.PrepayAssetAmt,
293+
resp.AssetRfqInfo.AssetName)
294+
} else {
295+
fmt.Printf(satAmtFmt, "No show penalty (prepay):",
296+
resp.PrepayAmtSat)
297+
}
284298
fmt.Printf(blkFmt, "Conf target:", resp.ConfTarget)
285299
fmt.Printf(blkFmt, "CLTV expiry delta:", resp.CltvDelta)
286300
fmt.Printf("%-38s %s\n",

0 commit comments

Comments
 (0)