|
74 | 74 | Usage: "path to macaroon file", |
75 | 75 | Value: loopd.DefaultMacaroonPath, |
76 | 76 | } |
| 77 | + verboseFlag = cli.BoolFlag{ |
| 78 | + Name: "verbose, v", |
| 79 | + Usage: "show expanded details", |
| 80 | + } |
| 81 | +) |
| 82 | + |
| 83 | +const ( |
| 84 | + |
| 85 | + // satAmtFmt formats a satoshi value into a one line string, intended to |
| 86 | + // prettify the terminal output. For Instance, |
| 87 | + // fmt.Printf(f, "Estimated on-chain fee:", fee) |
| 88 | + // prints out as, |
| 89 | + // Estimated on-chain fee: 7262 sat |
| 90 | + satAmtFmt = "%-36s %12d sat\n" |
| 91 | + |
| 92 | + // blkFmt formats the number of blocks into a one line string, intended |
| 93 | + // to prettify the terminal output. For Instance, |
| 94 | + // fmt.Printf(f, "Conf target", target) |
| 95 | + // prints out as, |
| 96 | + // Conf target: 9 block |
| 97 | + blkFmt = "%-36s %12d block\n" |
77 | 98 | ) |
78 | 99 |
|
79 | 100 | func printJSON(resp interface{}) { |
@@ -246,89 +267,56 @@ func getOutLimits(amt btcutil.Amount, |
246 | 267 | } |
247 | 268 | } |
248 | 269 |
|
249 | | -func displayInLimits(amt, minerFees btcutil.Amount, l *inLimits, |
250 | | - externalHtlc bool) error { |
| 270 | +func displayInDetails(req *looprpc.QuoteRequest, |
| 271 | + resp *looprpc.InQuoteResponse, verbose bool) error { |
251 | 272 |
|
252 | | - totalSuccessMax := l.maxMinerFee + l.maxSwapFee |
253 | | - |
254 | | - if externalHtlc { |
| 273 | + if req.ExternalHtlc { |
255 | 274 | fmt.Printf("On-chain fee for external loop in is not " + |
256 | 275 | "included.\nSufficient fees will need to be paid " + |
257 | 276 | "when constructing the transaction in the external " + |
258 | 277 | "wallet.\n\n") |
259 | 278 | } |
260 | 279 |
|
261 | | - fmt.Printf("Max swap fees for %d sat Loop %v: %d sat\n", amt, swap.TypeIn, |
262 | | - totalSuccessMax) |
| 280 | + printQuoteInResp(req, resp, verbose) |
263 | 281 |
|
264 | | - fmt.Printf("CONTINUE SWAP? (y/n), expand fee detail (x): ") |
| 282 | + fmt.Printf("\nCONTINUE SWAP? (y/n): ") |
265 | 283 |
|
266 | 284 | var answer string |
267 | 285 | fmt.Scanln(&answer) |
268 | | - |
269 | | - switch answer { |
270 | | - case "y": |
| 286 | + if answer == "y" { |
271 | 287 | return nil |
272 | | - case "x": |
273 | | - fmt.Println() |
274 | | - f := "%-36s %d sat\n" |
275 | | - |
276 | | - if !externalHtlc { |
277 | | - fmt.Printf(f, "Estimated on-chain HTLC fee:", |
278 | | - minerFees) |
279 | | - } |
280 | | - |
281 | | - fmt.Printf(f, "Max swap fee:", l.maxSwapFee) |
282 | | - |
283 | | - fmt.Printf("CONTINUE SWAP? (y/n): ") |
284 | | - fmt.Scanln(&answer) |
285 | | - if answer == "y" { |
286 | | - return nil |
287 | | - } |
288 | 288 | } |
289 | 289 |
|
290 | 290 | return errors.New("swap canceled") |
291 | 291 | } |
292 | 292 |
|
293 | | -func displayOutLimits(amt, minerFees btcutil.Amount, l *outLimits, |
294 | | - warning string) error { |
| 293 | +func displayOutDetails(l *outLimits, warning string, req *looprpc.QuoteRequest, |
| 294 | + resp *looprpc.OutQuoteResponse, verbose bool) error { |
295 | 295 |
|
296 | | - totalSuccessMax := l.maxMinerFee + l.maxSwapFee + l.maxSwapRoutingFee + |
297 | | - l.maxPrepayRoutingFee |
| 296 | + printQuoteOutResp(req, resp, verbose) |
298 | 297 |
|
299 | | - fmt.Printf("Max swap fees for %d sat Loop %v: %d sat\n", amt, swap.TypeOut, |
300 | | - totalSuccessMax) |
| 298 | + // Display fee limits. |
| 299 | + if verbose { |
| 300 | + fmt.Println() |
| 301 | + fmt.Printf(satAmtFmt, "Max on-chain fee:", l.maxMinerFee) |
| 302 | + fmt.Printf(satAmtFmt, |
| 303 | + "Max off-chain swap routing fee:", l.maxSwapRoutingFee, |
| 304 | + ) |
| 305 | + fmt.Printf(satAmtFmt, "Max off-chain prepay routing fee:", |
| 306 | + l.maxPrepayRoutingFee) |
| 307 | + } |
301 | 308 |
|
| 309 | + // show warning |
302 | 310 | if warning != "" { |
303 | | - fmt.Println(warning) |
| 311 | + fmt.Printf("\n%s\n\n", warning) |
304 | 312 | } |
305 | 313 |
|
306 | | - fmt.Printf("CONTINUE SWAP? (y/n), expand fee detail (x): ") |
| 314 | + fmt.Printf("CONTINUE SWAP? (y/n): ") |
307 | 315 |
|
308 | 316 | var answer string |
309 | 317 | fmt.Scanln(&answer) |
310 | | - |
311 | | - switch answer { |
312 | | - case "y": |
| 318 | + if answer == "y" { |
313 | 319 | return nil |
314 | | - case "x": |
315 | | - fmt.Println() |
316 | | - f := "%-36s %d sat\n" |
317 | | - |
318 | | - fmt.Printf(f, "Estimated on-chain sweep fee:", minerFees) |
319 | | - fmt.Printf(f, "Max on-chain sweep fee:", l.maxMinerFee) |
320 | | - fmt.Printf(f, "Max off-chain swap routing fee:", |
321 | | - l.maxSwapRoutingFee) |
322 | | - fmt.Printf(f, "Max no show penalty (prepay):", l.maxPrepayAmt) |
323 | | - fmt.Printf(f, "Max off-chain prepay routing fee:", |
324 | | - l.maxPrepayRoutingFee) |
325 | | - fmt.Printf(f, "Max swap fee:", l.maxSwapFee) |
326 | | - |
327 | | - fmt.Printf("CONTINUE SWAP? (y/n): ") |
328 | | - fmt.Scanln(&answer) |
329 | | - if answer == "y" { |
330 | | - return nil |
331 | | - } |
332 | 320 | } |
333 | 321 |
|
334 | 322 | return errors.New("swap canceled") |
|
0 commit comments