This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| submission_str = create_submission_str(block_template) | |
| # Define parameters for the RPC. | |
| parameters = { | |
| "host": "127.0.0.1", | |
| "port": "8332", | |
| "rpcuser": "Your Username", | |
| "rpcpass": "Your Password", | |
| "rpcurl": "http://127.0.0.1:8332" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create_submission_str(block: Dict) -> str: | |
| submission = ( | |
| calc_block_header(block).hex() | |
| + get_le_var_hex(len(block['transactions'])) | |
| ) | |
| for tx in block['transactions']: | |
| submission += tx['data'] | |
| return submission |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| block_template['merkleroot'] = calc_merkle_root( | |
| [transaction['hash'] for transaction in block_template['transactions']] | |
| ) | |
| block_template['nonce'] = 0 | |
| block_header = calc_block_header(block_template) | |
| block_hash = sha256_double_hash(block_header) | |
| block_hash < target_hash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calc_block_header(block: Dict) -> bytes: | |
| return ( | |
| struct.pack("<L", block["version"]) | |
| + bytes.fromhex(block["previousblockhash"])[::-1] | |
| + bytes.fromhex(block["merkleroot"])[::-1] | |
| + struct.pack("<L", block["curtime"]) | |
| + bytes.fromhex(block["bits"])[::-1] | |
| + struct.pack("<L", block["nonce"]) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calc_merkle_root(transactions: List[str]) -> str: | |
| # Convert transactions into big-endian bytes. | |
| be_hashes = [ | |
| bytes.fromhex(transaction)[::-1] | |
| for transaction in transactions | |
| ] | |
| # We combine the hashes pairwise until there is only 1 left. | |
| while len(be_hashes) > 1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from essential_generators import DocumentGenerator | |
| import hashlib | |
| def sha256_double_hash(target: str) -> str: | |
| return hashlib.sha256( | |
| hashlib.sha256(target).digest() | |
| ).digest()[::-1] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_le_hex(value: int, width: int) -> str: | |
| return value.to_bytes(width, byteorder='little').hex() | |
| def get_le_var_hex(value: int) -> str: | |
| if value < 0xfd: | |
| return get_le_hex(value, 1) | |
| if value <= 0xffff: | |
| return "fd" + get_le_hex(value, 2) | |
| if value <= 0xffffffff: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calc_target(bits: str) -> bytes: | |
| """ | |
| Decompress the target from a compact format. | |
| """ | |
| bits = bytes.fromhex(bits) | |
| # Extract the parts. | |
| byte_length = bits[0] - 3 | |
| significand = bits[1:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import base64 | |
| import json | |
| import random | |
| import urllib.request | |
| import urllib.error | |
| import urllib.parse | |
| # Define parameters for the RPC. | |
| parameters = { | |
| "host": "127.0.0.1", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git clone [email protected]:bitcoin/bitcoin.git | |
| cd bitcoin/share/rpcauth | |
| rpcauth.py [Your Username] [Your Password] |
NewerOlder