Skip to content

Instantly share code, notes, and snippets.

@humbdrag
Last active January 27, 2022 20:59
Show Gist options
  • Save humbdrag/ec6de05656ae13ace7f7cc68db4ca182 to your computer and use it in GitHub Desktop.
Save humbdrag/ec6de05656ae13ace7f7cc68db4ca182 to your computer and use it in GitHub Desktop.
Insert Coinbase transaction pyminer
from essential_generators import DocumentGenerator
import hashlib
def sha256_double_hash(target: str) -> str:
return hashlib.sha256(
hashlib.sha256(target).digest()
).digest()[::-1]
coinbase = {}
coinbase_text: str = DocumentGenerator().sentence().encode().hex()
coinbase['data'] = create_coinbase(
coinbase_value=block_template['coinbasevalue'],
coinbase_text=coinbase_text,
block_height=block_template['height'],
wallet_address=wallet_address,
)
coinbase['hash'] = sha256_double_hash(bytes.fromhex(coinbase['data'])).hex()
block_template['transactions'].insert(0, coinbase)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment