I want to hash a block header in C++ but dont know how.
Im just using a test block at the moment, so that I know what the expected outcome is. https://www.blockchain.com/btc/block/669892
I have a function which formats the block header into the hex string of 0000ff3fd90c0dfca35c8738aa92e1c5bdf706ba14eaafbb379206000000000000000000ad66d8cda0330c3af011ba6b7bc705789767c55a72a818685b3e06a0b8b9a2b054e82260b9210d17099976a6
Now, im struggling to properly hash this to the expected 000000000000000000064ec839564cc03166184f0a404d82cad9c655f714d886
static void calcHash(std::string hash){
CryptoPP::SHA256 hash;
std::string digest;
CryptoPP::StringSource(data, true,
new CryptoPP::HashFilter(hash, new
CryptoPP::HexEncoder(new CryptoPP::StringSink(digest)
)));
std::cout << "digest: " << digest << std::endl;
CryptoPP::SHA256 hash2;
std::string digest2;
CryptoPP::StringSource(digest, true,
new CryptoPP::HashFilter(hash2, new
CryptoPP::HexEncoder(new CryptoPP::StringSink(digest2)
)));
std::cout << "digest2: " << digest2 << std::endl;
return digest2;
}
When I pass that header through this function, i do not get the expected.
How do I get the expected hash from my formatted header using c++?
d886
isn't the hash of the header, it's the hash of the whole block.0000ff3fd...
?86d814f755c6d9ca824d400a4f186631c04c5639c84e06000000000000000000