-
-
Save shirriff/7e2b3cb0d7432175d719 to your computer and use it in GitHub Desktop.
Python functions to create an arbitrary Bitcoin peer-to-peer message, and a version message.
This file contains 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
magic = 0xd9b4bef9 | |
def makeMessage(magic, command, payload): | |
checksum = hashlib.sha256(hashlib.sha256(payload).digest()).digest()[0:4] | |
return struct.pack('L12sL4s', magic, command, len(payload), checksum) + payload | |
def getVersionMsg(): | |
version = 60002 | |
services = 1 | |
timestamp = int(time.time()) | |
addr_me = utils.netaddr(socket.inet_aton("127.0.0.1"), 8333) | |
addr_you = utils.netaddr(socket.inet_aton("127.0.0.1"), 8333) | |
nonce = random.getrandbits(64) | |
sub_version_num = utils.varstr('') | |
start_height = 0 | |
payload = struct.pack('<LQQ26s26sQsL', version, services, timestamp, addr_me, | |
addr_you, nonce, sub_version_num, start_height) | |
return makeMessage(magic, 'version', payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment