-
Notifications
You must be signed in to change notification settings - Fork 0
/
building.py
45 lines (41 loc) · 1.5 KB
/
building.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
import requests
import token_rpc
import time
# price to charge (in USD)
price = 7.77
# time limit for payments
time_limit = 60 * 15
# Needs better handling of different scenarios
def check_address(address, amount, tokenJson):
start = time.time()
while time.time() < start + time_limit:
response = requests.get("https://kmdexplorer.io/insight-api-komodo/addr/{}".format(address))
if response.status_code == 200:
data = response.json()
balance = data['balance']
if balance >= amount:
build(tokenJson)
break
else:
time.sleep(30)
else:
time.sleep(30)
print('error code {}, will keep trying'.format(response.status_code))
# generates new address and calculates the price
def receive(tokenJson):
pubkey, address = token_rpc.genaddress(token_rpc.rpc)
try:
value = requests.get("https://api.coinpaprika.com/v1/tickers/kmd-komodo").json()['quotes']['USD']['price']
amount = price / value
return "Please send {0} KMD to this address: {1}" \
"within 15 minutes to finish creating your token".format(amount, address)
except:
print("need proper error handling")
check_address(address, amount, tokenJson)
# actually builds the token
def build(tokenJson):
name = tokenJson['Name']
supply = tokenJson['Supply']
data = tokenJson['Data']
tokenid = token_rpc.tokencreate(token_rpc.rpc, name, supply, data)
return tokenid