diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2018-06-17 19:44:50 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2018-06-17 19:44:50 -0700 |
commit | bb582a59c7532b0e4f647d9dfe50f0d816e81427 (patch) | |
tree | 4961859632aa54894a57b87cdde4af6e2bb08c86 /src/script | |
parent | eaba1c111e9671cdd6faf4b96c39341bbdd41632 (diff) |
Add P2WSH destination helper and use it instead of manual hashing
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/standard.cpp | 10 | ||||
-rw-r--r-- | src/script/standard.h | 1 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/script/standard.cpp b/src/script/standard.cpp index d9269d6147..f0b2c62a91 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -5,6 +5,7 @@ #include <script/standard.h> +#include <crypto/sha256.h> #include <pubkey.h> #include <script/script.h> #include <util.h> @@ -18,6 +19,11 @@ unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY; CScriptID::CScriptID(const CScript& in) : uint160(Hash160(in.begin(), in.end())) {} +WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in) +{ + CSHA256().Write(in.data(), in.size()).Finalize(begin()); +} + const char* GetTxnOutputType(txnouttype t) { switch (t) @@ -329,9 +335,7 @@ CScript GetScriptForWitness(const CScript& redeemscript) return GetScriptForDestination(WitnessV0KeyHash(vSolutions[0])); } } - uint256 hash; - CSHA256().Write(&redeemscript[0], redeemscript.size()).Finalize(hash.begin()); - return GetScriptForDestination(WitnessV0ScriptHash(hash)); + return GetScriptForDestination(WitnessV0ScriptHash(redeemscript)); } bool IsValidDestination(const CTxDestination& dest) { diff --git a/src/script/standard.h b/src/script/standard.h index 4922b7236b..1380030871 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -77,6 +77,7 @@ struct WitnessV0ScriptHash : public uint256 { WitnessV0ScriptHash() : uint256() {} explicit WitnessV0ScriptHash(const uint256& hash) : uint256(hash) {} + explicit WitnessV0ScriptHash(const CScript& script); using uint256::uint256; }; |