From d1c75026b90c300f752f6c42d244c4d53f4be5e1 Mon Sep 17 00:00:00 2001 From: JunhoYeo <32605822+JunhoYeo@users.noreply.github.com> Date: Wed, 3 Jul 2019 13:39:53 +0900 Subject: [PATCH 1/2] feat(icon): faucet script --- icon/.gitignore | 2 ++ icon/faucet.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 3 files changed, 54 insertions(+) create mode 100644 icon/.gitignore create mode 100644 icon/faucet.py diff --git a/icon/.gitignore b/icon/.gitignore new file mode 100644 index 0000000..c1becc8 --- /dev/null +++ b/icon/.gitignore @@ -0,0 +1,2 @@ +# wallet keystore +*.json diff --git a/icon/faucet.py b/icon/faucet.py new file mode 100644 index 0000000..23359bd --- /dev/null +++ b/icon/faucet.py @@ -0,0 +1,51 @@ +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(): + '''automaticlly request faucets for ICON testnet''' + 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() diff --git a/requirements.txt b/requirements.txt index 829cf3d..7a1cfb8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ sanic-cors sanic-jwt-extended pytest pytest-sanic +http3 From 374d1d79429eacf6bca97db69abc38f9435bce60 Mon Sep 17 00:00:00 2001 From: JunhoYeo <32605822+JunhoYeo@users.noreply.github.com> Date: Wed, 3 Jul 2019 13:43:01 +0900 Subject: [PATCH 2/2] docs: faucet documentation --- icon/README.md | 13 +++++++++++++ icon/faucet.py | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 icon/README.md diff --git a/icon/README.md b/icon/README.md new file mode 100644 index 0000000..e3549ed --- /dev/null +++ b/icon/README.md @@ -0,0 +1,13 @@ +# BISS Migration of ICON Blockchain + +## Faucet +> Automaticlly request ICON testnet faucets + +`faucet.py`와 같은 경로에 다음과 같은 내용의 `secret.json`과 keystore 파일을 저장하고 실행한다. + +```js +{ + "keystore": "iconkeystore.json", // keystore 파일명 + "password": "@biss" // keystore의 passphrase +} +``` diff --git a/icon/faucet.py b/icon/faucet.py index 23359bd..60a3128 100644 --- a/icon/faucet.py +++ b/icon/faucet.py @@ -37,7 +37,6 @@ def request(address): print(wallet_status(address)) def loop(): - '''automaticlly request faucets for ICON testnet''' block_height = 0 while True: current_height = get_block_height()