. Caveat emptor.
Program which connects to a bitcoin node and downloads the first 500 blocks.
from bitcoin import *
import time
net = network()
chandle = None
def receive_inv(inv_packet):
print inv_packet
for inventory in inv_packet.invs:
print inventory.type, inventory.hash
def handle_send_getblocks(ec):
if ec:
# do something
print ec
def create_getblocks_message():
packet = getblocks()
gen_block = genesis_block()
print 'c'
packet.locator_start_hashes.append(hash_block_header(gen_block))
packet.hash_stop.nullify()
return packet
def handle_handshake(ec, host_id):
if ec:
# do something
print ec
return
chandle = host_id
net.subscribe_inv(chandle, receive_inv)
net.send_getblocks(chandle, create_getblocks_message(), handle_send_getblocks)
if __name__ == '__main__':
handshake_connect(net, "localhost", 8333, handle_handshake)
time.sleep(2)
from bitcoin import *
import time
i = net_addr()
i.ip_addr = [1, 2, 3]
print i.ip_addr
print inv_type.block
h = hash_digest([1, 2, 3])
h[12] = 110
print h[12]
vers = version()
vers.version = 100
vers.sub_version_num = "abc"
print vers
# from block 170
pubkey = data_chunk([0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12, 0xa3])
print len(pubkey)
print pubkey
print pubkey_to_address(pubkey)
print genesis_block().merkle
print 'Only', max_money(), 'bitcoins will ever exist'
print original_dialect()
s = script()
o = operation()
o.code = opcode.special
s.push_operation(o)
o.code = opcode.nop
o.data = data_chunk([0xde, 0xad, 0xbe, 0xef])
s.push_operation(o)
o = operation()
o.code = opcode.hash160
s.push_operation(o)
print s
tx = transaction()
print tx
n = network()
def foo(ec, hostid):
if ec:
print ec
print 'connected', hostid
handshake_connect(n, "localhost", 8333, foo)
time.sleep(10)
I'm not too knowledgeable on making bindings, so consider this an experiment.
for those looking for some more general utilities.