@@ -478,6 +478,13 @@ var staticAddressLoopInCommand = cli.Command{
478
478
"The client can retry the swap with adjusted " +
479
479
"parameters after the payment timed out." ,
480
480
},
481
+ cli.IntFlag {
482
+ Name : "amount" ,
483
+ Usage : "the number of satoshis that should be " +
484
+ "swapped from the selected deposits. If there" +
485
+ "is change it is sent back to the static " +
486
+ "address." ,
487
+ },
481
488
lastHopFlag ,
482
489
labelFlag ,
483
490
routeHintsFlag ,
@@ -500,13 +507,15 @@ func staticAddressLoopIn(ctx *cli.Context) error {
500
507
defer cleanup ()
501
508
502
509
var (
503
- ctxb = context .Background ()
504
- isAllSelected = ctx .IsSet ("all" )
505
- isUtxoSelected = ctx .IsSet ("utxo" )
506
- label = ctx .String ("static-loop-in" )
507
- hints []* swapserverrpc.RouteHint
508
- lastHop []byte
509
- paymentTimeoutSeconds = uint32 (loopin .DefaultPaymentTimeoutSeconds )
510
+ ctxb = context .Background ()
511
+ isAllSelected = ctx .IsSet ("all" )
512
+ isUtxoSelected = ctx .IsSet ("utxo" )
513
+ selectedAmount = ctx .Int64 ("amount" )
514
+ selectDepositsForQuote bool
515
+ label = ctx .String ("static-loop-in" )
516
+ hints []* swapserverrpc.RouteHint
517
+ lastHop []byte
518
+ paymentTimeoutSeconds = uint32 (loopin .DefaultPaymentTimeoutSeconds )
510
519
)
511
520
512
521
// Validate our label early so that we can fail before getting a quote.
@@ -542,7 +551,9 @@ func staticAddressLoopIn(ctx *cli.Context) error {
542
551
return err
543
552
}
544
553
545
- if len (depositList .FilteredDeposits ) == 0 {
554
+ allDeposits := depositList .FilteredDeposits
555
+
556
+ if len (allDeposits ) == 0 {
546
557
errString := fmt .Sprintf ("no confirmed deposits available, " +
547
558
"deposits need at least %v confirmations" ,
548
559
deposit .MinConfs )
@@ -552,17 +563,18 @@ func staticAddressLoopIn(ctx *cli.Context) error {
552
563
553
564
var depositOutpoints []string
554
565
switch {
555
- case isAllSelected == isUtxoSelected :
556
- return errors .New ("must select either all or some utxos" )
566
+ case isAllSelected && isUtxoSelected :
567
+ return errors .New ("cannot select all and specific utxos" )
557
568
558
569
case isAllSelected :
559
- depositOutpoints = depositsToOutpoints (
560
- depositList .FilteredDeposits ,
561
- )
570
+ depositOutpoints = depositsToOutpoints (allDeposits )
562
571
563
572
case isUtxoSelected :
564
573
depositOutpoints = ctx .StringSlice ("utxo" )
565
574
575
+ case selectedAmount > 0 :
576
+ // If only an amount is selected we will trigger coin selection.
577
+
566
578
default :
567
579
return fmt .Errorf ("unknown quote request" )
568
580
}
@@ -571,11 +583,17 @@ func staticAddressLoopIn(ctx *cli.Context) error {
571
583
return errors .New ("duplicate outpoints detected" )
572
584
}
573
585
586
+ if len (depositOutpoints ) == 0 && selectedAmount > 0 {
587
+ selectDepositsForQuote = true
588
+ }
589
+
574
590
quoteReq := & looprpc.QuoteRequest {
591
+ Amt : selectedAmount ,
575
592
LoopInRouteHints : hints ,
576
593
LoopInLastHop : lastHop ,
577
594
Private : ctx .Bool (privateFlag .Name ),
578
595
DepositOutpoints : depositOutpoints ,
596
+ SelectDeposits : selectDepositsForQuote ,
579
597
}
580
598
quote , err := client .GetLoopInQuote (ctxb , quoteReq )
581
599
if err != nil {
@@ -584,15 +602,6 @@ func staticAddressLoopIn(ctx *cli.Context) error {
584
602
585
603
limits := getInLimits (quote )
586
604
587
- // populate the quote request with the sum of selected deposits and
588
- // prompt the user for acceptance.
589
- quoteReq .Amt , err = sumDeposits (
590
- depositOutpoints , depositList .FilteredDeposits ,
591
- )
592
- if err != nil {
593
- return err
594
- }
595
-
596
605
if ! (ctx .Bool ("force" ) || ctx .Bool ("f" )) {
597
606
err = displayInDetails (quoteReq , quote , ctx .Bool ("verbose" ))
598
607
if err != nil {
@@ -605,6 +614,7 @@ func staticAddressLoopIn(ctx *cli.Context) error {
605
614
}
606
615
607
616
req := & looprpc.StaticAddressLoopInRequest {
617
+ Amount : quoteReq .Amt ,
608
618
Outpoints : depositOutpoints ,
609
619
MaxSwapFeeSatoshis : int64 (limits .maxSwapFee ),
610
620
LastHop : lastHop ,
@@ -637,26 +647,6 @@ func containsDuplicates(outpoints []string) bool {
637
647
return false
638
648
}
639
649
640
- func sumDeposits (outpoints []string , deposits []* looprpc.Deposit ) (int64 ,
641
- error ) {
642
-
643
- var sum int64
644
- depositMap := make (map [string ]* looprpc.Deposit )
645
- for _ , deposit := range deposits {
646
- depositMap [deposit .Outpoint ] = deposit
647
- }
648
-
649
- for _ , outpoint := range outpoints {
650
- if _ , ok := depositMap [outpoint ]; ! ok {
651
- return 0 , fmt .Errorf ("deposit %v not found" , outpoint )
652
- }
653
-
654
- sum += depositMap [outpoint ].Value
655
- }
656
-
657
- return sum , nil
658
- }
659
-
660
650
func depositsToOutpoints (deposits []* looprpc.Deposit ) []string {
661
651
outpoints := make ([]string , 0 , len (deposits ))
662
652
for _ , deposit := range deposits {
0 commit comments