Commit f5ce017
committed
descriptor: introduce several Taproot accessors
When working with Taproot descriptors you typically need to do an
annoying (and hard to discover) `match` statement to get the `Tr`
out of the descriptor, and then call accessors on that to get the
actual data out.
Add two new methods to `Descriptor` that directly access the internal
key and the taptree. Document that the actual leaves can be obtained by
calling `.iter` on the taptree.
Next, when a user is trying to sign a Taproot branch, they need to
obtain a TapLeafHash. We have internal code which does this (which I
have pulled into a helper function since there is some room to optimize
it there..) but no exposed code, forcing the user to go digging through
the rust-bitcoin docs to figure it out (including knowing the standard
Taproot leaf version, which is an arcane detail of the sort that
Miniscript otherwise hides).
Add a new method `leaf_hash` on Taproot miniscripts, so that the user
can directly obtain the leaf hashes.
Now you can write e.g.
for script in trdesc.tap_tree_iter() {
let leaf_hash = script.leaf_hash();
// Do whatever you want...
}
vs the previous code which was roughly
let tr = match trdesc {
Descriptor::Tr(ref tr) => tr,
_ => unreachable!("I know this is a Taproot descriptor"),
};
// Or tr.tap_tree().unwrap().iter() in case you miss the weirdly-named
// Tr::iter_scripts
for script in tr.iter_scripts() {
// Hope you know your rust-bitcoin docs by heart, and also that
// .encode is the way to convert a Miniscript to a Script!
let leaf_hash = TapLeafHash::from_script(
LeafVersion::TapScript,
script.encode(),
);
}1 parent 3977d1e commit f5ce017
3 files changed
+69
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
244 | 278 | | |
245 | 279 | | |
246 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
468 | 473 | | |
469 | 474 | | |
470 | 475 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
292 | 300 | | |
293 | 301 | | |
294 | 302 | | |
295 | 303 | | |
296 | 304 | | |
297 | 305 | | |
298 | 306 | | |
299 | | - | |
300 | | - | |
301 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
302 | 313 | | |
303 | 314 | | |
304 | 315 | | |
| |||
311 | 322 | | |
312 | 323 | | |
313 | 324 | | |
314 | | - | |
315 | 325 | | |
316 | 326 | | |
317 | 327 | | |
318 | 328 | | |
319 | | - | |
| 329 | + | |
320 | 330 | | |
321 | 331 | | |
322 | 332 | | |
| |||
344 | 354 | | |
345 | 355 | | |
346 | 356 | | |
347 | | - | |
348 | | - | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
349 | 363 | | |
350 | 364 | | |
351 | 365 | | |
| |||
356 | 370 | | |
357 | 371 | | |
358 | 372 | | |
359 | | - | |
360 | 373 | | |
361 | 374 | | |
362 | 375 | | |
363 | 376 | | |
364 | | - | |
| 377 | + | |
365 | 378 | | |
366 | 379 | | |
367 | 380 | | |
368 | 381 | | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
369 | 389 | | |
370 | 390 | | |
371 | 391 | | |
| |||
0 commit comments