ethernity-cloud-runner-py 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/PKG-INFO +1 -1
- ethernity_cloud_runner_py-0.2.4/ethernity_cloud_runner_py/contract/abi/ECLDAbi.py +8 -0
- ethernity_cloud_runner_py-0.2.2/ethernity_cloud_runner_py/contract/abi/polygonAbi.py → ethernity_cloud_runner_py-0.2.4/ethernity_cloud_runner_py/contract/abi/polygonProtocolAbi.py +1 -1
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/contract/operation/bloxbergProtocolContract.py +1 -1
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/contract/operation/imageRegistryContract.py +5 -5
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/contract/operation/polygonProtocolContract.py +68 -45
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/enums.py +9 -9
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/ipfs.py +0 -4
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/runner.py +151 -95
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py.egg-info/PKG-INFO +1 -1
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py.egg-info/SOURCES.txt +2 -1
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/setup.py +1 -1
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/LICENSE +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/README.md +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/__init__.py +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/contract/__init__.py +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/contract/abi/__init__.py +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/contract/abi/bloxbergAbi.py +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/contract/abi/imageRegistryAbi.py +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/contract/operation/__init__.py +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/crypto.py +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py/utils.py +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py.egg-info/dependency_links.txt +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py.egg-info/requires.txt +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/ethernity_cloud_runner_py.egg-info/top_level.txt +0 -0
- {ethernity_cloud_runner_py-0.2.2 → ethernity_cloud_runner_py-0.2.4}/setup.cfg +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
contract = {
|
|
4
|
+
"address": os.getenv(
|
|
5
|
+
"ECLD_CONTRACT_ADDRESS", "0xc6920888988cAcEeA7ACCA0c96f2D65b05eE22Ba"
|
|
6
|
+
),
|
|
7
|
+
"abi": [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"anonymous":False,"inputs":[{"indexed":True,"internalType":"address","name":"owner","type":"address"},{"indexed":True,"internalType":"address","name":"spender","type":"address"},{"indexed":False,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":False,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":False,"inputs":[{"indexed":False,"internalType":"address","name":"receiver","type":"address"},{"indexed":False,"internalType":"uint256","name":"value","type":"uint256"},{"indexed":False,"internalType":"string","name":"mintId","type":"string"}],"name":"Mint","type":"event"},{"anonymous":False,"inputs":[{"indexed":True,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":True,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":False,"inputs":[{"indexed":True,"internalType":"address","name":"from","type":"address"},{"indexed":True,"internalType":"address","name":"to","type":"address"},{"indexed":False,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"flashFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC3156FlashBorrower","name":"receiver","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"flashLoan","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"maxFlashLoan","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"string","name":"mintId","type":"string"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}],
|
|
8
|
+
}
|
|
@@ -73,7 +73,7 @@ class BloxbergProtocolContract:
|
|
|
73
73
|
).call()
|
|
74
74
|
if allowance < task_price_amount:
|
|
75
75
|
tx = self.ethernity_contract.functions.approve(
|
|
76
|
-
protocol_address,
|
|
76
|
+
protocol_address, int(task_price)
|
|
77
77
|
).build_transaction(self.__transaction_object)
|
|
78
78
|
signed_tx = self.provider.eth.account.sign_transaction(
|
|
79
79
|
tx, private_key=self.signer._private_key
|
|
@@ -15,7 +15,7 @@ class ImageRegistryContract:
|
|
|
15
15
|
def __init__(
|
|
16
16
|
self,
|
|
17
17
|
network_address: Address = ECAddress.BLOXBERG.TESTNET_ADDRESS, # type: ignore
|
|
18
|
-
runner_type: str = ECRunner.BLOXBERG["
|
|
18
|
+
runner_type: str = ECRunner.BLOXBERG["PYNITHY_RUNNER_TESTNET"],
|
|
19
19
|
signer: Any = None,
|
|
20
20
|
):
|
|
21
21
|
self.signer = signer
|
|
@@ -37,14 +37,14 @@ class ImageRegistryContract:
|
|
|
37
37
|
abi=contract["abi"],
|
|
38
38
|
)
|
|
39
39
|
elif network_address == ECAddress.BLOXBERG.MAINNET_ADDRESS:
|
|
40
|
-
if runner_type == ECRunner.BLOXBERG["
|
|
40
|
+
if runner_type == ECRunner.BLOXBERG["NODENITHY_RUNNER_MAINNET"]:
|
|
41
41
|
self.contract = self.provider.eth.contract(
|
|
42
42
|
address=to_checksum_address(
|
|
43
43
|
ECAddress.BLOXBERG.IMAGE_REGISTRY.NODENITHY.MAINNET_ADDRESS
|
|
44
44
|
),
|
|
45
45
|
abi=contract["abi"],
|
|
46
46
|
)
|
|
47
|
-
elif runner_type == ECRunner.BLOXBERG["
|
|
47
|
+
elif runner_type == ECRunner.BLOXBERG["PYNITHY_RUNNER_MAINNET"]:
|
|
48
48
|
self.contract = self.provider.eth.contract(
|
|
49
49
|
address=to_checksum_address(
|
|
50
50
|
ECAddress.BLOXBERG.IMAGE_REGISTRY.PYNITHY.MAINNET_ADDRESS
|
|
@@ -52,14 +52,14 @@ class ImageRegistryContract:
|
|
|
52
52
|
abi=contract["abi"],
|
|
53
53
|
)
|
|
54
54
|
elif network_address == ECAddress.POLYGON.MAINNET_ADDRESS:
|
|
55
|
-
if runner_type == ECRunner.POLYGON["
|
|
55
|
+
if runner_type == ECRunner.POLYGON["NODENITHY_RUNNER_MAINNET"]:
|
|
56
56
|
self.contract = self.provider.eth.contract(
|
|
57
57
|
address=to_checksum_address(
|
|
58
58
|
ECAddress.POLYGON.IMAGE_REGISTRY.NODENITHY.MAINNET_ADDRESS
|
|
59
59
|
),
|
|
60
60
|
abi=contract["abi"],
|
|
61
61
|
)
|
|
62
|
-
elif runner_type == ECRunner.POLYGON["
|
|
62
|
+
elif runner_type == ECRunner.POLYGON["PYNITHY_RUNNER_MAINNET"]:
|
|
63
63
|
self.contract = self.provider.eth.contract(
|
|
64
64
|
address=to_checksum_address(
|
|
65
65
|
ECAddress.POLYGON.IMAGE_REGISTRY.PYNITHY.MAINNET_ADDRESS
|
|
@@ -9,44 +9,58 @@ from web3.contract.contract import Contract
|
|
|
9
9
|
from web3.middleware import ExtraDataToPOAMiddleware
|
|
10
10
|
from web3.types import TxParams
|
|
11
11
|
|
|
12
|
-
from ..abi.
|
|
12
|
+
from ..abi.polygonProtocolAbi import contract as polygonAbi
|
|
13
|
+
from ..abi.ECLDAbi import contract as ECLDAbi
|
|
13
14
|
from ...enums import ECNetworkByChainIdDictionary, ECNetworkRPCDictionary
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class PolygonProtocolContract:
|
|
17
18
|
def __init__(
|
|
18
|
-
self,
|
|
19
|
+
self, token_address: Address, protocol_address: Address, signer: Any, chain_id: int = 8559
|
|
19
20
|
) -> None:
|
|
20
|
-
self.
|
|
21
|
-
self.
|
|
22
|
-
|
|
21
|
+
self.chain_id = chain_id
|
|
22
|
+
self.token_address = token_address
|
|
23
|
+
self.protocol_address = protocol_address
|
|
24
|
+
self.max_fee_per_gas = 1000
|
|
25
|
+
self.max_priority_fee_per_gas = 35
|
|
26
|
+
_rpc_url = ECNetworkRPCDictionary[token_address]
|
|
23
27
|
self.provider = Web3(Web3.HTTPProvider(_rpc_url))
|
|
24
|
-
|
|
28
|
+
|
|
25
29
|
self.provider.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
|
|
26
30
|
|
|
27
31
|
self.signer = signer
|
|
28
|
-
self.
|
|
29
|
-
address=
|
|
32
|
+
self.protocol_contract = self.provider.eth.contract(
|
|
33
|
+
address=protocol_address, abi=polygonAbi["abi"]
|
|
34
|
+
)
|
|
35
|
+
self.token_contract = self.provider.eth.contract(
|
|
36
|
+
address=token_address, abi=ECLDAbi["abi"]
|
|
30
37
|
)
|
|
31
38
|
|
|
32
|
-
def
|
|
33
|
-
return self.
|
|
39
|
+
def get_token_address(self) -> Address:
|
|
40
|
+
return self.token_address
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
def get_protocol_address(self) -> Address:
|
|
43
|
+
return self.protocol_address
|
|
44
|
+
|
|
45
|
+
def __transaction_object(self, gas) -> TxParams:
|
|
37
46
|
nonce = self.provider.eth.get_transaction_count(self.signer.address)
|
|
47
|
+
max_fee_per_gas = self.provider.to_wei(self.max_fee_per_gas, 'gwei')
|
|
48
|
+
max_priority_fee_per_gas = self.provider.to_wei(self.max_priority_fee_per_gas, 'gwei')
|
|
49
|
+
|
|
38
50
|
return {
|
|
39
|
-
"
|
|
40
|
-
"chainId":
|
|
51
|
+
"from": self.signer.address,
|
|
52
|
+
"chainId": self.chain_id,
|
|
41
53
|
"nonce": nonce,
|
|
42
|
-
"
|
|
54
|
+
"gas": gas,
|
|
55
|
+
"maxFeePerGas" : max_fee_per_gas,
|
|
56
|
+
"maxPriorityFeePerGas": max_priority_fee_per_gas,
|
|
43
57
|
}
|
|
44
58
|
|
|
45
59
|
def get_signer(self) -> Any:
|
|
46
60
|
return self.signer
|
|
47
61
|
|
|
48
62
|
def get_contract(self) -> Contract:
|
|
49
|
-
return self.
|
|
63
|
+
return self.protocol_contract
|
|
50
64
|
|
|
51
65
|
def get_provider(self) -> Web3:
|
|
52
66
|
return self.provider
|
|
@@ -57,39 +71,42 @@ class PolygonProtocolContract:
|
|
|
57
71
|
def get_balance(self) -> int:
|
|
58
72
|
try:
|
|
59
73
|
address = self.signer.address
|
|
60
|
-
balance = self.
|
|
74
|
+
balance = self.token_contract.functions.balanceOf(address).call()
|
|
61
75
|
return Web3.from_wei(balance, "ether")
|
|
62
76
|
except Exception as e:
|
|
63
77
|
print(e)
|
|
64
78
|
return 0
|
|
65
79
|
|
|
66
80
|
def check_and_set_allowance(
|
|
67
|
-
self,
|
|
81
|
+
self, task_price: str
|
|
68
82
|
) -> bool:
|
|
69
|
-
allowance_amount = Web3.to_wei(amount, "ether")
|
|
70
83
|
task_price_amount = Web3.to_wei(task_price, "ether")
|
|
71
84
|
current_wallet_address = self.signer.address
|
|
72
|
-
allowance = self.
|
|
73
|
-
current_wallet_address, protocol_address
|
|
85
|
+
allowance = self.token_contract.functions.allowance(
|
|
86
|
+
current_wallet_address, self.protocol_address
|
|
74
87
|
).call()
|
|
75
88
|
if allowance < task_price_amount:
|
|
76
|
-
tx = self.ethernity_contract.functions.approve(
|
|
77
|
-
protocol_address, allowance_amount
|
|
78
|
-
).build_transaction(self.__transaction_object)
|
|
79
|
-
signed_tx = self.provider.eth.account.sign_transaction(
|
|
80
|
-
tx, private_key=self.signer._private_key
|
|
81
|
-
)
|
|
82
|
-
self.provider.eth.send_raw_transaction(signed_tx.raw_transaction)
|
|
83
|
-
recept = self.provider.to_hex(
|
|
84
|
-
self.provider.keccak(signed_tx.raw_transaction)
|
|
85
|
-
)
|
|
86
89
|
try:
|
|
87
|
-
self.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
tx = self.token_contract.functions.approve(
|
|
91
|
+
self.protocol_address, int(task_price_amount * 10)
|
|
92
|
+
).build_transaction(self.__transaction_object(100000))
|
|
93
|
+
|
|
94
|
+
signed_tx = self.provider.eth.account.sign_transaction(
|
|
95
|
+
tx, private_key=self.signer._private_key
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
self.provider.eth.send_raw_transaction(signed_tx.raw_transaction)
|
|
99
|
+
|
|
100
|
+
receipt = self.provider.to_hex(
|
|
101
|
+
self.provider.keccak(signed_tx.raw_transaction)
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
self.provider.eth.wait_for_transaction_receipt(receipt)
|
|
105
|
+
|
|
106
|
+
allowance = self.protocol_contract.functions.allowance(
|
|
107
|
+
current_wallet_address, self.protocol_address
|
|
90
108
|
).call()
|
|
91
109
|
except Exception as e:
|
|
92
|
-
print(e)
|
|
93
110
|
return False
|
|
94
111
|
return True
|
|
95
112
|
|
|
@@ -112,14 +129,16 @@ class PolygonProtocolContract:
|
|
|
112
129
|
resources: dict,
|
|
113
130
|
gas_limit: None = None,
|
|
114
131
|
) -> HexStr:
|
|
132
|
+
|
|
115
133
|
cpu = resources.get("cpu", 1)
|
|
116
134
|
memory = resources.get("memory", 1)
|
|
117
135
|
storage = resources.get("storage", 40)
|
|
118
136
|
bandwidth = resources.get("bandwidth", 1)
|
|
119
137
|
duration = resources.get("duration", 1)
|
|
120
138
|
validators = resources.get("validators", 1)
|
|
121
|
-
task_price = resources.get("
|
|
122
|
-
|
|
139
|
+
task_price = resources.get("taskPrice", 10)
|
|
140
|
+
|
|
141
|
+
tx = self.protocol_contract.functions._addDORequest(
|
|
123
142
|
cpu,
|
|
124
143
|
memory,
|
|
125
144
|
storage,
|
|
@@ -131,22 +150,23 @@ class PolygonProtocolContract:
|
|
|
131
150
|
payload_metadata,
|
|
132
151
|
input_metadata,
|
|
133
152
|
node_address,
|
|
134
|
-
).build_transaction(self.__transaction_object)
|
|
153
|
+
).build_transaction(self.__transaction_object(1000000))
|
|
135
154
|
|
|
136
155
|
signed_tx = self.provider.eth.account.sign_transaction(
|
|
137
156
|
tx, private_key=self.signer._private_key
|
|
138
157
|
)
|
|
158
|
+
|
|
139
159
|
self.provider.eth.send_raw_transaction(signed_tx.raw_transaction)
|
|
140
160
|
return self.provider.to_hex(self.provider.keccak(signed_tx.raw_transaction))
|
|
141
161
|
|
|
142
162
|
def get_order(self, order_id: int) -> int:
|
|
143
|
-
return self.
|
|
163
|
+
return self.protocol_contract.functions._getOrder(order_id).call()
|
|
144
164
|
|
|
145
165
|
def approve_order(self, order_id: int) -> HexStr:
|
|
146
|
-
# return self.
|
|
147
|
-
unicorn_txn = self.
|
|
166
|
+
# return self.protocol_contract.functions._approveOrder(order_id).transact()
|
|
167
|
+
unicorn_txn = self.protocol_contract.functions._approveOrder(
|
|
148
168
|
order_id
|
|
149
|
-
).build_transaction(self.__transaction_object)
|
|
169
|
+
).build_transaction(self.__transaction_object(100000))
|
|
150
170
|
|
|
151
171
|
signed_txn = self.provider.eth.account.sign_transaction(
|
|
152
172
|
unicorn_txn, private_key=self.signer._private_key
|
|
@@ -155,12 +175,15 @@ class PolygonProtocolContract:
|
|
|
155
175
|
return self.provider.to_hex(self.provider.keccak(signed_txn.raw_transaction))
|
|
156
176
|
|
|
157
177
|
def get_result_from_order(self, order_id: int) -> Any:
|
|
158
|
-
self.
|
|
159
|
-
return self.
|
|
178
|
+
self.protocol_contract.caller()._getOrder(order_id)
|
|
179
|
+
return self.protocol_contract.caller()._getResultFromOrder(order_id)
|
|
160
180
|
|
|
181
|
+
def get_status_from_order(self, order_id: int) -> Any:
|
|
182
|
+
return self.protocol_contract.caller()._getOrder(order_id)[4]
|
|
183
|
+
|
|
161
184
|
def is_node_operator(self, account: str) -> bool:
|
|
162
185
|
try:
|
|
163
|
-
requests = self.
|
|
186
|
+
requests = self.protocol_contract.functions._getMyDPRequests().call(
|
|
164
187
|
{"from": account}
|
|
165
188
|
)
|
|
166
189
|
return len(requests) > 0
|
|
@@ -60,14 +60,14 @@ class ECRunner:
|
|
|
60
60
|
BLOXBERG = {
|
|
61
61
|
"PYNITHY_RUNNER_TESTNET": "etny-pynithy-testnet",
|
|
62
62
|
"NODENITHY_RUNNER_TESTNET": "etny-nodenithy-testnet",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
63
|
+
"PYNITHY_RUNNER_MAINNET": "etny-pynithy",
|
|
64
|
+
"NODENITHY_RUNNER_MAINNET": "etny-nodenithy"
|
|
65
65
|
}
|
|
66
66
|
POLYGON = {
|
|
67
67
|
"PYNITHY_RUNNER_TESTNET": "ecld-pynithy-mumbai",
|
|
68
68
|
"NODENITHY_RUNNER_TESTNET": "ecld-nodenithy",
|
|
69
|
-
"
|
|
70
|
-
"
|
|
69
|
+
"PYNITHY_RUNNER_MAINNET": "ecld-pynithy",
|
|
70
|
+
"NODENITHY_RUNNER_MAINNET": "ecld-nodenithy"
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
def __getitem__(self, key):
|
|
@@ -126,10 +126,10 @@ ECNetworkName1Dictionary = {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
ECNetworkRPCDictionary = {
|
|
129
|
-
ECAddress.BLOXBERG.MAINNET_ADDRESS: "https://
|
|
130
|
-
ECAddress.BLOXBERG.TESTNET_ADDRESS: "https://
|
|
129
|
+
ECAddress.BLOXBERG.MAINNET_ADDRESS: "https://bloxberg.ethernity.cloud",
|
|
130
|
+
ECAddress.BLOXBERG.TESTNET_ADDRESS: "https://bloxberg.ethernity.cloud",
|
|
131
131
|
ECAddress.POLYGON.TESTNET_ADDRESS: "https://rpc-mumbai.matic.today",
|
|
132
|
-
ECAddress.POLYGON.MAINNET_ADDRESS: "https://rpc
|
|
132
|
+
ECAddress.POLYGON.MAINNET_ADDRESS: "https://polygon-rpc.com",
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
ECNetworkEnvToEnum = {
|
|
@@ -143,8 +143,8 @@ ZERO_CHECKSUM = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85
|
|
|
143
143
|
|
|
144
144
|
|
|
145
145
|
class ECError(Enum):
|
|
146
|
-
PARSE_ERROR = "
|
|
147
|
-
IPFS_DOWNLOAD_ERROR = "
|
|
146
|
+
PARSE_ERROR = "The result is not a valid v3 result"
|
|
147
|
+
IPFS_DOWNLOAD_ERROR = "Unable to download results, will keep trying until the download is complete."
|
|
148
148
|
|
|
149
149
|
class ECLog(IntEnum):
|
|
150
150
|
ERROR = 1
|
|
@@ -45,7 +45,6 @@ class IPFSClient:
|
|
|
45
45
|
return None
|
|
46
46
|
else:
|
|
47
47
|
print(f"Failed to upload to IPFS. Status code: {response.status_code}")
|
|
48
|
-
print(response.text)
|
|
49
48
|
return None
|
|
50
49
|
|
|
51
50
|
def download_file(
|
|
@@ -74,9 +73,6 @@ class IPFSClient:
|
|
|
74
73
|
# TODO: use a get encoding function to determine the encoding
|
|
75
74
|
return response.content.decode("utf-8")
|
|
76
75
|
else:
|
|
77
|
-
print(
|
|
78
|
-
f"Failed to get content from IPFS. Attempt {attempt}. Status code: {response.status_code}. Response text: {response.text}.\n{'Trying again...' if attempt < 6 else ''}"
|
|
79
|
-
)
|
|
80
76
|
if attempt < 6:
|
|
81
77
|
self.get_file_content(ipfs_hash, attempt + 1)
|
|
82
78
|
|
|
@@ -13,10 +13,12 @@ from web3.contract.contract import Contract
|
|
|
13
13
|
from web3.exceptions import TimeExhausted, TransactionNotFound
|
|
14
14
|
|
|
15
15
|
from .contract.abi.bloxbergAbi import contract as bloxbergAbi
|
|
16
|
-
from .contract.abi.
|
|
16
|
+
from .contract.abi.polygonProtocolAbi import contract as polygonAbi
|
|
17
|
+
from .contract.abi.ECLDAbi import contract as ECLDAbi
|
|
17
18
|
from .contract.operation.bloxbergProtocolContract import BloxbergProtocolContract
|
|
18
19
|
from .contract.operation.imageRegistryContract import ImageRegistryContract
|
|
19
20
|
from .contract.operation.polygonProtocolContract import PolygonProtocolContract
|
|
21
|
+
from .enums import ECNetworkByChainId
|
|
20
22
|
from binascii import hexlify
|
|
21
23
|
from nacl.public import Box, PrivateKey, PublicKey
|
|
22
24
|
|
|
@@ -71,6 +73,7 @@ class EthernityCloudRunner:
|
|
|
71
73
|
self.event_queue = Queue() # Queue to store events
|
|
72
74
|
self.processed_events: List[str] = [] # List to store processed events
|
|
73
75
|
self.task_thread = None
|
|
76
|
+
self.current_order_index = 0
|
|
74
77
|
self.status = ECStatus.RUNNING
|
|
75
78
|
self.progress = ECEvent.INIT
|
|
76
79
|
self.last_error = None
|
|
@@ -83,6 +86,8 @@ class EthernityCloudRunner:
|
|
|
83
86
|
def set_network(self, network, type) -> None:
|
|
84
87
|
self.network = network.lower()+ "_" + type.lower()
|
|
85
88
|
self.trustedZoneImage = ECRunner()[network.upper()]["PYNITHY_RUNNER_"+type.upper()]
|
|
89
|
+
self.network_address = getattr(getattr(ECAddress, network.upper(), None), f"{type.upper()}_ADDRESS", None)
|
|
90
|
+
self.chain_id = ECNetworkByChainId[network.upper()][type.upper()]
|
|
86
91
|
|
|
87
92
|
def set_private_key(self, private_key) -> None:
|
|
88
93
|
self.private_key = private_key
|
|
@@ -98,22 +103,28 @@ class EthernityCloudRunner:
|
|
|
98
103
|
ECAddress.BLOXBERG.TESTNET_ADDRESS,
|
|
99
104
|
ECAddress.BLOXBERG.MAINNET_ADDRESS,
|
|
100
105
|
]:
|
|
101
|
-
self.
|
|
106
|
+
self.protocol = BloxbergProtocolContract(
|
|
102
107
|
network_address, self.signer
|
|
103
108
|
)
|
|
104
109
|
self.protocol_abi = bloxbergAbi.get("abi")
|
|
110
|
+
self.token_contract = self.contract.token_contract
|
|
111
|
+
self.protocol_contract = self.contract.protocol_contract
|
|
112
|
+
|
|
105
113
|
elif network_address == ECAddress.POLYGON.MAINNET_ADDRESS:
|
|
106
|
-
self.
|
|
107
|
-
ECAddress.POLYGON.MAINNET_PROTOCOL_ADDRESS, self.signer,
|
|
114
|
+
self.contract = PolygonProtocolContract(
|
|
115
|
+
ECAddress.POLYGON.MAINNET_ADDRESS, ECAddress.POLYGON.MAINNET_PROTOCOL_ADDRESS, self.signer, self.chain_id # type: ignore
|
|
108
116
|
)
|
|
109
117
|
self.protocol_abi = polygonAbi.get("abi")
|
|
118
|
+
self.token_contract = self.contract.token_contract
|
|
119
|
+
self.protocol_contract = self.contract.protocol_contract
|
|
120
|
+
|
|
110
121
|
elif network_address == ECAddress.POLYGON.TESTNET_ADDRESS:
|
|
111
|
-
self.
|
|
112
|
-
ECAddress.POLYGON.TESTNET_PROTOCOL_ADDRESS, self.signer,
|
|
122
|
+
self.contract = PolygonProtocolContract(
|
|
123
|
+
ECAddress.POLYGON.TESTNET_ADDRESS, ECAddress.POLYGON.TESTNET_PROTOCOL_ADDRESS, self.signer, self.chain_id # type: ignore
|
|
113
124
|
)
|
|
114
125
|
self.protocol_abi = polygonAbi.get("abi")
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
self.token_contract = self.contract.token_contract
|
|
127
|
+
self.protocol_contract = self.contract.protocol_contract
|
|
117
128
|
|
|
118
129
|
def set_log_level(self, level):
|
|
119
130
|
self.log_level = ECLog[level.upper()]
|
|
@@ -136,7 +147,7 @@ class EthernityCloudRunner:
|
|
|
136
147
|
debug_details = ""
|
|
137
148
|
if (self.log_level == ECLog.DEBUG):
|
|
138
149
|
debug_details = "Event:",{event_type},"Status:",{status}
|
|
139
|
-
self.log.append(f"[{
|
|
150
|
+
self.log.append(f"[{log_level.name}] {datetime.now()} {message} {debug_details}")
|
|
140
151
|
|
|
141
152
|
|
|
142
153
|
def get_enclave_details(self) -> bool:
|
|
@@ -149,6 +160,8 @@ class EthernityCloudRunner:
|
|
|
149
160
|
self.enclave_public_key,
|
|
150
161
|
self.enclave_docker_compose_ipfs_hash,
|
|
151
162
|
) = details
|
|
163
|
+
|
|
164
|
+
print(self.enclave_public_key)
|
|
152
165
|
self.log_append(
|
|
153
166
|
f"ENCLAVE_IMAGE_IPFS_HASH: {self.enclave_image_ipfs_hash}"
|
|
154
167
|
)
|
|
@@ -192,8 +205,8 @@ class EthernityCloudRunner:
|
|
|
192
205
|
def check_web3_connection(self) -> Literal[False]:
|
|
193
206
|
try:
|
|
194
207
|
# self.token_contract.get_provider().send("eth_requestAccounts", [])
|
|
195
|
-
self.
|
|
196
|
-
wallet_address = self.
|
|
208
|
+
self.contract.get_provider()
|
|
209
|
+
wallet_address = self.contract.get_current_wallet()
|
|
197
210
|
return wallet_address is not None and wallet_address != ""
|
|
198
211
|
except Exception as e:
|
|
199
212
|
self.log_append(
|
|
@@ -232,11 +245,11 @@ class EthernityCloudRunner:
|
|
|
232
245
|
self.log_append(
|
|
233
246
|
f"Uploaded encrypted code to IPFS: {self.script_hash}"
|
|
234
247
|
)
|
|
235
|
-
script_checksum = self.
|
|
248
|
+
script_checksum = self.contract.sign_message(script_checksum)
|
|
236
249
|
return f"{TRUSTEDZONE_VERSION}:{self.script_hash}:{script_checksum.signature.hex()}"
|
|
237
250
|
|
|
238
251
|
def get_v3_input_metadata(self) -> str:
|
|
239
|
-
file_set_checksum = self.
|
|
252
|
+
file_set_checksum = self.contract.sign_message(ZERO_CHECKSUM)
|
|
240
253
|
return f"{TRUSTEDZONE_VERSION}::{file_set_checksum.signature.hex()}"
|
|
241
254
|
|
|
242
255
|
def create_do_request(
|
|
@@ -248,17 +261,26 @@ class EthernityCloudRunner:
|
|
|
248
261
|
gas_limit: None = None,
|
|
249
262
|
) -> bool:
|
|
250
263
|
try:
|
|
251
|
-
__provider = self.
|
|
264
|
+
__provider = self.contract.get_provider()
|
|
252
265
|
self.log_append(
|
|
253
266
|
f"Submitting transaction for DO request",
|
|
254
267
|
)
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
268
|
+
while True:
|
|
269
|
+
try:
|
|
270
|
+
transaction_hash = self.contract.add_do_request(
|
|
271
|
+
image_metadata,
|
|
272
|
+
code_metadata,
|
|
273
|
+
input_metadata,
|
|
274
|
+
node_address,
|
|
275
|
+
self.resources,
|
|
276
|
+
)
|
|
277
|
+
break
|
|
278
|
+
except Exception as e:
|
|
279
|
+
self.log_append(
|
|
280
|
+
f"Unable to build transaction: {e}", ECLog.WARNING
|
|
281
|
+
)
|
|
282
|
+
time.sleep(1)
|
|
283
|
+
|
|
262
284
|
|
|
263
285
|
self.do_hash = transaction_hash
|
|
264
286
|
receipt = None
|
|
@@ -269,13 +291,13 @@ class EthernityCloudRunner:
|
|
|
269
291
|
)
|
|
270
292
|
|
|
271
293
|
is_processed = self.wait_for_transaction_to_be_processed(
|
|
272
|
-
self.
|
|
294
|
+
self.contract, transaction_hash
|
|
273
295
|
)
|
|
274
296
|
receipt = __provider.eth.wait_for_transaction_receipt(
|
|
275
297
|
transaction_hash
|
|
276
298
|
)
|
|
277
299
|
processed_logs = (
|
|
278
|
-
self.
|
|
300
|
+
self.protocol_contract.events._addDORequestEV().process_receipt(
|
|
279
301
|
receipt
|
|
280
302
|
)
|
|
281
303
|
)
|
|
@@ -352,58 +374,81 @@ class EthernityCloudRunner:
|
|
|
352
374
|
|
|
353
375
|
try:
|
|
354
376
|
self.log_append(f"Operator {self.order[1]} is processing task {order_id}")
|
|
355
|
-
while self.protocol_contract.get_status_from_order(order_id) == 1:
|
|
356
|
-
time.sleep(1)
|
|
357
|
-
|
|
358
|
-
order_result = self.protocol_contract.get_result_from_order(order_id)
|
|
359
377
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
378
|
+
while True:
|
|
379
|
+
try:
|
|
380
|
+
while self.contract.get_status_from_order(order_id) == 1:
|
|
381
|
+
time.sleep(1)
|
|
382
|
+
|
|
383
|
+
order_result = self.contract.get_result_from_order(order_id)
|
|
364
384
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
385
|
+
self.log_append(
|
|
386
|
+
f"Task {order_id} was successfully processed."
|
|
387
|
+
)
|
|
388
|
+
break
|
|
389
|
+
except Exception as e:
|
|
390
|
+
self.log_append(f"Checking order details: {e}", ECLog.WARNING)
|
|
368
391
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
392
|
+
try:
|
|
393
|
+
|
|
394
|
+
parsed_order_result = self.parse_order_result(order_result)
|
|
395
|
+
|
|
396
|
+
self.log_append(
|
|
397
|
+
f"Checking result hash: {parsed_order_result['result_ipfs_hash']}"
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
transaction_result = self.parse_transaction_bytes(
|
|
401
|
+
parsed_order_result["transaction_bytes"]
|
|
402
|
+
)
|
|
403
|
+
except Exception as e:
|
|
404
|
+
self.log_append(f"Error parsing transaction bytes: {e}", ECLog.ERROR)
|
|
405
|
+
self.log_append(f"Could not parse transaction bytes. The operator result is invalid, indicating a failure", ECLog.ERROR)
|
|
406
|
+
self.log_append(f"The tokens associated with the task will be refunded after automatic result validation", ECLog.ERROR)
|
|
407
|
+
self.log_append(f"Please try again.", ECLog.ERROR)
|
|
408
|
+
return False
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
self.log_append(f"Verifying ZK proof")
|
|
372
412
|
|
|
373
413
|
wallet = generate_wallet(
|
|
374
414
|
self.challenge_hash.decode("utf-8"), # type: ignore
|
|
375
415
|
transaction_result["enclave_challenge"],
|
|
376
416
|
)
|
|
377
417
|
if not wallet or wallet != transaction_result["from"]:
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
)
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
418
|
+
self.log_append(f"Integrity check failed, signer wallet address is wrong", ECLog.ERROR)
|
|
419
|
+
self.log_append(f"The tokens associated with the task will be refunded after automatic result validation.", ECLog.ERROR)
|
|
420
|
+
self.log_append(f"Please try running the task again", ECLog.ERROR)
|
|
421
|
+
return False
|
|
422
|
+
|
|
423
|
+
self.log_append(f"Verification succesful!")
|
|
424
|
+
self.log_append(f"The result is signed by: {wallet}")
|
|
425
|
+
|
|
426
|
+
while True:
|
|
427
|
+
try:
|
|
428
|
+
time.sleep(1)
|
|
429
|
+
self.log_append(f"Downloading {parsed_order_result['result_ipfs_hash']}")
|
|
430
|
+
|
|
431
|
+
ipfs_result = ipfsClient.get_file_content(
|
|
432
|
+
parsed_order_result["result_ipfs_hash"]
|
|
433
|
+
)
|
|
434
|
+
break
|
|
435
|
+
except Exception as e:
|
|
436
|
+
self.log_append(f"Error downloading IPFS result: {e}", ECLog.WARNING)
|
|
437
|
+
self.log_append(f"Retrying")
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
self.log_append(f"Decrypting result")
|
|
392
441
|
|
|
393
442
|
decrypted_data = decrypt_nacl(self.private_key, ipfs_result)
|
|
394
443
|
if not decrypted_data["success"]:
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
"message": "Could not decrypt the order result.",
|
|
398
|
-
}
|
|
444
|
+
self.log_append(f"Could not decrypt the order result.", ECLog.ERROR)
|
|
445
|
+
|
|
399
446
|
|
|
400
447
|
self.log_append(f"Result value: {decrypted_data['data']}",ECLog.DEBUG)
|
|
401
448
|
ipfs_result_checksum = sha256(decrypted_data["data"],True)
|
|
402
449
|
if ipfs_result_checksum != transaction_result["checksum"]:
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
"message": "Integrity check failed, checksum of the order result is wrong. {ipfs_result_checksum} != {transaction_result['checksum']}",
|
|
406
|
-
}
|
|
450
|
+
self.log_append(f"Integrity check failed, checksum of the order result is wrong. {ipfs_result_checksum} != {transaction_result['checksum']}", ECLog.ERROR)
|
|
451
|
+
return False
|
|
407
452
|
|
|
408
453
|
result_transaction_hash = ""
|
|
409
454
|
block_timestamp = 0
|
|
@@ -441,7 +486,7 @@ class EthernityCloudRunner:
|
|
|
441
486
|
|
|
442
487
|
return {
|
|
443
488
|
"success": True,
|
|
444
|
-
"contract_address": self.
|
|
489
|
+
"contract_address": self.contract.get_protocol_address(),
|
|
445
490
|
"input_transaction_hash": self.do_hash,
|
|
446
491
|
"output_transaction_hash": result_transaction_hash,
|
|
447
492
|
"order_id": order_id,
|
|
@@ -461,16 +506,22 @@ class EthernityCloudRunner:
|
|
|
461
506
|
)
|
|
462
507
|
|
|
463
508
|
if str(e) == ECError.PARSE_ERROR:
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
509
|
+
error_message = ECError.PARSE_ERROR
|
|
510
|
+
self.log_append(error_message)
|
|
511
|
+
self.progress = ECEvent.FINISHED
|
|
512
|
+
self.status = ECStatus.ERROR
|
|
513
|
+
return False
|
|
468
514
|
if str(e) == ECError.IPFS_DOWNLOAD_ERROR:
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
515
|
+
self.log_append("Unable to download result from ipfs, trying again",ECLog.WARNING)
|
|
516
|
+
time.sleep(5)
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
if (self.get_result_from_order_repeats > 10):
|
|
520
|
+
self.log_append("After multiple tries, the result cannot be downloaded", ECLog.ERROR)
|
|
521
|
+
self.progress = ECEvent.FINISHED
|
|
522
|
+
self.status = ECStatus.ERROR
|
|
523
|
+
return False
|
|
524
|
+
|
|
474
525
|
self.get_result_from_order_repeats += 1
|
|
475
526
|
return self.get_result_from_order(order_id)
|
|
476
527
|
|
|
@@ -481,6 +532,7 @@ class EthernityCloudRunner:
|
|
|
481
532
|
image_metadata = self.get_v3_image_metadata(self.challenge_hash)
|
|
482
533
|
code_metadata = self.get_v3_code_metadata(code)
|
|
483
534
|
input_metadata = self.get_v3_input_metadata()
|
|
535
|
+
self.current_order_index = self.protocol_contract.functions._getOrdersCount().call()
|
|
484
536
|
do_sent_successfully = self.create_do_request(
|
|
485
537
|
image_metadata, code_metadata, input_metadata, self.node_address, None
|
|
486
538
|
)
|
|
@@ -493,7 +545,7 @@ class EthernityCloudRunner:
|
|
|
493
545
|
self.log_append(
|
|
494
546
|
f"Waiting for Ethernity CLOUD network..."
|
|
495
547
|
)
|
|
496
|
-
|
|
548
|
+
|
|
497
549
|
while True:
|
|
498
550
|
try:
|
|
499
551
|
if self.find_order(self.do_request):
|
|
@@ -534,9 +586,10 @@ class EthernityCloudRunner:
|
|
|
534
586
|
|
|
535
587
|
|
|
536
588
|
def find_order(self, doreq: int) -> bool:
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
589
|
+
time.sleep(1)
|
|
590
|
+
count = self.protocol_contract.functions._getOrdersCount().call()
|
|
591
|
+
for i in range(count - 1, self.current_order_index - 1, -1):
|
|
592
|
+
order = self.protocol_contract.caller()._getOrder(i)
|
|
540
593
|
# if order[2] == doreq and order[4] == 0:
|
|
541
594
|
if order[2] == doreq:
|
|
542
595
|
self.order = order
|
|
@@ -545,7 +598,11 @@ class EthernityCloudRunner:
|
|
|
545
598
|
return False
|
|
546
599
|
|
|
547
600
|
def approve_order(self) -> bool:
|
|
548
|
-
transaction_hash = self.
|
|
601
|
+
transaction_hash = self.contract.approve_order(self.order_id)
|
|
602
|
+
|
|
603
|
+
if self.node_address != "":
|
|
604
|
+
self.log_append(f"Transaction is delegated to {self.node_address}, skipping approval")
|
|
605
|
+
return True
|
|
549
606
|
|
|
550
607
|
receipt = None
|
|
551
608
|
for i in range(100):
|
|
@@ -553,11 +610,11 @@ class EthernityCloudRunner:
|
|
|
553
610
|
self.log_append(
|
|
554
611
|
f"{transaction_hash} is pending..."
|
|
555
612
|
)
|
|
556
|
-
receipt = self.
|
|
613
|
+
receipt = self.contract.get_provider().eth.wait_for_transaction_receipt(
|
|
557
614
|
transaction_hash
|
|
558
615
|
)
|
|
559
616
|
if receipt is not None:
|
|
560
|
-
self.node_address = self.
|
|
617
|
+
self.node_address = self.contract.get_order(self.order_id)[1]
|
|
561
618
|
break
|
|
562
619
|
except KeyError:
|
|
563
620
|
time.sleep(1)
|
|
@@ -600,7 +657,7 @@ class EthernityCloudRunner:
|
|
|
600
657
|
return True
|
|
601
658
|
|
|
602
659
|
if is_address(node_address):
|
|
603
|
-
is_node = self.
|
|
660
|
+
is_node = self.contract.is_node_operator(node_address)
|
|
604
661
|
if not is_node:
|
|
605
662
|
self.log_append(
|
|
606
663
|
"The target address is not a valid node operator address",
|
|
@@ -636,7 +693,8 @@ class EthernityCloudRunner:
|
|
|
636
693
|
"validators": 1,
|
|
637
694
|
}
|
|
638
695
|
|
|
639
|
-
self.resources = resources
|
|
696
|
+
self.resources = resources
|
|
697
|
+
self.price = resources['taskPrice']
|
|
640
698
|
|
|
641
699
|
if self.running:
|
|
642
700
|
raise RuntimeError("A task is already running.")
|
|
@@ -680,14 +738,14 @@ class EthernityCloudRunner:
|
|
|
680
738
|
if event == ECEvent.INIT:
|
|
681
739
|
self.progress = ECEvent.INIT
|
|
682
740
|
self.log_append("Checking wallet balance...")
|
|
683
|
-
balance = self.
|
|
741
|
+
balance = self.contract.get_balance()
|
|
684
742
|
balance = int(balance)
|
|
685
743
|
|
|
686
|
-
if balance <
|
|
744
|
+
if balance < self.price:
|
|
687
745
|
self.progress = ECEvent.FINISHED
|
|
688
746
|
self.status = ECStatus.ERROR
|
|
689
747
|
error_message = (
|
|
690
|
-
f"Insufficient wallet balance. Required: {
|
|
748
|
+
f"Insufficient wallet balance. Required: {self.price}, "
|
|
691
749
|
f"Available: {balance}"
|
|
692
750
|
)
|
|
693
751
|
self.last_error = error_message
|
|
@@ -740,21 +798,19 @@ class EthernityCloudRunner:
|
|
|
740
798
|
ECAddress.POLYGON.TESTNET_ADDRESS,
|
|
741
799
|
]:
|
|
742
800
|
self.log_append(
|
|
743
|
-
"Checking
|
|
801
|
+
"Checking allowance on the current wallet..."
|
|
744
802
|
)
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
self.processed_events.append(event)
|
|
757
|
-
return
|
|
803
|
+
while True:
|
|
804
|
+
try:
|
|
805
|
+
passed_allowance = self.contract.check_and_set_allowance(
|
|
806
|
+
str(self.price),
|
|
807
|
+
)
|
|
808
|
+
if passed_allowance == True:
|
|
809
|
+
break
|
|
810
|
+
except Exception as e:
|
|
811
|
+
self.log_append(f"Unable to set allowance on current wallet: {e}", ECLog.WARNING)
|
|
812
|
+
self.log_append(f"Retrying...", ECLog.WARNING)
|
|
813
|
+
|
|
758
814
|
self.log_append("Allowance checking completed.")
|
|
759
815
|
if not self.create_task(code):
|
|
760
816
|
self.progress = ECEvent.FINISHED
|
|
@@ -13,10 +13,11 @@ ethernity_cloud_runner_py.egg-info/dependency_links.txt
|
|
|
13
13
|
ethernity_cloud_runner_py.egg-info/requires.txt
|
|
14
14
|
ethernity_cloud_runner_py.egg-info/top_level.txt
|
|
15
15
|
ethernity_cloud_runner_py/contract/__init__.py
|
|
16
|
+
ethernity_cloud_runner_py/contract/abi/ECLDAbi.py
|
|
16
17
|
ethernity_cloud_runner_py/contract/abi/__init__.py
|
|
17
18
|
ethernity_cloud_runner_py/contract/abi/bloxbergAbi.py
|
|
18
19
|
ethernity_cloud_runner_py/contract/abi/imageRegistryAbi.py
|
|
19
|
-
ethernity_cloud_runner_py/contract/abi/
|
|
20
|
+
ethernity_cloud_runner_py/contract/abi/polygonProtocolAbi.py
|
|
20
21
|
ethernity_cloud_runner_py/contract/operation/__init__.py
|
|
21
22
|
ethernity_cloud_runner_py/contract/operation/bloxbergProtocolContract.py
|
|
22
23
|
ethernity_cloud_runner_py/contract/operation/imageRegistryContract.py
|
|
@@ -13,7 +13,7 @@ print(this_directory);
|
|
|
13
13
|
|
|
14
14
|
setup(
|
|
15
15
|
name="ethernity-cloud-runner-py",
|
|
16
|
-
version="0.2.
|
|
16
|
+
version="0.2.4",
|
|
17
17
|
url="https://github.com/ethernity-cloud/ethernity-cloud-runner-py",
|
|
18
18
|
author="Ethernity Cloud Team",
|
|
19
19
|
author_email="contact@ethernity.cloud",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|