-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
43 lines (37 loc) · 1.3 KB
/
utils.py
File metadata and controls
43 lines (37 loc) · 1.3 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
import json, os
from urllib.request import urlopen
# pip install pycrypto
# from Crypto.Cipher import XOR
import base64
from init_web3 import *
def encrypt(key, plaintext):
# cipher = XOR.new(key).encrypt(plaintext)
return base64.b64encode(plaintext)
def decrypt(key, ciphertext):
# cipher = XOR.new(key).decrypt()
return base64.b64decode(ciphertext)
def loadABI(contract_json_filename):
fullpath_filename = os.path.dirname(os.path.realpath(__file__)) + '/' + contract_json_filename
with open(fullpath_filename, 'r') as infile:
data = json.load(infile)
if isinstance(data, dict) and data["abi"]:
return data["abi"]
else:
return data
def fetchABIFromEtherscan(address):
html = urlopen("https://api.etherscan.io/api?module=contract&action=getabi&address=" + address + "&apikey=9TBD9VA31ASIGDRID7SBASUHPAHJGPKT17")
result = json.loads(html.read())
if (result['status'] == '1'):
return json.loads(result['result'])
else:
return None
def contractInstanceFromAddress(address):
abi = fetchABIFromEtherscan(address)
return web3.eth.contract(address = address, abi = abi)
def getTxHashIfSuccessful(txHash):
isBytes = isinstance(txHash, bytes)
if (isBytes):
return web3.toHex(txHash)
else:
print("Error! expected txhash, but got a " + str(type(txHash)))
return False