-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfaucet.py
More file actions
50 lines (43 loc) · 1.41 KB
/
faucet.py
File metadata and controls
50 lines (43 loc) · 1.41 KB
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
49
50
from iconsdk.icon_service import IconService
from iconsdk.providers.http_provider import HTTPProvider
from iconsdk.wallet.wallet import KeyWallet
import http3
import json
import time
import sys
import os.path
def filepath(filename):
return os.path.join(sys.path[0], filename)
icon_service = IconService(HTTPProvider('https://bicon.net.solidwallet.io/api/v3'))
with open(filepath('secret.json'), 'r') as f:
secret = json.load(f)
wallet = KeyWallet.load(filepath(secret['keystore']), secret['password'])
wallet_addr = wallet.get_address()
def wallet_status(address):
return '{}: {}'.format(
address,
icon_service.get_balance(address) / 10 ** 18
)
def get_block_height():
return icon_service.get_block('latest')['height']
def request(address):
try:
res = http3.get(
'http://icon-faucet-api.ibriz.ai/api/requesticx/{}'.format(address),
timeout=5
).json()
if not res['status']: # fail
print(res['message'])
except http3.exceptions.ReadTimeout: # success
print(wallet_status(address))
def loop():
block_height = 0
while True:
current_height = get_block_height()
if (current_height > block_height + 30):
request(wallet_addr)
block_height = current_height
time.sleep(10)
if __name__ == '__main__':
print('Starting auto-faucet with wallet {}'.format(wallet_addr))
loop()