def load_chain(raw_chain):
    chain = []
    loader = bitcoin.satoshi_exporter()
    for raw_blk in raw_chain:
        blk = loader.load_block(bitcoin.data_chunk(raw_blk))
        chain.append(blk)
    return chain
Exemplo n.º 2
0
 def broadcast_transaction(self, request):
     raw_tx = bitcoin.data_chunk(str(request["params"][0]))
     exporter = bitcoin.satoshi_exporter()
     try:
         tx = exporter.load_transaction(raw_tx)
     except RuntimeError:
         response = {"id": request["id"], "result": None,
                     "error": {"message": 
                         "Exception while parsing the transaction data.",
                         "code": -4}}
     else:
         self.backend.protocol.broadcast_transaction(tx)
         tx_hash = str(bitcoin.hash_transaction(tx))
         response = {"id": request["id"], "result": tx_hash, "error": None}
     self.push_response(response)
Exemplo n.º 3
0
 def broadcast_transaction(self, request):
     raw_tx = bitcoin.data_chunk(str(request["params"][0]))
     exporter = bitcoin.satoshi_exporter()
     try:
         tx = exporter.load_transaction(raw_tx)
     except RuntimeError:
         response = {
             "id": request["id"],
             "result": None,
             "error": {
                 "message": "Exception while parsing the transaction data.",
                 "code": -4,
             }
         }
     else:
         self.backend.protocol.broadcast_transaction(tx)
         tx_hash = str(bitcoin.hash_transaction(tx))
         response = {"id": request["id"], "result": tx_hash, "error": None}
     self.push_response(response)
Exemplo n.º 4
0
            # No more inputs left to load
            # This info has finished loading
            info["height"] = None
            info["block_hash"] = "mempool"
        self.finish_if_done()


def payment_history(chain, txpool, membuf, address, handle_finish):
    h = History(chain, txpool, membuf)
    expiry_queue.add(h)
    h.start(address, handle_finish)


if __name__ == "__main__":
    ex = bitcoin.satoshi_exporter()
    tx_a = bitcoin.data_chunk("0100000003d0406a31f628e18f5d894b2eaf4af719906dc61be4fb433a484ed870f6112d15000000008b48304502210089c11db8c1524d8839243803ac71e536f3d876e8265bbb3bc4a722a5d0bd40aa022058c3e59a7842ef1504b1c2ce048f9af2d69bbf303401dced1f68b38d672098a10141046060f6c8e355b94375eec2cc1d231f8044e811552d54a7c4b36fe8ee564861d07545c6c9d5b9f60d16e67d683b93486c01d3bd3b64d142f48af70bb7867d0ffbffffffff6152ed1552b1f2635317cea7be06615a077fc0f4aa62795872836c4182ca0f25000000008b48304502205f75a468ddb08070d235f76cb94c3f3e2a75e537bc55d087cc3e2a1559b7ac9b022100b17e4c958aaaf9b93359f5476aa5ed438422167e294e7207d5cfc105e897ed91014104a7108ec63464d6735302085124f3b7a06aa8f9363eab1f85f49a21689b286eb80fbabda7f838d9b6bff8550b377ad790b41512622518801c5230463dbbff6001ffffffff01c52914dcb0f3d8822e5a9e3374e5893a7b6033c9cfce5a8e5e6a1b3222a5cb010000008c4930460221009561f7206cc98f40f3eab5f3308b12846d76523bd07b5f058463f387694452b2022100b2684ec201760fa80b02954e588f071e46d0ff16562c1ab393888416bf8fcc44014104a7108ec63464d6735302085124f3b7a06aa8f9363eab1f85f49a21689b286eb80fbabda7f838d9b6bff8550b377ad790b41512622518801c5230463dbbff6001ffffffff02407e0f00000000001976a914c3b98829108923c41b3c1ba6740ecb678752fd5e88ac40420f00000000001976a914424648ea6548cc1c4ea707c7ca58e6131791785188ac00000000")
    tx_a = ex.load_transaction(tx_a)
    assert bitcoin.hash_transaction(tx_a) == "e72e4f025695446cfd5c5349d1720beb38801f329a00281f350cb7e847153397"
    tx_b = bitcoin.data_chunk("0100000001e269f0d74b8e6849233953715bc0be3ba6727afe0bc5000d015758f9e67dde34000000008c4930460221008e305e3fdf4420203a8cced5be20b73738a3b51186dfda7c6294ee6bebe331b7022100c812ded044196132f5e796dbf4b566b6ee3246cc4915eca3cf07047bcdf24a9301410493b6ce24182a58fc3bd0cbee0ddf5c282e00c0c10b1293c7a3567e95bfaaf6c9a431114c493ba50398ad0a82df06254605d963d6c226db615646fadd083ddfd9ffffffff020f9c1208000000001976a91492fffb2cb978d539b6bcd12c968b263896c6aacf88ac8e3f7600000000001976a914654dc745e9237f86b5fcdfd7e01165af2d72909588ac00000000")
    tx_b = ex.load_transaction(tx_b)
    assert bitcoin.hash_transaction(tx_b) == "acfda6dbf4ae1b102326bfb7c9541702d5ebb0339bc57bd74d36746855be8eac"

    def blockchain_started(ec, chain):
        print "Blockchain initialisation:", ec

    def store_tx(ec):
        print "Tx", ec

    def finish(result):
        print "Finish"
        if result is None:
