Ejemplo n.º 1
0
    'address': 'http://127.0.0.1:5000/'
}
_thread.start_new_thread(open_mine, (cont, ))
subprocess.Popen('python Server.py 5001')
time.sleep(2)
subprocess.Popen('python Server.py 5002')
time.sleep(2)
subprocess.Popen('python Server.py 5003')
time.sleep(2)
subprocess.Popen('python Server.py 5004')
time.sleep(3)


for port in range(5000, 5005):
    cont = {
        "cont": FileModule.get_account_by_port(port),
        "amount": 0
    }
    conturi.append(cont)

initial_transactions = []

for port in range(5001, 5005):
    trans = {
        'receiver_public_key': conturi[port-5000]['cont']['public_key'],
        'amount': random.randint(5000,7000),
        'sender_public_key': conturi[0]['cont']['public_key'],
        'sender_private_key': conturi[0]['cont']['private_key']
    }
    conturi[0]['amount'] = conturi[0]['amount'] - trans['amount']
    conturi[port-5001]['amount'] = conturi[port-5001]['amount'] + trans['amount']
Ejemplo n.º 2
0
import FileModule
import json
import requests
headers = {'Content-type': 'application/json'}

cont1 = FileModule.get_account_by_port(5000)
cont2 = FileModule.get_account_by_port(5005)

data = {
    'receiver_public_key': cont2['public_key'],
    'amount': 30000,
    'sender_public_key': cont1['public_key'],
    'sender_private_key': cont1['private_key']
}

requests.post(cont1['address'] + 'transactions/new',
              data=json.dumps(data),
              headers=headers)
import FileModule
import json
import asyncio
from aiohttp import ClientSession

headers = {'Content-type': 'application/json'}

account1 = FileModule.get_account_by_port(5001, True)
account2 = FileModule.get_account_by_port(5002, True)
account3 = FileModule.get_account_by_port(5003, True)

trans1 = {
    'receiver_public_key': account2['public_key'],
    'amount': 15000,
    'sender_public_key': account1['public_key'],
    'sender_private_key': account1['private_key']
}

trans2 = {
    'receiver_public_key': account3['public_key'],
    'amount': 15000,
    'sender_public_key': account1['public_key'],
    'sender_private_key': account1['private_key']
}


async def post_text(url, body):
    async with ClientSession() as session:
        async with session.post(url=url, data=body,
                                headers=headers) as response:
            await response.read()
# Step1: Open root server
subprocess.Popen('python ../Server.py 5000')
time.sleep(3)
date = datetime.datetime.now()

cont = {'address': 'http://127.0.0.1:5000/'}
_thread.start_new_thread(open_mine, (cont, ))

# Step2: open rest of servers
for port in PORTS:
    subprocess.Popen('python ../Server.py ' + port)
    time.sleep(3)
time.sleep(2)
# Get accounts
for port in range(5000, 5010):
    accounts.append(FileModule.get_account_by_port(port, True))

# distributes the stack
initial_transactions = []

amounts = [25000, 15000, 10000, 5000, 4500, 4000, 3000, 2000, 1000]
for port in range(5001, 5010):
    trans = {
        'receiver_public_key': accounts[port - 5000]['public_key'],
        'amount': amounts[port - 5001],
        'sender_public_key': accounts[0]['public_key'],
        'sender_private_key': accounts[0]['private_key']
    }

    initial_transactions.append(trans)
Ejemplo n.º 5
0
subprocess.Popen('python Server.py 5000')
time.sleep(3)
cont = {'address': 'http://127.0.0.1:5000/'}
_thread.start_new_thread(open_mine, (cont, ))
subprocess.Popen('python Server.py 5001')
time.sleep(2)
subprocess.Popen('python Server.py 5002')
time.sleep(2)
subprocess.Popen('python Server.py 5003')
time.sleep(2)
subprocess.Popen('python Server.py 5004')
time.sleep(3)

for port in range(5000, 5005):
    cont = {"cont": FileModule.get_account_by_port(port), "amount": 0}
    conturi.append(cont)

initial_transactions = []

for port in range(5001, 5005):
    trans = {
        'receiver_public_key': conturi[port - 5000]['cont']['public_key'],
        'amount': 15001,
        'sender_public_key': conturi[0]['cont']['public_key'],
        'sender_private_key': conturi[0]['cont']['private_key']
    }
    conturi[0]['amount'] = conturi[0]['amount'] - trans['amount']
    conturi[port -
            5001]['amount'] = conturi[port - 5001]['amount'] + trans['amount']
    initial_transactions.append(trans)