Im trying to understand how to obtain the p2SH address when decoding an output script.
r.push_back(Pair("p2sh", CBitcoinAddress(CScriptID(script)).ToString()));
As far as I understand CScriptID is the hash160 of the script.
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.
Sign up to join this communityIm trying to understand how to obtain the p2SH address when decoding an output script.
r.push_back(Pair("p2sh", CBitcoinAddress(CScriptID(script)).ToString()));
As far as I understand CScriptID is the hash160 of the script.
So, a P2SH scriptPubKey looks like this:
OP_HASH160 <20 byte script hash> OP_EQUAL
Serialized, in hex, that looks like:
17a9140000000000000000000000000000000000000087
^ ScriptPubkey len
^ OP_HASH160
^ Data element len
^ Data element
^ OP_EQUAL
where the zeros can be any byte.
How does that transform into an address starting with 3? You transform it the same way you would a normal Bitcoin address, but with a different version byte. Instead of 00
, you would use 05
.
See also the P2SH address specification.
OP_HASH160 <hash> OP_EQUAL
and bare multisig looks like <something> OP_CHECKMULTISIGVERIFY
– Nick ODell
Sep 6 '16 at 23:39