Skip to content

Commit aa767d3

Browse files
committed
btc: add encoded address as descriptor label
1 parent 9fadec9 commit aa767d3

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

btc/bitcoind.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,22 @@ func (d *Descriptors) Format(hdKey *hdkeychain.ExtendedKey,
294294
if err != nil {
295295
return "", fmt.Errorf("could not encode WIF: %w", err)
296296
}
297+
addrP2WKH, err := lnd.P2WKHAddr(privKey.PubKey(), params)
298+
if err != nil {
299+
return "", fmt.Errorf("could not create address: %w", err)
300+
}
301+
addrNP2WKH, err := lnd.NP2WKHAddr(privKey.PubKey(), params)
302+
if err != nil {
303+
return "", fmt.Errorf("could not create address: %w", err)
304+
}
305+
addrP2TR, err := lnd.P2TRAddr(privKey.PubKey(), params)
306+
if err != nil {
307+
return "", fmt.Errorf("could not create address: %w", err)
308+
}
297309

298-
np2wkh := makeDescriptor("sh(wpkh(%s))", wif.String())
299-
p2wkh := makeDescriptor("wpkh(%s)", wif.String())
300-
p2tr := makeDescriptor("tr(%s)", wif.String())
310+
np2wkh := makeDescriptor("sh(wpkh(%s))", wif.String(), addrNP2WKH)
311+
p2wkh := makeDescriptor("wpkh(%s)", wif.String(), addrP2WKH)
312+
p2tr := makeDescriptor("tr(%s)", wif.String(), addrP2TR)
301313

302314
return fmt.Sprintf("bitcoin-cli importdescriptors '[%s,%s,%s]'",
303315
np2wkh, p2wkh, p2tr), nil
@@ -307,8 +319,11 @@ func (d *Descriptors) Trailer(birthdayBlock uint32) string {
307319
return fmt.Sprintf("bitcoin-cli rescanblockchain %d\n", birthdayBlock)
308320
}
309321

310-
func makeDescriptor(format, wif string) string {
322+
func makeDescriptor(format, wif string, address btcutil.Address) string {
311323
descriptor := fmt.Sprintf(format, wif)
312-
return fmt.Sprintf("{\"desc\":\"%s\",\"timestamp\":\"now\"}",
313-
DescriptorSumCreate(descriptor))
324+
return fmt.Sprintf(
325+
"{\"desc\":\"%s\",\"timestamp\":\"now\",\"label\":\"%s\"}",
326+
DescriptorSumCreate(descriptor),
327+
address.String(),
328+
)
314329
}

0 commit comments

Comments
 (0)