Bitcoin Forum
June 19, 2024, 06:28:08 PM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Concatenating two byte arrays (ss << pindex->hashProof << 0x0000000000000000)  (Read 2469 times)
janko33 (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 132


View Profile
August 13, 2014, 08:32:45 PM
Last edit: August 14, 2014, 03:03:58 PM by janko33
 #1

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();
}
       }
janko33 (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 132


View Profile
August 14, 2014, 04:11:02 PM
 #2

studied studied studied and studied and than corrected ;DD

you know where the error is?

here
ssStakeStream.write(Utils.reverseBytes(arrayHashProof));
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!