diff options
| author | Pieter Wuille <[email protected]> | 2019-02-16 14:18:54 -0800 |
|---|---|---|
| committer | Pieter Wuille <[email protected]> | 2019-05-10 14:22:33 -0700 |
| commit | eaf4f887348a08c620732125ad4430e1a133d434 (patch) | |
| tree | 81dcc32ec90bd4c5ea8b0ada61e348cfd6b4b0d2 /src/script | |
| parent | Merge #15607: [Docs] Release process updates (diff) | |
| download | discoin-eaf4f887348a08c620732125ad4430e1a133d434.tar.xz discoin-eaf4f887348a08c620732125ad4430e1a133d434.zip | |
Abstract out IsSegWitOutput from utxoupdatepsbt
This is not a pure refactor; additional functionality is added in
IsSegWitOutput which lets it recurse into P2SH when a
SigningProvider is provided that knows about the inner script.
Diffstat (limited to 'src/script')
| -rw-r--r-- | src/script/sign.cpp | 16 | ||||
| -rw-r--r-- | src/script/sign.h | 3 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 36dd68a3d..5320dc087 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -505,3 +505,19 @@ FlatSigningProvider Merge(const FlatSigningProvider& a, const FlatSigningProvide ret.origins.insert(b.origins.begin(), b.origins.end()); return ret; } + +bool IsSegWitOutput(const SigningProvider& provider, const CScript& script) +{ + std::vector<valtype> solutions; + auto whichtype = Solver(script, solutions); + if (whichtype == TX_WITNESS_V0_SCRIPTHASH || whichtype == TX_WITNESS_V0_KEYHASH || whichtype == TX_WITNESS_UNKNOWN) return true; + if (whichtype == TX_SCRIPTHASH) { + auto h160 = uint160(solutions[0]); + CScript subscript; + if (provider.GetCScript(h160, subscript)) { + whichtype = Solver(subscript, solutions); + if (whichtype == TX_WITNESS_V0_SCRIPTHASH || whichtype == TX_WITNESS_V0_KEYHASH || whichtype == TX_WITNESS_UNKNOWN) return true; + } + } + return false; +} diff --git a/src/script/sign.h b/src/script/sign.h index f746325b9..e5c0329a6 100644 --- a/src/script/sign.h +++ b/src/script/sign.h @@ -232,4 +232,7 @@ void UpdateInput(CTxIn& input, const SignatureData& data); * Solvability is unrelated to whether we consider this output to be ours. */ bool IsSolvable(const SigningProvider& provider, const CScript& script); +/** Check whether a scriptPubKey is known to be segwit. */ +bool IsSegWitOutput(const SigningProvider& provider, const CScript& script); + #endif // BITCOIN_SCRIPT_SIGN_H |