Exemplo n.º 5
0

def finish(ec, result):
    print "Finish:", ec
    for line in result:
        for k, v in line.iteritems():
            begin = k + ":"
            print begin, " " * (12 - len(begin)), v
        print


a = bitcoin.async_service(1)
chain = bitcoin.bdb_blockchain(a, "/home/genjix/libbitcoin/database",
                               blockchain_started)
txpool = bitcoin.transaction_pool(a, chain)
txdat = bitcoin.data_chunk("0100000001d6cad920a04acd6c0609cd91fe4dafa1f3b933ac90e032c78fdc19d98785f2bb010000008b483045022043f8ce02784bd7231cb362a602920f2566c18e1877320bf17d4eabdac1019b2f022100f1fd06c57330683dff50e1b4571fb0cdab9592f36e3d7e98d8ce3f94ce3f255b01410453aa8d5ddef56731177915b7b902336109326f883be759ec9da9c8f1212c6fa3387629d06e5bf5e6bcc62ec5a70d650c3b1266bb0bcc65ca900cff5311cb958bffffffff0280969800000000001976a9146025cabdbf823949f85595f3d1c54c54cd67058b88ac602d2d1d000000001976a914c55c43631ab14f7c4fd9c5f153f6b9123ec32c8888ac00000000")
ex = bitcoin.satoshi_exporter()
tx = ex.load_transaction(txdat)


def stored(ec):
    print "mbuff", ec

mbuff = membuf.memory_buffer(a.internal_ptr, chain.internal_ptr,
                             txpool.internal_ptr)
mbuff.receive(tx, stored)
address = "1AA6mgxqSrvJTxRrYrikSnLaAGupVzvx4f"
raw_input()
history.payment_history(a, chain, txpool, mbuff, address, finish)
raw_input()
Exemplo n.º 6
0
            # This info has finished loading
            info["height"] = None
            info["block_hash"] = "mempool"
        self.finish_if_done()


def payment_history(chain, txpool, membuf, address, handle_finish):
    h = History(chain, txpool, membuf)
    expiry_queue.add(h)
    h.start(address, handle_finish)


