Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions icon/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# wallet keystore
*.json
13 changes: 13 additions & 0 deletions icon/README.md
Original file line number Diff line number Diff line change
@@ -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
}
```
50 changes: 50 additions & 0 deletions icon/faucet.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ sanic-cors
sanic-jwt-extended
pytest
pytest-sanic
http3