def response(self, group_index, from_node_index, secret_number, multiplied_share): op = self.contract.functions.response(group_index, from_node_index, secret_number, multiplied_share) tx = post_transaction(self.skale.wallet, op, GAS['dkg_response'], dkg_gas_price(self.skale.gas_price)) return {'tx': tx}
def broadcast(self, group_index, node_index, verification_vector, secret_key_conribution): op = self.contract.functions.broadcast(group_index, node_index, verification_vector, secret_key_conribution) tx = post_transaction(self.skale.wallet, op, GAS['dkg_broadcast'], dkg_gas_price(self.skale.gas_price)) return {'tx': tx}
def create_schain(self, lifetime, type_of_nodes, deposit, name): logger.info( f'create_schain: type_of_nodes: {type_of_nodes}, name: {name}') token = self.skale.get_contract_by_name('token') skale_nonce = helper.generate_nonce() transaction_data = self.create_schain_data_to_bytes( lifetime, type_of_nodes, name, skale_nonce) op = token.contract.functions.send(self.address, deposit, transaction_data) tx = post_transaction(self.skale.wallet, op, GAS['create_schain']) return {'tx': tx, 'nonce': skale_nonce}
def run_func(self, contract_name, function_name, is_call, kwargs): cm_name = to_camel_case(contract_name) address = self.cm_contract.get_contract_address(cm_name) address = get_contract_address_by_name(self.abi, contract_name) abi = get_contract_abi_by_name(self.abi, contract_name) contract = BaseContract( skale=self.skale, name=contract_name, address=address, abi=abi ) for name in kwargs: if check_int(kwargs[name]): kwargs[name] = int(kwargs[name]) params = list(kwargs.values()) print(f'RUNNING:{function_name}:{contract_name}') contract_funcs = contract.contract.functions func_to_run = getattr(contract_funcs, function_name) if is_call: if CALL_SENDER is not None: p = {'from': CALL_SENDER} else: p = {} gas = func_to_run(*params).estimateGas(p) print(f'GAS_USED:{gas}') res = func_to_run(*params).call(p) else: tx_hash = post_transaction(self.wallet, func_to_run(*params), 8000000) res = wait_for_receipt_by_blocks( self.skale.web3, tx_hash ) return res
def create_node(self, ip, port, name, public_ip=None): logger.info( f'create_node: {ip}:{port}, public ip: {public_ip} name: {name}') token = self.skale.get_contract_by_name('token') skale_nonce = helper.generate_nonce() pk = self.skale.wallet.public_key if not public_ip: public_ip = ip transaction_data = self.create_node_data_to_bytes( ip, public_ip, port, name, pk, skale_nonce) op = token.contract.functions.send(self.address, NODE_DEPOSIT, transaction_data) tx = post_transaction(self.skale.wallet, op, GAS['create_node']) return {'tx': tx, 'nonce': skale_nonce}
def get_bounty(self, node_id): op = self.contract.functions.getBounty(node_id) tx = post_transaction(self.skale.wallet, op, GAS['get_bounty']) return {'tx': tx}
def set_latency(self, new_allowable_latency): op = self.contract.functions.setLatency(new_allowable_latency) tx = post_transaction(self.skale.wallet, op, GAS['set_latency']) return {'tx': tx}
def set_check_time(self, new_check_time): op = self.contract.functions.setCheckTime(new_check_time) tx = post_transaction(self.skale.wallet, op, GAS['set_check_time']) return {'tx': tx}
def set_periods(self, new_reward_period, new_delta_period): op = self.contract.functions.setPeriods(new_reward_period, new_delta_period) tx = post_transaction(self.skale.wallet, op, GAS['set_periods']) return {'tx': tx}
def add_authorized(self, address, wallet): # pragma: no cover op = self.contract.functions.addAuthorized(address) tx = post_transaction(self.skale.wallet, op, GAS['token_transfer']) return {'tx': tx}
def transfer(self, address, value): op = self.contract.functions.send(address, value, b'') tx = post_transaction(self.skale.wallet, op, GAS['token_transfer']) return {'tx': tx}
def complaint(self, group_index, from_node_index, to_node_index): op = self.contract.functions.complaint(group_index, from_node_index, to_node_index) tx = post_transaction(self.skale.wallet, op, GAS['dkg_complaint'], dkg_gas_price(self.skale.gas_price)) return {'tx': tx}
def send_verdicts(self, validator, nodes_ids, downtimes, latencies): op = self.contract.functions.sendVerdicts(validator, nodes_ids, downtimes, latencies) tx = post_transaction(self.skale.wallet, op, GAS['send_verdicts']) return {'tx': tx}
def send_verdict(self, validator, node_id, downtime, latency): op = self.contract.functions.sendVerdict(validator, node_id, downtime, latency) tx = post_transaction(self.skale.wallet, op, GAS['send_verdict']) return {'tx': tx}
def deregister(self, node_id): op = self.contract.functions.deleteNode(node_id) tx = post_transaction(self.skale.wallet, op, GAS['delete_node']) return {'tx': tx}
def delete_node_by_root(self, node_id): op = self.contract.functions.deleteNodeByRoot(node_id) tx = post_transaction(self.skale.wallet, op, GAS['delete_node_by_root']) return {'tx': tx}
def delete_schain(self, schain_name): op = self.contract.functions.deleteSchain(schain_name) tx = post_transaction(self.skale.wallet, op, GAS['delete_schain']) return {'tx': tx}