Skip to content

Instantly share code, notes, and snippets.

@volbil
Created November 10, 2019 17:15
Show Gist options
  • Save volbil/d4dfac09bdd49970b5d878d886a9b1e2 to your computer and use it in GitHub Desktop.
Save volbil/d4dfac09bdd49970b5d878d886a9b1e2 to your computer and use it in GitHub Desktop.
import hashlib
import struct
header = {
"version": 2,
"prev_block": "000000000000000117c80378b8da0e33559b5997f2ad55e2f7d18ec1975b9717",
"merkle_root": "871714dcbae6c8193a2bb9b2a69fe1c0440399f38d94b3a0f1b447275a29978a",
"timestamp": 1392872245,
"bits": 419520339,
"nonce": 856192328
}
raw_header = (struct.pack("<L", header["version"]) +
bytearray.fromhex(header["prev_block"])[::-1] +
bytearray.fromhex(header["merkle_root"])[::-1] +
struct.pack("<LLL", header["timestamp"], header["bits"], header["nonce"]))
print(hashlib.sha256(hashlib.sha256(raw_header).digest()).digest()[::-1].hex())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment