66 "os"
77 "time"
88
9+ "github.com/btcsuite/btcd/btcutil"
910 "github.com/lightninglabs/loop"
1011 "github.com/lightninglabs/loop/looprpc"
1112 "github.com/lightningnetwork/lnd/routing/route"
@@ -19,10 +20,11 @@ var quoteCommand = cli.Command{
1920}
2021
2122var quoteInCommand = cli.Command {
22- Name : "in" ,
23- Usage : "get a quote for the cost of a loop in swap" ,
24- ArgsUsage : "amt" ,
25- Description : "Allows to determine the cost of a swap up front" ,
23+ Name : "in" ,
24+ Usage : "get a quote for the cost of a loop in swap" ,
25+ ArgsUsage : "amt" ,
26+ Description : "Allows to determine the cost of a swap up front." +
27+ "Either specify an amount or deposit outpoints." ,
2628 Flags : []cli.Flag {
2729 cli.StringFlag {
2830 Name : lastHopFlag .Name ,
@@ -33,20 +35,36 @@ var quoteInCommand = cli.Command{
3335 verboseFlag ,
3436 privateFlag ,
3537 routeHintsFlag ,
38+ cli.StringSliceFlag {
39+ Name : "deposit_outpoint" ,
40+ Usage : "one or more static address deposit outpoints " +
41+ "to quote for. Deposit outpoints are not to " +
42+ "be used in combination with an amount." ,
43+ },
3644 },
3745 Action : quoteIn ,
3846}
3947
4048func quoteIn (ctx * cli.Context ) error {
4149 // Show command help if the incorrect number arguments was provided.
42- if ctx .NArg () != 1 {
50+ if ctx .NArg () != 1 && ! ctx . IsSet ( "deposit_outpoint" ) {
4351 return cli .ShowCommandHelp (ctx , "in" )
4452 }
4553
46- args := ctx .Args ()
47- amt , err := parseAmt (args [0 ])
48- if err != nil {
49- return err
54+ var (
55+ manualAmt btcutil.Amount
56+ depositAmt btcutil.Amount
57+ depositOutpoints []string
58+ err error
59+ ctxb = context .Background ()
60+ )
61+
62+ if ctx .NArg () == 1 {
63+ args := ctx .Args ()
64+ manualAmt , err = parseAmt (args [0 ])
65+ if err != nil {
66+ return err
67+ }
5068 }
5169
5270 client , cleanup , err := getClient (ctx )
@@ -62,11 +80,20 @@ func quoteIn(ctx *cli.Context) error {
6280 return err
6381 }
6482
83+ if ctx .IsSet ("deposit_outpoint" ) {
84+ depositOutpoints = ctx .StringSlice ("deposit_outpoint" )
85+ depositAmt , err = depositAmount (ctxb , client , depositOutpoints )
86+ if err != nil {
87+ return err
88+ }
89+ }
90+
6591 quoteReq := & looprpc.QuoteRequest {
66- Amt : int64 (amt ),
92+ Amt : int64 (manualAmt ),
6793 ConfTarget : int32 (ctx .Uint64 ("conf_target" )),
6894 LoopInRouteHints : hints ,
6995 Private : ctx .Bool (privateFlag .Name ),
96+ DepositOutpoints : depositOutpoints ,
7097 }
7198
7299 if ctx .IsSet (lastHopFlag .Name ) {
@@ -80,7 +107,6 @@ func quoteIn(ctx *cli.Context) error {
80107 quoteReq .LoopInLastHop = lastHopVertex [:]
81108 }
82109
83- ctxb := context .Background ()
84110 quoteResp , err := client .GetLoopInQuote (ctxb , quoteReq )
85111 if err != nil {
86112 return err
@@ -98,10 +124,39 @@ func quoteIn(ctx *cli.Context) error {
98124 "amount.\n " )
99125 }
100126
127+ // If the user specified static address deposits, we quoted for their
128+ // total value and need to display that value instead of the manually
129+ // selected one.
130+ if manualAmt == 0 {
131+ quoteReq .Amt = int64 (depositAmt )
132+ }
101133 printQuoteInResp (quoteReq , quoteResp , ctx .Bool ("verbose" ))
102134 return nil
103135}
104136
137+ func depositAmount (ctx context.Context , client looprpc.SwapClientClient ,
138+ depositOutpoints []string ) (btcutil.Amount , error ) {
139+
140+ var (
141+ depositAmt btcutil.Amount
142+ )
143+
144+ addressSummary , err := client .GetStaticAddressSummary (
145+ ctx , & looprpc.StaticAddressSummaryRequest {
146+ Outpoints : depositOutpoints ,
147+ },
148+ )
149+ if err != nil {
150+ return 0 , err
151+ }
152+
153+ for _ , deposit := range addressSummary .FilteredDeposits {
154+ depositAmt += btcutil .Amount (deposit .Value )
155+ }
156+
157+ return depositAmt , nil
158+ }
159+
105160var quoteOutCommand = cli.Command {
106161 Name : "out" ,
107162 Usage : "get a quote for the cost of a loop out swap" ,
0 commit comments