diff --git a/code/addr.cpp b/code/addr.cpp index 9efea583..9c6fac5e 100644 --- a/code/addr.cpp +++ b/code/addr.cpp @@ -3,8 +3,10 @@ int main() { // Private secret key. - bc::ec_secret secret = bc::decode_hash( + bc::ec_secret secret; + bool success = bc::decode_hash(secret, "038109007313a5807b2eccc082c8c3fbb988a973cacf1a7df9ce725c31b14776"); + assert(success); // Get public key. bc::ec_point public_key = bc::secret_to_public_key(secret); std::cout << "Public key: " << bc::encode_hex(public_key) << std::endl; diff --git a/code/merkle.cpp b/code/merkle.cpp index 605e24f4..52f983fe 100644 --- a/code/merkle.cpp +++ b/code/merkle.cpp @@ -1,6 +1,6 @@ #include -bc::hash_digest create_merkle(bc::hash_digest_list& merkle) +bc::hash_digest create_merkle(bc::hash_list& merkle) { // Stop if hash list is empty. if (merkle.empty()) @@ -18,7 +18,7 @@ bc::hash_digest create_merkle(bc::hash_digest_list& merkle) assert(merkle.size() % 2 == 0); // New hash list. - bc::hash_digest_list new_merkle; + bc::hash_list new_merkle; // Loop through hashes 2 at a time. for (auto it = merkle.begin(); it != merkle.end(); it += 2) { @@ -47,13 +47,21 @@ bc::hash_digest create_merkle(bc::hash_digest_list& merkle) return merkle[0]; } +// Convert hex string to hash bytes. +bc::hash_digest get_hash(const std::string& value) +{ + bc::hash_digest result; + bool success = bc::decode_hash(result, value); + return result; +} + int main() { // Replace these hashes with ones from a block to reproduce the same merkle root. - bc::hash_digest_list tx_hashes{{ - bc::decode_hash("0000000000000000000000000000000000000000000000000000000000000000"), - bc::decode_hash("0000000000000000000000000000000000000000000000000000000000000011"), - bc::decode_hash("0000000000000000000000000000000000000000000000000000000000000022"), + bc::hash_list tx_hashes{{ + get_hash("0000000000000000000000000000000000000000000000000000000000000000"), + get_hash("0000000000000000000000000000000000000000000000000000000000000011"), + get_hash("0000000000000000000000000000000000000000000000000000000000000022"), }}; const bc::hash_digest merkle_root = create_merkle(tx_hashes); std::cout << "Result: " << bc::encode_hex(merkle_root) << std::endl;