def __init__(self): # Create 3 thread-pools each with 1 thread self.network_service = bitcoin.async_service(1) self.disk_service = bitcoin.async_service(1) self.mempool_service = bitcoin.async_service(1) self.hosts = bitcoin.hosts(self.network_service) self.handshake = bitcoin.handshake(self.network_service) self.network = bitcoin.network(self.network_service) self.protocol = bitcoin.protocol(self.network_service, self.hosts, self.handshake, self.network) db_prefix = "/home/genjix/libbitcoin/database" self.blockchain = bitcoin.bdb_blockchain(self.disk_service, db_prefix, self.blockchain_started) self.poller = bitcoin.poller(self.mempool_service, self.blockchain) self.transaction_pool = \ bitcoin.transaction_pool(self.mempool_service, self.blockchain) self.protocol.subscribe_channel(self.monitor_tx) self.session = \ bitcoin.session(self.network_service, self.hosts, self.handshake, self.network, self.protocol, self.blockchain, self.poller, self.transaction_pool) self.session.start(self.handle_start) self.memory_buffer = \ membuf.memory_buffer(self.mempool_service.internal_ptr, self.blockchain.internal_ptr, self.transaction_pool.internal_ptr)
import bitcoin, trace_tx def blockchain_started(ec, chain): print "Blockchain initialisation:", ec def handle_tx(ec, tx): if ec: print ec trace_tx.trace_tx(service.internal_ptr, chain.internal_ptr, tx, finish) def finish(ec, result): print ec print result service = bitcoin.async_service(1) chain = bitcoin.bdb_blockchain(service, "/home/genjix/libbitcoin/database", blockchain_started) chain.fetch_transaction( bitcoin.hash_digest("16e3e3bfbaa072e33e6a9be1df7a13ecde5ad46a8d4d4893dbecaf0c0aeeb842"), handle_tx) raw_input()
import bitcoin import trace_tx def blockchain_started(ec, chain): print "Blockchain initialisation:", ec def handle_tx(ec, tx): if ec: print ec trace_tx.trace_tx(service.internal_ptr, chain.internal_ptr, tx, finish) def finish(ec, result): print ec print result if __name__ == '__main__': service = bitcoin.async_service(1) chain = bitcoin.bdb_blockchain(service, "/home/genjix/libbitcoin/database", blockchain_started) chain.fetch_transaction( bitcoin.hash_digest( "16e3e3bfbaa072e33e6a9be1df7a13ecde5ad46a8d4d4893dbecaf0c0aeeb842" ), handle_tx) raw_input()
if not [empty_in for empty_in in info["inputs"] if empty_in is None]: with statement_line.lock: if info["is_input"] == 1: statement_line.input_loaded = info else: statement_line.output_loaded = info self.finish_if_done() def payment_history(chain, address, handle_finish): ph = PaymentHistory(chain) expiry_queue.add(ph) ph.run(address, handle_finish) if __name__ == "__main__": def finish(result): print result def last(ec, depth): print "D:", depth service = bitcoin.async_service(1) prefix = "/home/genjix/libbitcoin/database" chain = bitcoin.bdb_blockchain(service, prefix) chain.fetch_last_depth(last) address = "1Pbn3DLXfjqF1fFV9YPdvpvyzejZwkHhZE" print "Looking up", address payment_history(chain, address, finish) raw_input()
for line in result: for k, v in line.iteritems(): begin = k + ":" print begin, " " * (12 - len(begin)), v print class FakeMonitor: def tx_stored(self, tx): pass def tx_confirmed(self, tx): pass service = bitcoin.async_service(1) prefix = "/home/genjix/libbitcoin/database" chain = bitcoin.bdb_blockchain(service, prefix, blockchain_started) txpool = bitcoin.transaction_pool(service, chain) membuf = MemoryPoolBuffer(txpool, chain, FakeMonitor()) membuf.recv_tx(tx_a, store_tx) membuf.recv_tx(tx_b, store_tx) txdat = bitcoin.data_chunk("0100000001d6cad920a04acd6c0609cd91fe4dafa1f3b933ac90e032c78fdc19d98785f2bb010000008b483045022043f8ce02784bd7231cb362a602920f2566c18e1877320bf17d4eabdac1019b2f022100f1fd06c57330683dff50e1b4571fb0cdab9592f36e3d7e98d8ce3f94ce3f255b01410453aa8d5ddef56731177915b7b902336109326f883be759ec9da9c8f1212c6fa3387629d06e5bf5e6bcc62ec5a70d650c3b1266bb0bcc65ca900cff5311cb958bffffffff0280969800000000001976a9146025cabdbf823949f85595f3d1c54c54cd67058b88ac602d2d1d000000001976a914c55c43631ab14f7c4fd9c5f153f6b9123ec32c8888ac00000000") req = {"id": 110, "params": ["1GULoCDnGjhfSWzHs6zDzBxbKt9DR7uRbt"]} ex = bitcoin.satoshi_exporter() tx = ex.load_transaction(txdat) time.sleep(4) membuf.recv_tx(tx, store_tx) raw_input() address = "1Jqu2PVGDvNv4La113hgCJsvRUCDb3W65D", "1GULoCDnGjhfSWzHs6zDzBxbKt9DR7uRbt" #address = "1Pbn3DLXfjqF1fFV9YPdvpvyzejZwkHhZE"
with statement_line.lock: if info["is_input"] == 1: statement_line.input_loaded = info else: statement_line.output_loaded = info self.finish_if_done() def payment_history(chain, address, handle_finish): ph = PaymentHistory(chain) expiry_queue.add(ph) ph.run(address, handle_finish) if __name__ == "__main__": def finish(result): print result def last(ec, depth): print "D:", depth service = bitcoin.async_service(1) prefix = "/home/genjix/libbitcoin/database" chain = bitcoin.bdb_blockchain(service, prefix) chain.fetch_last_depth(last) address = "1Pbn3DLXfjqF1fFV9YPdvpvyzejZwkHhZE" print "Looking up", address payment_history(chain, address, finish) raw_input()
import bitcoin def start_polling(ec, node, poll): if ec: print ec return poll.query(node) if __name__ == "__main__": s1 = bitcoin.async_service(1) s2 = bitcoin.async_service(1) chain = bitcoin.bdb_blockchain(s1, "database") poll = bitcoin.poller(chain) net = bitcoin.network(s2) hs = bitcoin.handshake(s2) hs.connect(net, "localhost", 8333, bitcoin.bind(start_polling, bitcoin._1, bitcoin._2, poll)) raw_input()
for line in result: for k, v in line.iteritems(): begin = k + ":" print begin, " " * (12 - len(begin)), v print class FakeMonitor: def tx_stored(self, tx): pass def tx_confirmed(self, tx): pass service = bitcoin.async_service(1) prefix = "/home/genjix/libbitcoin/database" chain = bitcoin.bdb_blockchain(service, prefix, blockchain_started) txpool = bitcoin.transaction_pool(service, chain) membuf = MemoryPoolBuffer(txpool, chain, FakeMonitor()) membuf.recv_tx(tx_a, store_tx) membuf.recv_tx(tx_b, store_tx) txdat = bitcoin.data_chunk( "0100000001d6cad920a04acd6c0609cd91fe4dafa1f3b933ac90e032c78fdc19d98785f2bb010000008b483045022043f8ce02784bd7231cb362a602920f2566c18e1877320bf17d4eabdac1019b2f022100f1fd06c57330683dff50e1b4571fb0cdab9592f36e3d7e98d8ce3f94ce3f255b01410453aa8d5ddef56731177915b7b902336109326f883be759ec9da9c8f1212c6fa3387629d06e5bf5e6bcc62ec5a70d650c3b1266bb0bcc65ca900cff5311cb958bffffffff0280969800000000001976a9146025cabdbf823949f85595f3d1c54c54cd67058b88ac602d2d1d000000001976a914c55c43631ab14f7c4fd9c5f153f6b9123ec32c8888ac00000000" ) req = {"id": 110, "params": ["1GULoCDnGjhfSWzHs6zDzBxbKt9DR7uRbt"]} ex = bitcoin.satoshi_exporter() tx = ex.load_transaction(txdat) time.sleep(4) membuf.recv_tx(tx, store_tx) raw_input()