|
7 | 7 | "errors"
|
8 | 8 | "fmt"
|
9 | 9 | "os"
|
| 10 | + "path/filepath" |
10 | 11 | "regexp"
|
11 | 12 | "time"
|
12 | 13 |
|
@@ -122,30 +123,13 @@ func (c *rescueClosedCommand) Execute(_ *cobra.Command, _ []string) error {
|
122 | 123 | return fmt.Errorf("error reading root key: %w", err)
|
123 | 124 | }
|
124 | 125 |
|
| 126 | + cmdErr := errors.New("you either need to specify --channeldb and " + |
| 127 | + "--fromsummary or --force_close_addr and " + |
| 128 | + "--commit_point but not a mixture of them") |
| 129 | + |
125 | 130 | // What way of recovery has the user chosen? From summary and DB or from
|
126 | 131 | // address and commit point?
|
127 | 132 | switch {
|
128 |
| - case c.ChannelDB != "": |
129 |
| - db, err := lnd.OpenDB(c.ChannelDB, true) |
130 |
| - if err != nil { |
131 |
| - return fmt.Errorf("error opening rescue DB: %w", err) |
132 |
| - } |
133 |
| - |
134 |
| - // Parse channel entries from any of the possible input files. |
135 |
| - entries, err := c.inputs.parseInputType() |
136 |
| - if err != nil { |
137 |
| - return err |
138 |
| - } |
139 |
| - |
140 |
| - commitPoints, err := commitPointsFromDB(db.ChannelStateDB()) |
141 |
| - if err != nil { |
142 |
| - return fmt.Errorf("error reading commit points from "+ |
143 |
| - "db: %w", err) |
144 |
| - } |
145 |
| - return rescueClosedChannels( |
146 |
| - c.NumKeys, extendedKey, entries, commitPoints, |
147 |
| - ) |
148 |
| - |
149 | 133 | case c.Addr != "":
|
150 | 134 | // First parse address to get targetPubKeyHash from it later.
|
151 | 135 | targetAddr, err := btcutil.DecodeAddress(c.Addr, chainParams)
|
@@ -185,9 +169,39 @@ func (c *rescueClosedCommand) Execute(_ *cobra.Command, _ []string) error {
|
185 | 169 | )
|
186 | 170 |
|
187 | 171 | default:
|
188 |
| - return errors.New("you either need to specify --channeldb and " + |
189 |
| - "--fromsummary or --force_close_addr and " + |
190 |
| - "--commit_point but not a mixture of them") |
| 172 | + var opts []lnd.DBOption |
| 173 | + |
| 174 | + // In case the channel DB is specified, we get the graph dir |
| 175 | + // from it. |
| 176 | + if c.ChannelDB != "" { |
| 177 | + graphDir := filepath.Dir(c.ChannelDB) |
| 178 | + opts = append(opts, lnd.WithCustomGraphDir(graphDir)) |
| 179 | + } |
| 180 | + |
| 181 | + dbConfig := GetDBConfig() |
| 182 | + |
| 183 | + db, err := lnd.OpenChannelDB( |
| 184 | + dbConfig, false, chainParams.Name, opts..., |
| 185 | + ) |
| 186 | + if err != nil { |
| 187 | + return fmt.Errorf("error opening rescue DB: %w, %w", |
| 188 | + err, cmdErr) |
| 189 | + } |
| 190 | + |
| 191 | + // Parse channel entries from any of the possible input files. |
| 192 | + entries, err := c.inputs.parseInputType() |
| 193 | + if err != nil { |
| 194 | + return err |
| 195 | + } |
| 196 | + |
| 197 | + commitPoints, err := commitPointsFromDB(db.ChannelStateDB()) |
| 198 | + if err != nil { |
| 199 | + return fmt.Errorf("error reading commit points from "+ |
| 200 | + "db: %w", err) |
| 201 | + } |
| 202 | + return rescueClosedChannels( |
| 203 | + c.NumKeys, extendedKey, entries, commitPoints, |
| 204 | + ) |
191 | 205 | }
|
192 | 206 | }
|
193 | 207 |
|
|
0 commit comments