6
6
"os"
7
7
"time"
8
8
9
+ "github.com/btcsuite/btcd/btcutil"
9
10
"github.com/lightninglabs/loop"
10
11
"github.com/lightninglabs/loop/looprpc"
11
12
"github.com/lightningnetwork/lnd/routing/route"
@@ -19,10 +20,11 @@ var quoteCommand = cli.Command{
19
20
}
20
21
21
22
var 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." ,
26
28
Flags : []cli.Flag {
27
29
cli.StringFlag {
28
30
Name : lastHopFlag .Name ,
@@ -33,20 +35,36 @@ var quoteInCommand = cli.Command{
33
35
verboseFlag ,
34
36
privateFlag ,
35
37
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
+ },
36
44
},
37
45
Action : quoteIn ,
38
46
}
39
47
40
48
func quoteIn (ctx * cli.Context ) error {
41
49
// Show command help if the incorrect number arguments was provided.
42
- if ctx .NArg () != 1 {
50
+ if ctx .NArg () != 1 && ! ctx . IsSet ( "deposit_outpoint" ) {
43
51
return cli .ShowCommandHelp (ctx , "in" )
44
52
}
45
53
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
+ }
50
68
}
51
69
52
70
client , cleanup , err := getClient (ctx )
@@ -62,11 +80,20 @@ func quoteIn(ctx *cli.Context) error {
62
80
return err
63
81
}
64
82
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
+
65
91
quoteReq := & looprpc.QuoteRequest {
66
- Amt : int64 (amt ),
92
+ Amt : int64 (manualAmt ),
67
93
ConfTarget : int32 (ctx .Uint64 ("conf_target" )),
68
94
LoopInRouteHints : hints ,
69
95
Private : ctx .Bool (privateFlag .Name ),
96
+ DepositOutpoints : depositOutpoints ,
70
97
}
71
98
72
99
if ctx .IsSet (lastHopFlag .Name ) {
@@ -80,7 +107,6 @@ func quoteIn(ctx *cli.Context) error {
80
107
quoteReq .LoopInLastHop = lastHopVertex [:]
81
108
}
82
109
83
- ctxb := context .Background ()
84
110
quoteResp , err := client .GetLoopInQuote (ctxb , quoteReq )
85
111
if err != nil {
86
112
return err
@@ -98,10 +124,39 @@ func quoteIn(ctx *cli.Context) error {
98
124
"amount.\n " )
99
125
}
100
126
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
+ }
101
133
printQuoteInResp (quoteReq , quoteResp , ctx .Bool ("verbose" ))
102
134
return nil
103
135
}
104
136
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
+
105
160
var quoteOutCommand = cli.Command {
106
161
Name : "out" ,
107
162
Usage : "get a quote for the cost of a loop out swap" ,
0 commit comments