-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
55 lines (43 loc) · 1.59 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
import json
import time
import requests
from eth_account import Account
from web3 import Web3
from eth_account.messages import encode_defunct
from loguru import logger
logger.remove()
logger.add('my.log', format='<g>{time:YYYY-MM-DD HH:mm:ss:SSS}</g> | <c>{level}</c> | <level>{message}</level>')
logger.add(sys.stdout, format='<g>{time:YYYY-MM-DD HH:mm:ss:SSS}</g> | <c>{level}</c> | <level>{message}</level>')
class Avail(obj):
def __init__(self, seed: str, proxy='') -> None:
Account.enable_unaudited_hdwallet_features()
seed = seed.strip()
if ' ' in seed:
self.account = Account.from_mnemonic(seed)
else:
self.account = Account.from_key(seed)
if proxy:
self.proxy = {
'http': proxy,
'https': proxy,
}
else:
self.proxy = {}
def check(self):
ts = time.time()
msg = f'''Greetings from Avail!
Sign this message to check your eligibility. This signature will not cost you any fees.
Timestamp: {ts}'''
msghash = encode_defunct(text=msg)
sign = self.account.sign_message(msghash)
url = 'https://claim-api.availproject.org/check-rewards'
sign = sign.signature.hex()
payload = {
'account': self.account.address,
'signedMessage': sign,
'timestamp': ts,
'type': 'ETHEREUM'
}
res = requests.post(url=url, json=payload, proxies=self.proxy)
logger.info(self.account.address + ' ' + res.text)