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/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 new file mode 100644 index 0000000..60a3128 --- /dev/null +++ b/icon/faucet.py @@ -0,0 +1,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() 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