Add P2WSH destination helper and use it instead of manual hashing

This commit is contained in:
Pieter Wuille
2018-06-17 19:44:50 -07:00
parent eaba1c111e
commit bb582a59c7
5 changed files with 39 additions and 109 deletions

View File

@@ -637,9 +637,7 @@ static UniValue decodescript(const JSONRPCRequest& request)
} else {
// Scripts that are not fit for P2WPKH are encoded as P2WSH.
// Newer segwit program versions should be considered when then become available.
uint256 scriptHash;
CSHA256().Write(script.data(), script.size()).Finalize(scriptHash.begin());
segwitScr = GetScriptForDestination(WitnessV0ScriptHash(scriptHash));
segwitScr = GetScriptForDestination(WitnessV0ScriptHash(script));
}
ScriptPubKeyToUniv(segwitScr, sr, true);
sr.pushKV("p2sh-segwit", EncodeDestination(CScriptID(segwitScr)));