-
Notifications
You must be signed in to change notification settings - Fork 1
/
curated_staking_contract.py
91 lines (83 loc) · 3.13 KB
/
curated_staking_contract.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# for each operator, get the list of added validators
import requests
from eth_abi import decode, encode
import sha3
from config import API_KEY
#-------------------------------------
# getActiveNodeOperatorsCount()
#-------------------------------------
def get_number_of_operators(api_url, contract_address, API_KEY):
k = sha3.keccak_256()
k.update(b"getActiveNodeOperatorsCount()")
getActiveNodeOperatorsCount = "0x" + k.hexdigest()
params = {
'module': 'proxy',
'action': 'eth_call',
'to': contract_address,
'data': getActiveNodeOperatorsCount,
'apikey': API_KEY
}
response = requests.get(api_url, params=params)
if response.status_code == 200:
data = response.json()
numberOfOperators = int(data['result'], 16)
print ("\nnumber of node operators: " + str(numberOfOperators) + "\n")
return numberOfOperators
else:
print(f"Error: {response.status_code} - {response.text}")
return None
#-------------------------------------
# getActiveNodeOperator(uint256,bool)
#-------------------------------------
def get_node_operator(api_url, contract_address, API_KEY, _nodeOperatorId):
k = sha3.keccak_256()
k.update(b"getNodeOperator(uint256,bool)")
getNodeOperator = "0x" + k.hexdigest()[:8]
params_encoded = encode(['uint256', 'bool'], [_nodeOperatorId, True]).hex()
getNodeOperator += params_encoded
params = {
'module': 'proxy',
'action': 'eth_call',
'to': contract_address,
'data': getNodeOperator,
'apikey': API_KEY
}
response = requests.get(api_url, params=params)
if response.status_code == 200:
data = response.json()
abi = ["bool","string","address","uint256","uint256","uint256","uint256"]
hex_string = data['result'][2:]
decoded_data = decode(abi, bytes.fromhex(hex_string))
print ("node operator " + str(_nodeOperatorId) + ":" + str(decoded_data))
return decoded_data
else:
print(f"Error: {response.status_code} - {response.text}")
return None
#-------------------------------------
# getSigningKeys(uint256)
#-------------------------------------
def get_signing_key(api_url, contract_address, API_KEY, _nodeOperatorId, _index):
k = sha3.keccak_256()
k.update(b"getSigningKey(uint256,uint256)")
getSigningKey = "0x" + k.hexdigest()[:8]
params_encoded = encode(['uint256', 'uint256'], [_nodeOperatorId, _index]).hex()
getSigningKey += params_encoded
params = {
'module': 'proxy',
'action': 'eth_call',
'to': contract_address,
'data': getSigningKey,
'apikey': API_KEY
}
response = requests.get(api_url, params=params)
if response.status_code == 200:
data = response.json()
abi = ["bytes","bytes","bool"]
hex_string = data['result'][2:]
decoded_data = decode(abi, bytes.fromhex(hex_string))
deposit_signature = decoded_data[1].hex()
key = decoded_data[0].hex()
return deposit_signature, key, _index
else:
print(f"Error: {response.status_code} - {response.text}")
return None