-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.py
48 lines (41 loc) · 1.15 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import requests
import click
import addresses
from ip import get_my_ip
@click.group()
def cli():
pass
@click.command()
def hello():
click.echo("Hello World!")
@click.command()
def connect():
click.echo("Connecting to bootstrap...")
my_ip = get_my_ip()
url = "http://" + my_ip + ":5000/setup_myself"
r = requests.get(url)
click.echo("Returned this:")
click.echo(r.text)
@click.command()
@click.option('-i', '--id', help='Id of receiving node.')
@click.option('-a', '--amount', help='Amount of CC to send.')
def t(id, amount):
# Send amount CC another node
#url = "http://" + addresses[id] + ':5000/send_money'
print("Sending request")
my_ip = get_my_ip()
print(my_ip)
print(type(my_ip))
url = "http://" + my_ip + ":5000/send_money"
r = requests.post(url, data={'ip': addresses.global_addresses[id], 'amount': amount})
print(r)
@click.command()
def balance():
r = requests.get("http://" + get_my_ip() + ":5000/get_balance")
print("Your wallet has " + r.text + " NBCs")
cli.add_command(balance)
cli.add_command(hello)
cli.add_command(connect)
cli.add_command(t)
if __name__ == '__main__':
cli()