I have same problem whit create a double sha256 of the transactions and blocks with C++.
The hash block it is created with the concatenation of these data,
version + previusBlock + merkleRoot + timeStamp + bit + nonce
In the hash block is not necessary to include the all data raw transaction because is are include in the merkleRoot, right?
For create, hash transaction is create whit the concatenation of these data, versionRawTransaction + output of the transaction input + scriptSing + sequences transaction input + cAmmount transaction output + publicKeyScript + lockTime raw transaction
Or are include the data for saving the variable structure? in this method
numberRawTransactions + versionRawTransaction + numbarTransactionInput + output of the transaction input + scriptLenght + scriptSing + sequences transaction input + numbarTransactionOutput + cAmmount transaction output + publicKeyScriptLenght + publicKeyScript + lockTime raw transaction
Now I've tried to apply this theory in my C ++ program but can't get the desired hash. Can you help me?
This is the my test code
TEST(hash_test, first_test_double_sha_bit_genesi_block_bitcoin_crypolibrary)
{
//Init logger
FLAGS_minloglevel = 0;
FLAGS_logtostderr = true;
google::SetLogDestination(google::GLOG_WARNING, "/home/vincenzo/Github/SpyCblock/test/log/first_test_sha_not_on_bitcoin_protocolo.log");
string version = "01000000";
string previusBlock = "0000000000000000000000000000000000000000000000000000000000000000";
string merkleRoot = "3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a";
string timeStamp = "29ab5f49";
string bit = "ffff001d";
string nonce = "1dac2b7c";
stringstream stream;
stream << version << previusBlock << merkleRoot << timeStamp << bit << nonce;
Bytes byte = asciiBytes(stream.str().c_str());
Sha256Hash shaHash = Sha256::getDoubleHash(byte.data(), byte.size());
LOG(INFO) << "The hash genesi block converting with double sha256: " << shaHash.ToString();
ASSERT_EQ(shaHash.ToString(), "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f");
}
but I get this result 46f4d3f53251d05ab58a3f8925ce7023f2115dc38468ec78521c7d0e1dc7bd19
Since I know practically nothing in cryptography in practice, I relied on this library where I use this type of data here that makes the double sha256 Find here
Sorry for my terrible English but I'm learning