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