Esempio n. 1
0
def start(
):  # wait : thread add_block(txs)   txs = []   packing function >1MB or no tx verify if tx are valid
    couch = couchdb.Server("http://127.0.0.1:5984")
    try:
        couch.delete('block_chain')
    except:
        pass
    db = DB("http://127.0.0.1:5984")

    bc = BlockChain()  # only one blockchain called bc
    utxo_set = UTXOSet()
    utxo_set.reindex(bc)

    tcpserver = TCPServer()
    tcpserver.listen()
    tcpserver.run()

    rpc = RPCServer(export_instance=Cli())
    rpc.start(False)

    p2p = P2p()
    server = PeerServer()
    server.run(p2p)
    p2p.run()

    time.sleep(60)
    t1 = threading.Thread(target=finding_new_block, args=())
    t1.start()
Esempio n. 2
0
def start():
    bc = BlockChain()
    utxo_set = UTXOSet()
    utxo_set.reindex(bc)

    tcpserver = TCPServer()
    tcpserver.listen()
    tcpserver.run()

    rpc = RPCServer(export_instance=Cli())
    rpc.start(False)

    p2p = P2p()
    server = PeerServer()
    server.run(p2p)
    p2p.run()
Esempio n. 3
0
def start(
):  # wait : thread add_block(txs)   txs = []   packing function >1MB or no tx verify if tx are valid
    couch = couchdb.Server("http://127.0.0.1:5984")
    try:
        couch.delete('block_chain')
    except:
        pass
    db = DB("http://127.0.0.1:5984")

    bc = BlockChain()  # only one blockchain called bc
    utxo_set = UTXOSet()
    utxo_set.reindex(bc)

    tcpserver = TCPServer()
    tcpserver.listen()
    tcpserver.run()

    rpc = RPCServer(export_instance=Cli())
    rpc.start(False)

    p2p = P2p()
    server = PeerServer()
    server.run(p2p)
    p2p.run()

    time.sleep(30)  # automatically create a genesis block
    w1 = Wallet.generate_wallet()
    ws = Wallets()
    ws[w1.address] = w1
    ws.save()
    tx = bc.coin_base_tx(w1.address)
    bc.new_genesis_block(tx)
    fo = open("address.txt", "w")
    fo.truncate()
    fo.write(w1.address)  # save the address of the genesis block
    fo.write("\n")

    w2 = Wallet.generate_wallet()  # create another wallet to send transaction
    ws[w2.address] = w2
    ws.save()
    fo.write(w2.address)
    fo.close()
Esempio n. 4
0
def start(
):  # wait : thread add_block(txs)   txs = []   packing function >1MB or no tx verify if tx are valid
    couch = couchdb.Server("http://127.0.0.1:5984")
    try:
        couch.delete('block_chain')
    except:
        pass
    env_dist = os.environ
    db_url1 = "http://couchdb"
    db_url1 += env_dist.get('DB_URL')
    db_url1 += ":5984"
    db = DB(db_url1)

    bc = BlockChain()  # only one blockchain called bc
    utxo_set = UTXOSet()
    utxo_set.reindex(bc)

    try:
        f = open('address.txt', 'r')
        addrs = []
        for line in f:
            addrs.append(line[:34])
        f.close()
        tx = bc.coin_base_tx(addrs[0])
        bc.new_genesis_block(tx)
    except:
        pass

    tcpserver = TCPServer()
    tcpserver.listen()
    tcpserver.run()

    rpc = RPCServer(export_instance=Cli())
    rpc.start(False)

    t2 = threading.Thread(target=client2, args=())
    t2.start()

    p2p = P2p()
    server = PeerServer()
    server.run(p2p)
    p2p.run()
Esempio n. 5
0
def start(
):  # wait : thread add_block(txs)   txs = []   packing function >1MB or no tx verify if tx are valid
    couch = couchdb.Server("http://127.0.0.1:5984")
    try:
        couch.delete('block_chain')
    except:
        pass
    db = DB("http://127.0.0.1:5984")

    bc = BlockChain()  # only one blockchain called bc
    utxo_set = UTXOSet()
    utxo_set.reindex(bc)

    tcpserver = TCPServer()
    tcpserver.listen()
    tcpserver.run()

    rpc = RPCServer(export_instance=Cli())
    rpc.start(False)

    p2p = P2p()
    server = PeerServer()
    server.run(p2p)
    p2p.run()

    time.sleep(40)
    fo = open("address.txt", "r")
    addrs = []
    for line in fo:
        addrs.append(line)
    fo.close()
    fee = random.uniform(0.1, 0.6)
    amount = 1
    tx = bc.new_transaction(addrs[0], addrs[1], amount, fee)  # change
    tx_pool = TxPool()
    tx_pool.add(tx)
    try:
        server = PeerServer()
        server.broadcast_tx(tx)
    except Exception as e:
        pass