Author

Topic: Creation of <20-byte hash of redeem Script> in a P2SH Transaction (Read 934 times)

staff
Activity: 3374
Merit: 6530
Just writing some code
Thanks for the help!

I created the redeem Script as follows:
Script redeemScript=scriptbuilder.createRedeemScript(2, pubkeys);

Then in order to get the bytes of the script i used the :
byte[] bytesFromScript=myScript.getProgram();

and finally in got the hash of the Script using the  RIPEMD160(SHA256(bytesFromScript)) procedure.

The Script class doesn't have any other function to get the bytes so i used the getProgram() function.
Am i wrong to this?


 
That should be right.
newbie
Activity: 11
Merit: 0
Thanks for the help!

I created the redeem Script as follows:
Script redeemScript=scriptbuilder.createRedeemScript(2, pubkeys);

Then in order to get the bytes of the script i used the :
byte[] bytesFromScript=myScript.getProgram();

and finally in got the hash of the Script using the  RIPEMD160(SHA256(bytesFromScript)) procedure.

The Script class doesn't have any other function to get the bytes so i used the getProgram() function.
Am i wrong to this?


 
staff
Activity: 3374
Merit: 6530
Just writing some code
The hash is the hash of the redeem script encoded as hex bytes. You can build a script using the ScriptBuilder class and then get the bytes of the script and perform the sha256 and ripemd160 hashes on those bytes to get the hash.
newbie
Activity: 11
Merit: 0
Hello.

According to this example:

Redeem Script: 2 PubKey1 PubKey2 PubKey3 PubKey4 PubKey5 5 OP_CHECKMULTISIG

Locking Script: OP_HASH160 <20-byte hash of redeem script> OP_EQUAL

Unlocking Script: Sig1 Sig2 redeem script

I want to calculate the <20-byte hash of redeem script> with BitcoinJ but i don't know how to do it.

This <20-byte hash of redeem script> is the result of :

RIPEMD160(SHA256(PubKey1.getPublicKeyAsHex() || PubKey2.getPublicKeyAsHex() || PubKey3.getPublicKeyAsHex() || PubKey4.getPublicKeyAsHex() || PubKey5.getPublicKeyAsHex())) or RIPEMD160(SHA256(input))Huh

The input (which is String type) from above is the concatenation of each public key of all participants in the redeem script.

And if <20-byte hash of redeem script> it is not the result that i mentioned above...how can i estimate this hash with BitcoinJ?

Thanks in advance.
Jump to: