Skip to content

Commit 7e3ea44

Browse files
committed
multi: standardize address checks
1 parent 53085d3 commit 7e3ea44

18 files changed

+206
-52
lines changed

cmd/chantools/closepoolaccount.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ obtained by running 'pool accounts list' `,
8888
"API instead of just printing the TX",
8989
)
9090
cc.cmd.Flags().StringVar(
91-
&cc.SweepAddr, "sweepaddr", "", "address to sweep the funds to",
91+
&cc.SweepAddr, "sweepaddr", "", "address to recover the funds "+
92+
"to; specify '"+lnd.AddressDeriveFromWallet+"' to "+
93+
"derive a new address from the seed automatically",
9294
)
9395
cc.cmd.Flags().Uint32Var(
9496
&cc.FeeRate, "feerate", defaultFeeSatPerVByte, "fee rate to "+
@@ -124,8 +126,12 @@ func (c *closePoolAccountCommand) Execute(_ *cobra.Command, _ []string) error {
124126
}
125127

126128
// Make sure sweep addr is set.
127-
if c.SweepAddr == "" {
128-
return fmt.Errorf("sweep addr is required")
129+
err = lnd.CheckAddress(
130+
c.SweepAddr, chainParams, true, "sweep", lnd.AddrTypeP2WKH,
131+
lnd.AddrTypeP2TR,
132+
)
133+
if err != nil {
134+
return err
129135
}
130136

131137
// Parse account outpoint and auctioneer key.

cmd/chantools/doublespendinputs.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ type doubleSpendInputs struct {
3434
func newDoubleSpendInputsCommand() *cobra.Command {
3535
cc := &doubleSpendInputs{}
3636
cc.cmd = &cobra.Command{
37-
Use: "doublespendinputs",
38-
Short: "Tries to double spend the given inputs by deriving the " +
39-
"private for the address and sweeping the funds to the given " +
40-
"address. This can only be used with inputs that belong to " +
41-
"an lnd wallet.",
37+
Use: "doublespendinputs",
38+
Short: "Replace a transaction by double spending its input",
39+
Long: `Tries to double spend the given inputs by deriving the
40+
private for the address and sweeping the funds to the given address. This can
41+
only be used with inputs that belong to an lnd wallet.`,
4242
Example: `chantools doublespendinputs \
43-
--inputoutpoints xxxxxxxxx:y,xxxxxxxxx:y \
44-
--sweepaddr bc1q..... \
45-
--feerate 10 \
46-
--publish`,
43+
--inputoutpoints xxxxxxxxx:y,xxxxxxxxx:y \
44+
--sweepaddr bc1q..... \
45+
--feerate 10 \
46+
--publish`,
4747
RunE: cc.Execute,
4848
}
4949
cc.cmd.Flags().StringVar(
@@ -55,7 +55,9 @@ func newDoubleSpendInputsCommand() *cobra.Command {
5555
"list of outpoints to double spend in the format txid:vout",
5656
)
5757
cc.cmd.Flags().StringVar(
58-
&cc.SweepAddr, "sweepaddr", "", "address to sweep the funds to",
58+
&cc.SweepAddr, "sweepaddr", "", "address to recover the funds "+
59+
"to; specify '"+lnd.AddressDeriveFromWallet+"' to "+
60+
"derive a new address from the seed automatically",
5961
)
6062
cc.cmd.Flags().Uint32Var(
6163
&cc.FeeRate, "feerate", defaultFeeSatPerVByte, "fee rate to "+
@@ -83,8 +85,12 @@ func (c *doubleSpendInputs) Execute(_ *cobra.Command, _ []string) error {
8385
}
8486

8587
// Make sure sweep addr is set.
86-
if c.SweepAddr == "" {
87-
return fmt.Errorf("sweep addr is required")
88+
err = lnd.CheckAddress(
89+
c.SweepAddr, chainParams, true, "sweep", lnd.AddrTypeP2WKH,
90+
lnd.AddrTypeP2TR,
91+
)
92+
if err != nil {
93+
return err
8894
}
8995

9096
// Make sure we have at least one input.

cmd/chantools/pullanchor.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ transaction of an anchor output channel type. This will attempt to CPFP the
6565
)
6666
cc.cmd.Flags().StringVar(
6767
&cc.ChangeAddr, "changeaddr", "", "the change address to "+
68-
"send the remaining funds to",
68+
"send the remaining funds back to; specify '"+
69+
lnd.AddressDeriveFromWallet+"' to derive a new "+
70+
"address from the seed automatically",
6971
)
7072
cc.cmd.Flags().Uint32Var(
7173
&cc.FeeRate, "feerate", defaultFeeSatPerVByte, "fee rate to "+
@@ -90,8 +92,21 @@ func (c *pullAnchorCommand) Execute(_ *cobra.Command, _ []string) error {
9092
if len(c.AnchorAddrs) == 0 {
9193
return fmt.Errorf("at least one anchor addr is required")
9294
}
93-
if c.ChangeAddr == "" {
94-
return fmt.Errorf("change addr is required")
95+
for _, anchorAddr := range c.AnchorAddrs {
96+
err = lnd.CheckAddress(
97+
anchorAddr, chainParams, true, "anchor",
98+
lnd.AddrTypeP2WSH, lnd.AddrTypeP2TR,
99+
)
100+
if err != nil {
101+
return err
102+
}
103+
}
104+
err = lnd.CheckAddress(
105+
c.ChangeAddr, chainParams, true, "change", lnd.AddrTypeP2WKH,
106+
lnd.AddrTypeP2TR,
107+
)
108+
if err != nil {
109+
return err
95110
}
96111

97112
outpoint, err := lnd.ParseOutpoint(c.SponsorInput)

cmd/chantools/recoverloopin.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ func newRecoverLoopInCommand() *cobra.Command {
6969
"database directory, where the loop.db file is located",
7070
)
7171
cc.cmd.Flags().StringVar(
72-
&cc.SweepAddr, "sweep_addr", "", "address to recover "+
73-
"the funds to",
72+
&cc.SweepAddr, "sweepaddr", "", "address to recover the funds "+
73+
"to; specify '"+lnd.AddressDeriveFromWallet+"' to "+
74+
"derive a new address from the seed automatically",
7475
)
7576
cc.cmd.Flags().Uint32Var(
7677
&cc.FeeRate, "feerate", 0, "fee rate to "+
@@ -116,12 +117,15 @@ func (c *recoverLoopInCommand) Execute(_ *cobra.Command, _ []string) error {
116117
return fmt.Errorf("loop_db_dir is required")
117118
}
118119

119-
if c.SweepAddr == "" {
120-
return fmt.Errorf("sweep_addr is required")
120+
err = lnd.CheckAddress(
121+
c.SweepAddr, chainParams, true, "sweep", lnd.AddrTypeP2WKH,
122+
lnd.AddrTypeP2TR,
123+
)
124+
if err != nil {
125+
return err
121126
}
122127

123128
api := newExplorerAPI(c.APIURL)
124-
125129
signer := &lnd.Signer{
126130
ExtendedKey: extendedKey,
127131
ChainParams: chainParams,

cmd/chantools/rescuefunding.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ chantools rescuefunding \
112112
"specified manually",
113113
)
114114
cc.cmd.Flags().StringVar(
115-
&cc.SweepAddr, "sweepaddr", "", "address to sweep the funds to",
115+
&cc.SweepAddr, "sweepaddr", "", "address to recover the funds "+
116+
"to; specify '"+lnd.AddressDeriveFromWallet+"' to "+
117+
"derive a new address from the seed automatically",
116118
)
117119
cc.cmd.Flags().Uint32Var(
118120
&cc.FeeRate, "feerate", defaultFeeSatPerVByte, "fee rate to "+
@@ -226,6 +228,14 @@ func (c *rescueFundingCommand) Execute(_ *cobra.Command, _ []string) error {
226228
}
227229
}
228230

231+
err = lnd.CheckAddress(
232+
c.SweepAddr, chainParams, true, "sweep", lnd.AddrTypeP2WKH,
233+
lnd.AddrTypeP2TR,
234+
)
235+
if err != nil {
236+
return err
237+
}
238+
229239
// Make sure the sweep addr is a P2WKH address so we can do accurate
230240
// fee estimation.
231241
sweepScript, err := lnd.GetP2WPKHScript(c.SweepAddr, chainParams)

cmd/chantools/sweepremoteclosed.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ Supported remote force-closed channel types are:
7676
"API instead of just printing the TX",
7777
)
7878
cc.cmd.Flags().StringVar(
79-
&cc.SweepAddr, "sweepaddr", "", "address to sweep the funds to",
79+
&cc.SweepAddr, "sweepaddr", "", "address to recover the funds "+
80+
"to; specify '"+lnd.AddressDeriveFromWallet+"' to "+
81+
"derive a new address from the seed automatically",
8082
)
8183
cc.cmd.Flags().Uint32Var(
8284
&cc.FeeRate, "feerate", defaultFeeSatPerVByte, "fee rate to "+
@@ -95,8 +97,12 @@ func (c *sweepRemoteClosedCommand) Execute(_ *cobra.Command, _ []string) error {
9597
}
9698

9799
// Make sure sweep addr is set.
98-
if c.SweepAddr == "" {
99-
return fmt.Errorf("sweep addr is required")
100+
err = lnd.CheckAddress(
101+
c.SweepAddr, chainParams, true, "sweep", lnd.AddrTypeP2WKH,
102+
lnd.AddrTypeP2TR,
103+
)
104+
if err != nil {
105+
return err
100106
}
101107

102108
// Set default values.
@@ -423,7 +429,7 @@ func queryAddressBalances(pubKey *btcec.PublicKey, path string,
423429
return nil, err
424430
}
425431

426-
p2tr, scriptTree, err := lnd.P2TaprootStaticRemove(pubKey, chainParams)
432+
p2tr, scriptTree, err := lnd.P2TaprootStaticRemote(pubKey, chainParams)
427433
if err != nil {
428434
return nil, err
429435
}

cmd/chantools/sweeptimelock.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ parameter to 144.`,
6464
"API instead of just printing the TX",
6565
)
6666
cc.cmd.Flags().StringVar(
67-
&cc.SweepAddr, "sweepaddr", "", "address to sweep the funds to",
67+
&cc.SweepAddr, "sweepaddr", "", "address to recover the funds "+
68+
"to; specify '"+lnd.AddressDeriveFromWallet+"' to "+
69+
"derive a new address from the seed automatically",
6870
)
6971
cc.cmd.Flags().Uint16Var(
7072
&cc.MaxCsvLimit, "maxcsvlimit", defaultCsvLimit, "maximum CSV "+
@@ -88,8 +90,12 @@ func (c *sweepTimeLockCommand) Execute(_ *cobra.Command, _ []string) error {
8890
}
8991

9092
// Make sure sweep addr is set.
91-
if c.SweepAddr == "" {
92-
return fmt.Errorf("sweep addr is required")
93+
err = lnd.CheckAddress(
94+
c.SweepAddr, chainParams, true, "sweep", lnd.AddrTypeP2WKH,
95+
lnd.AddrTypeP2TR,
96+
)
97+
if err != nil {
98+
return err
9399
}
94100

95101
// Parse channel entries from any of the possible input files.

cmd/chantools/sweeptimelockmanual.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ chantools sweeptimelockmanual \
8989
"API instead of just printing the TX",
9090
)
9191
cc.cmd.Flags().StringVar(
92-
&cc.SweepAddr, "sweepaddr", "", "address to sweep the funds to",
92+
&cc.SweepAddr, "sweepaddr", "", "address to recover the funds "+
93+
"to; specify '"+lnd.AddressDeriveFromWallet+"' to "+
94+
"derive a new address from the seed automatically",
9395
)
9496
cc.cmd.Flags().Uint16Var(
9597
&cc.MaxCsvLimit, "maxcsvlimit", defaultCsvLimit, "maximum CSV "+
@@ -142,11 +144,20 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
142144
}
143145

144146
// Make sure the sweep and time lock addrs are set.
145-
if c.SweepAddr == "" {
146-
return fmt.Errorf("sweep addr is required")
147+
err = lnd.CheckAddress(
148+
c.SweepAddr, chainParams, true, "sweep", lnd.AddrTypeP2WKH,
149+
lnd.AddrTypeP2TR,
150+
)
151+
if err != nil {
152+
return err
147153
}
148-
if c.TimeLockAddr == "" {
149-
return fmt.Errorf("time lock addr is required")
154+
155+
err = lnd.CheckAddress(
156+
c.TimeLockAddr, chainParams, true, "time lock",
157+
lnd.AddrTypeP2WSH,
158+
)
159+
if err != nil {
160+
return err
150161
}
151162

152163
var (

doc/chantools.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Chantools helps recover funds from lightning channels
66

77
This tool provides helper functions that can be used rescue
88
funds locked in lnd channels in case lnd itself cannot run properly anymore.
9-
Complete documentation is available at https://github.com/lightninglabs/chantools/.
9+
Complete documentation is available at
10+
https://github.com/lightninglabs/chantools/.
1011

1112
### Options
1213

@@ -24,7 +25,7 @@ Complete documentation is available at https://github.com/lightninglabs/chantool
2425
* [chantools compactdb](chantools_compactdb.md) - Create a copy of a channel.db file in safe/read-only mode
2526
* [chantools deletepayments](chantools_deletepayments.md) - Remove all (failed) payments from a channel DB
2627
* [chantools derivekey](chantools_derivekey.md) - Derive a key with a specific derivation path
27-
* [chantools doublespendinputs](chantools_doublespendinputs.md) - Tries to double spend the given inputs by deriving the private for the address and sweeping the funds to the given address. This can only be used with inputs that belong to an lnd wallet.
28+
* [chantools doublespendinputs](chantools_doublespendinputs.md) - Replace a transaction by double spending its input
2829
* [chantools dropchannelgraph](chantools_dropchannelgraph.md) - Remove all graph related data from a channel DB
2930
* [chantools dropgraphzombies](chantools_dropgraphzombies.md) - Remove all channels identified as zombies from the graph to force a re-sync of the graph
3031
* [chantools dumpbackup](chantools_dumpbackup.md) - Dump the content of a channel.backup file

doc/chantools_closepoolaccount.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ chantools closepoolaccount \
4141
--outpoint string last account outpoint of the account to close (<txid>:<txindex>)
4242
--publish publish sweep TX to the chain API instead of just printing the TX
4343
--rootkey string BIP32 HD root key of the wallet to use for deriving keys; leave empty to prompt for lnd 24 word aezeed
44-
--sweepaddr string address to sweep the funds to
44+
--sweepaddr string address to recover the funds to; specify 'fromseed' to derive a new address from the seed automatically
4545
```
4646

4747
### Options inherited from parent commands

0 commit comments

Comments
 (0)