if __name__ == "__main__":
    ex = bitcoin.satoshi_exporter()
    tx_a = bitcoin.data_chunk(
        "0100000003d0406a31f628e18f5d894b2eaf4af719906dc61be4fb433a484ed870f6112d15000000008b48304502210089c11db8c1524d8839243803ac71e536f3d876e8265bbb3bc4a722a5d0bd40aa022058c3e59a7842ef1504b1c2ce048f9af2d69bbf303401dced1f68b38d672098a10141046060f6c8e355b94375eec2cc1d231f8044e811552d54a7c4b36fe8ee564861d07545c6c9d5b9f60d16e67d683b93486c01d3bd3b64d142f48af70bb7867d0ffbffffffff6152ed1552b1f2635317cea7be06615a077fc0f4aa62795872836c4182ca0f25000000008b48304502205f75a468ddb08070d235f76cb94c3f3e2a75e537bc55d087cc3e2a1559b7ac9b022100b17e4c958aaaf9b93359f5476aa5ed438422167e294e7207d5cfc105e897ed91014104a7108ec63464d6735302085124f3b7a06aa8f9363eab1f85f49a21689b286eb80fbabda7f838d9b6bff8550b377ad790b41512622518801c5230463dbbff6001ffffffff01c52914dcb0f3d8822e5a9e3374e5893a7b6033c9cfce5a8e5e6a1b3222a5cb010000008c4930460221009561f7206cc98f40f3eab5f3308b12846d76523bd07b5f058463f387694452b2022100b2684ec201760fa80b02954e588f071e46d0ff16562c1ab393888416bf8fcc44014104a7108ec63464d6735302085124f3b7a06aa8f9363eab1f85f49a21689b286eb80fbabda7f838d9b6bff8550b377ad790b41512622518801c5230463dbbff6001ffffffff02407e0f00000000001976a914c3b98829108923c41b3c1ba6740ecb678752fd5e88ac40420f00000000001976a914424648ea6548cc1c4ea707c7ca58e6131791785188ac00000000"
    )
    tx_a = ex.load_transaction(tx_a)
    assert bitcoin.hash_transaction(
        tx_a
    ) == "e72e4f025695446cfd5c5349d1720beb38801f329a00281f350cb7e847153397"
    tx_b = bitcoin.data_chunk(
        "0100000001e269f0d74b8e6849233953715bc0be3ba6727afe0bc5000d015758f9e67dde34000000008c4930460221008e305e3fdf4420203a8cced5be20b73738a3b51186dfda7c6294ee6bebe331b7022100c812ded044196132f5e796dbf4b566b6ee3246cc4915eca3cf07047bcdf24a9301410493b6ce24182a58fc3bd0cbee0ddf5c282e00c0c10b1293c7a3567e95bfaaf6c9a431114c493ba50398ad0a82df06254605d963d6c226db615646fadd083ddfd9ffffffff020f9c1208000000001976a91492fffb2cb978d539b6bcd12c968b263896c6aacf88ac8e3f7600000000001976a914654dc745e9237f86b5fcdfd7e01165af2d72909588ac00000000"
    )
    tx_b = ex.load_transaction(tx_b)
    assert bitcoin.hash_transaction(
        tx_b
    ) == "acfda6dbf4ae1b102326bfb7c9541702d5ebb0339bc57bd74d36746855be8eac"

    def blockchain_started(ec, chain):
        print "Blockchain initialisation:", ec
Exemplo n.º 7
0
         0, 0, 255, 255, 127, 0, 0, 1]
    vers.address_me.port = 8333
    vers.address_you.services = 1
    vers.address_you.ip = \
        [0, 0, 0, 0, 0, 0, 0, 0, 
         0, 0, 255, 255, 127, 0, 0, 1]
    vers.address_you.port = 8333
    vers.user_agent = "/libbitcoin:0.4/example:1/";
    vers.start_height = 0
    vers.nonce = 42
    channel.send_version(vers, handle_send)
    chan = channel
    channel.subscribe_version(read_version_reply)
    print 'connect'

d = bitcoin.data_chunk("001212")
print d
h = bitcoin.hash_digest("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")
print h
if h == "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f":
    print 'Yes'
print len(h)

tx = bitcoin.transaction()
print bitcoin.hash_transaction(tx)

netaddr = bitcoin.network_address()
print netaddr.ip

s = bitcoin.script()
o = bitcoin.operation()
import bitcoin

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)