forked from a000b/ZombieBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheth_.py
More file actions
58 lines (47 loc) · 1.89 KB
/
eth_.py
File metadata and controls
58 lines (47 loc) · 1.89 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
51
52
53
54
55
56
57
58
from web3 import Web3
import logging
import json
target_path = ""
logging.basicConfig(filename=target_path + 'logs.log', level=logging.INFO,
format='%(asctime)s|%(levelname)s|%(filename)s|%(funcName)s|%(message)s')
def read_file(filename):
try:
f = open(filename, "r", encoding='utf-8')
except Exception as e:
logging.error(e)
d = 'err'
else:
d = json.load(f)
finally:
f.close()
return d
def prepare_provider(data):
provider = Web3(Web3.HTTPProvider(data))
return provider
def create_new_eth_account(provider):
try:
account = provider.eth.account.create()
except Exception as e:
account = None
logging.error(e)
return account
def connect_2_contract(provider, contract_address):
contract = provider.eth.contract(address=provider.toChecksumAddress(contract_address),
abi=read_file(f'{target_path}bot_contract_abi.json'))
return contract
def get_answer_from_blokchain(question):
data = read_file(f'{target_path}infura.api.json')
contract = connect_2_contract(prepare_provider(data['rinkeby_url']), data["contract_bot_rinkeby"])
return contract.functions.getAnswer(question).call()
def prepare_contract_url(contract_address):
return f'https://rinkeby.etherscan.io/address/{contract_address}#code'
def get_contract_url():
return prepare_contract_url(read_file(f'{target_path}infura.api.json')['contract_bot_rinkeby'])
def prepare_answer():
new_account = create_new_eth_account(prepare_provider(read_file(f'{target_path}infura.api.json')['rinkeby_url']))
if new_account is not None:
priv_key = new_account.privateKey.hex()
address = new_account.address
return f'Twoje konto:\nhttps://rinkeby.etherscan.io/address/{address}\nKlucz prywatny: {priv_key[2:]}'
else:
return f'Coś poszło nie tak ;('