Author

Topic: Concatenating two byte arrays (ss << pindex->hashProof << 0x0000000000000000) (Read 2486 times)

full member
Activity: 145
Merit: 132
studied studied studied and studied and than corrected ;DD

you know where the error is?

here
ssStakeStream.write(Utils.reverseBytes(arrayHashProof));
full member
Activity: 145
Merit: 132
How do I do this in bitcoinj?

0x0000000000000000 is uint64_t

am stuck on this for 2 weeks Sad
I think somebody from here can help me to see what did I do wrong
or can you point me to.

c++ code
ss << pindex->hashProof << 0x0000000000000000;
uint256 hashSelection = Hash(ss.begin(), ss.end());

c++ code

How do I port these 2 lines to java using bitcoinj?

can I use BigInteger.compareTo for comparing hashSelection(uint256) ?
Can somebody help me?

This is my attempt but I think it's wrong!

for example for hashProof = 1faef25dec4fbcf906e6242621df2c183bf232f263d0ba5b101911e4563
I get hashSelection.toString(16)  
f1d854c7a268dcebc4b40a9ef954300f681a56796621469c63d643e29f7e7a81
but I should get        
bb245d8baac1fd953cc6a0a6ec6ea6339d2ab755ebbb3801cd2c4c7268f5bd5e
 
Code:
//256 = 32, 64 = 8
byte[] arrayHashProof  = pindex.getHeader().getHash().toBigInteger().toByteArray();
// CDataStream ss(SER_GETHASH, 0);
ByteArrayOutputStream ssStakeStream = new UnsafeByteArrayOutputStream(32 + 8);

//ss << pindex->hashProof << 0x0000000000000000;
try {
ssStakeStream.write(arrayHashProof);
Utils.uint64ToByteStreamLE(BigInteger.valueOf(0x0000000000000000), ssStakeStream);

        //uint256 hashSelection = Hash(ss.begin(), ss.end());
sha256HashSelection = new Sha256Hash(Utils.reverseBytes(doubleDigest(ssStakeStream.toByteArray())));
hashSelection = sha256HashSelection.toBigInteger();

} catch (IOException e) {
e.printStackTrace();
} finally{
try {
ssStakeStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
       }
Jump to: