from bitcoin import genesis_block, save_script genblk = genesis_block() assert len(genblk.transactions) == 1 coinbase_tx = genblk.transactions[0] assert len(coinbase_tx.inputs) == 1 coinbase_input = coinbase_tx.inputs[0] input_script = coinbase_input.input_script print input_script, input_script.__class__ raw_block_message = save_script(input_script) print raw_block_message
import bitcoin tx = bitcoin.genesis_block().transactions[0] bitcoin.hash_transaction(tx)
def create_get_blocks_message(): packet = bitcoin.get_blocks() genesis_hash = bitcoin.hash_block_header(bitcoin.genesis_block()) packet.start_hashes.append(genesis_hash) packet.hash_stop = bitcoin.null_hash return packet
def import_finished(error): print "Import finished", error chain.fetch_block_header(0, fetch_finished) chain.fetch_block_header(1000, fetch_finished) print "Import finished2" # start up engine pool = bitcoin.threadpool(1) print pool chain = bitcoin.leveldb_blockchain(pool) chain.start("database", blockchain_start); print 'chain', chain # load the first block first_block = bitcoin.genesis_block() print first_block chain._import(first_block, 0, import_finished) # get some block headers print "fetch block header" chain.fetch_block_header(0, fetch_finished) print "waiting..." #time.sleep(60) time.sleep(3) print "pool.stop" pool.stop()
raw_tx_repr = "010000000187493c4c15c76df9f69ddd7aeb7ffbcddad4b7a979210f19602282d5b9862581000000008a47304402202d9e9f75be9c8a4c4304931b032e1de83fd2c6af2c1154a3d2b885efd5c3bfda02201184139215fb74499eae9c71ae86354c41b4d20b95a6b1fffcb8f1c5f051288101410497d11f5c33adb7c3fed0adc637358279de04f72851b7b93fb4a8655613729047c7e2908966551b5fb7f6899f6c3dd358b57eb20a61b2c9909aa106eac6310f9fffffffff0140420f00000000001976a91407e761706c63b36e5a328fab1d94e9397f40704d88b000000000" raw_tx = bitcoin.data_chunk(raw_tx_repr) print raw_tx print len(raw_tx) ex = bitcoin.satoshi_exporter() tx = ex.load_transaction(raw_tx) print "txhash", bitcoin.hash_transaction(tx) print tx print ex.save_transaction(tx) print len(ex.save_transaction(tx)) assert str(ex.save_transaction(tx)) == raw_tx_repr print 'blk' blk = bitcoin.genesis_block() print bitcoin.hash_block_header(blk) rawblk = ex.save_block(blk) blk2 = ex.load_block(rawblk) print bitcoin.hash_block_header(blk2) print bitcoin.hash_transaction(blk.transactions[0]) print bitcoin.hash_transaction(blk2.transactions[0]) assert str(ex.save_block(blk2)) == str(rawblk) getblocks = bitcoin.get_blocks() getblocks.start_hashes.append(bitcoin.hash_block_header(blk)) getblocks.start_hashes.append(bitcoin.hash_transaction(blk.transactions[0])) getblocks.hash_stop = bitcoin.null_hash rawgb = ex.save_get_blocks(getblocks) gb2 = ex.load_get_blocks(rawgb) print gb2.start_hashes[0]