def estimate_step(self, transaction: Transaction, full_response: bool = False) -> int: """ Returns an estimated step of how much step is necessary to allow the transaction to complete. :param transaction: a raw transaction :param full_response: a boolean indicating whether or not it returns refined data :return: an estimated step """ if not isinstance(transaction, Transaction): raise DataTypeException("Transaction object is unrecognized.") params = { "version": convert_int_to_hex_str(transaction.version) if transaction.version else "0x3", "from": transaction.from_, "to": transaction.to, "timestamp": convert_int_to_hex_str(transaction.timestamp) if transaction.timestamp else get_timestamp(), "nid": convert_int_to_hex_str(transaction.nid) if transaction.nid else "0x1" } if transaction.value is not None: params["value"] = convert_int_to_hex_str(transaction.value) if transaction.nonce is not None: params["nonce"] = convert_int_to_hex_str(transaction.nonce) if transaction.data_type is not None: params["dataType"] = transaction.data_type if transaction.data_type in ('deploy', 'call'): params["data"] = generate_data_value(transaction) elif transaction.data_type == 'message': params["data"] = transaction.data result = self.__provider.make_request('debug_estimateStep', params, full_response) return result if full_response else int(result, 16)
def convert_tx_to_jsonrpc_request(transaction: Transaction, wallet: Wallet = None) -> dict: """Converts an instance of the transaction into JSON RPC request in dict""" dict_tx = { "version": convert_int_to_hex_str(transaction.version) if transaction.version else "0x3", "from": transaction.from_ if transaction.from_ else wallet.get_address(), "to": transaction.to, "stepLimit": convert_int_to_hex_str(transaction.step_limit), "timestamp": convert_int_to_hex_str(transaction.timestamp) if transaction.timestamp else get_timestamp(), "nid": convert_int_to_hex_str(transaction.nid) if transaction.nid else "0x1" } if transaction.value is not None: dict_tx["value"] = convert_int_to_hex_str(transaction.value) if transaction.nonce is not None: dict_tx["nonce"] = convert_int_to_hex_str(transaction.nonce) if transaction.data_type is not None: dict_tx["dataType"] = transaction.data_type if transaction.data_type in ('deploy', 'call'): dict_tx["data"] = generate_data_value(transaction) elif transaction.data_type == 'message': dict_tx["data"] = transaction.data elif transaction.data_type == "deposit": dict_tx["data"] = {"action": transaction.action} if transaction.action == "withdraw": if transaction.id is not None: dict_tx["data"]["id"] = transaction.id elif transaction.amount is not None: dict_tx["data"]["amount"] = convert_int_to_hex_str( transaction.amount) return dict_tx