From e18576b1219a718c80d1a6f94ae314c5ebea1f55 Mon Sep 17 00:00:00 2001 From: Samuel Dobson Date: Sat, 22 Feb 2020 07:57:56 +1300 Subject: [PATCH] Merge #18034: Get the OutputType for a descriptor 7e80f646b24a2abf3c031a649bcc706a695f80da Get the OutputType for a descriptor (Andrew Chow) Pull request description: Adds a `GetOutputType()` method to get the OutputType of a descriptor. Some descriptors don't have a determinate OutputType, so we actually use an `Optional`. For descriptors with indeterminate OutputType, we return `nullopt`. `addr()` and `raw()` use OutputTypes as determined by the CTxDestination they have. For simplicity, `ScriptHash` destinations are `LEGACY` even though they could be `P2SH_SEGWIT`. `combo()`, `pk()`, and `multi()` are `nullopt` as they either don't have an OutputType or they have multiple. `DescriptorImpl` defaults to `nullopt`. `pkh()` is `LEGACY` as expected `wpkh()` and `wsh()` are `BECH32` as expected. `sh()` checks whether the sub-descriptor is `BECH32`. If so, it is `P2SH_SEGWIT`. Otherwise it is `LEGACY`. The descriptor tests are updated to check the OutputType too. ACKs for top commit: fjahr: ACK 7e80f646b24a2abf3c031a649bcc706a695f80da meshcollider: utACK 7e80f646b24a2abf3c031a649bcc706a695f80da instagibbs: cursory ACK https://github.com/bitcoin/bitcoin/pull/18034/commits/7e80f646b24a2abf3c031a649bcc706a695f80da Sjors: Code review ACK 7e80f646b24a2abf3c031a649bcc706a695f80da jonatack: ACK 7e80f64 code review/build/tests Tree-SHA512: c5a813447b62e982435e1c948066f8d6c148c9ebffb0a5eb5a9028b173b01d5ead2f076a5ca3f7f37698538baa346f82a977ee48f583d89cb4e5ebd9111b2341 --- src/outputtype.h | 5 ++++ src/script/descriptor.cpp | 43 +++++++++++++++++++++++---- src/script/descriptor.h | 5 ++++ src/test/descriptor_tests.cpp | 55 ++++++++++++++++++----------------- 4 files changed, 77 insertions(+), 31 deletions(-) diff --git a/src/outputtype.h b/src/outputtype.h index 17b4d36d95..e8765cc163 100644 --- a/src/outputtype.h +++ b/src/outputtype.h @@ -9,6 +9,11 @@ #include