feat: scheduler contract's caller for testing
This commit is contained in:
commit
2d0582e8ad
30
main.py
Normal file
30
main.py
Normal file
@ -0,0 +1,30 @@
|
||||
import json
|
||||
from web3 import Web3
|
||||
from src.scheduler import Scheduler
|
||||
|
||||
SCHEDULER_ADDR = "0x13D69Cf7d6CE4218F646B759Dcf334D82c023d8e"
|
||||
SCHEDULER_ABI_FILE = "../gpu-contract/abi/Scheduler.abi"
|
||||
|
||||
PROVIDER1_KEY = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
|
||||
PROVIDER2_KEY = "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
|
||||
PROVIDER3_KEY = "0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a"
|
||||
|
||||
CLIENT_KEY = "0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6"
|
||||
|
||||
w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:8545'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if w3.is_connected():
|
||||
scheduler = Scheduler(w3, SCHEDULER_ADDR, SCHEDULER_ABI_FILE)
|
||||
|
||||
provider1 = w3.eth.account.from_key(PROVIDER1_KEY)
|
||||
provider2 = w3.eth.account.from_key(PROVIDER2_KEY)
|
||||
provider3 = w3.eth.account.from_key(PROVIDER3_KEY)
|
||||
client = w3.eth.account.from_key(CLIENT_KEY)
|
||||
|
||||
print(scheduler.getClusters())
|
||||
|
||||
else:
|
||||
print("cannot connected to the chain")
|
||||
|
||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
web3==6.18.0
|
||||
BIN
src/__pycache__/scheduler.cpython-310.pyc
Normal file
BIN
src/__pycache__/scheduler.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/utils.cpython-310.pyc
Normal file
BIN
src/__pycache__/utils.cpython-310.pyc
Normal file
Binary file not shown.
29
src/scheduler.py
Normal file
29
src/scheduler.py
Normal file
@ -0,0 +1,29 @@
|
||||
from web3 import Web3
|
||||
from src.utils import load_abi
|
||||
|
||||
class Scheduler():
|
||||
def __init__(self, w3: Web3, address: str, abi_file: str):
|
||||
self.w3 = w3
|
||||
abi = load_abi(abi_file)
|
||||
self.contract = self.w3.eth.contract(address=address, abi=abi)
|
||||
|
||||
def registerCluster(self, account, gpu_id: int, gpu_num: int):
|
||||
tx = self.contract.functions.registerCluster(gpu_id, gpu_num).build_transaction({
|
||||
'from': account.address,
|
||||
'nonce': self.w3.eth.get_transaction_count(account.address)
|
||||
})
|
||||
signed_tx = self.w3.eth.account.sign_transaction(tx, private_key=account.key)
|
||||
|
||||
tx_hash = self.w3.eth.send_raw_transaction(signed_tx.rawTransaction)
|
||||
tx_receipt = self.w3.eth.wait_for_transaction_receipt(tx_hash)
|
||||
print(tx_receipt)
|
||||
_hash = tx_receipt['transactionHash']
|
||||
print(self.w3.eth.get_transaction(_hash))
|
||||
|
||||
def getClusters(self):
|
||||
return self.contract.functions.getClusters().call()
|
||||
|
||||
def getStartRunEvent(self):
|
||||
event_filter = self.contract.events.StartRun.create_filter(fromBlock=0)
|
||||
events = event_filter.get_new_entries()
|
||||
print(events)
|
||||
4
src/utils.py
Normal file
4
src/utils.py
Normal file
@ -0,0 +1,4 @@
|
||||
def load_abi(file):
|
||||
with open(file) as fp:
|
||||
abi = fp.read()
|
||||
return abi
|
||||
Loading…
Reference in New Issue
Block a user