def rpc_post(self, api, params=None, headers=None, form=None, unit=None, format_str=None): try: data = None url = None if format_str: data = super_json_dumps(params) else: if params: data = json.dumps(params) elif form: data = form if unit == "wallet": url = self.rpc_base_wallet_url + api response = requests.post(url, data=data, headers=headers, timeout=3600) if response.status_code in (200, 201): return response.json() else: if api != "/unlock": raise Exception("http code: " + str(response.status_code)) except Exception as e: raise_logger("Exception rpc_post: " + str(e), "wallet", "error") return {}
def end(cls, floor="3"): """ 计时log,统计运行时间 :return: """ cls.end_time = time.time() record = "%.10f seconds" % (cls.end_time - cls.begin_time) sys_frame = sys._getframe() floor_back = { "1": sys_frame, "2": sys_frame.f_back, "3": sys_frame.f_back.f_back if hasattr(sys_frame.f_back, "f_back") else None, } floor_back["4"] = floor_back["3"].f_back if floor_back["3"] else None floor_back["5"] = floor_back["4"].f_back if floor_back["4"] else None f_back = floor_back[str(floor)] file_path = str(f_back.f_code.co_filename) line_no = str(f_back.f_lineno) func_name = str(f_back.f_code.co_name) if file_path[0] == "/": if log_server_name in file_path: file_path = file_path[file_path.rindex(log_server_name) + len(log_server_name):] file = " file:" + file_path + " line:" + line_no + " func:" + func_name record = super_json_dumps({ "position": file, "msg": record }) timing_logger.info(record)
def raise_logger(msg, log_name='rs', lv="info", file=None): """ :param msg: 日志的写入内容,若为int,则表示为报错编码;为str则是报错信息 :param log_name: 要写入的日志文件 rs game_bet_in game_product block wallet script :param lv: 级别 info error :param file: 报错文件行数 :return: """ try: if not isinstance(msg, str): record = super_json_dumps(msg) else: record = msg except Exception as e: record = str(e) f_back = sys._getframe().f_back if not file: file_path = str(f_back.f_code.co_filename) if file_path[0] == "/": file_path = file_path[file_path.rindex(log_server_name) + len(log_server_name):] line_no = str(f_back.f_lineno) func_name = str(f_back.f_code.co_name) file = " file:" + file_path + " line:" + line_no + " func:" + func_name record = super_json_dumps({ "file": file, "msg": record }) logger_switch = { "rs": logger, "game_bet_in": game_bet_in_logger, "game_publish_lottery": game_publish_lottery, "game_product": game_product_logger, "block": block_logger, "wallet": wallet_logger, "script": script_logger, } tmp_logger = logger_switch.get(log_name, "") if not tmp_logger: raise Exception("The log name is wrong") if lv == 'error': tmp_logger.error(record) elif lv == 'info': tmp_logger.info(record)
def http_abi_json_to_bin(self, params): """ :param args: :return: """ api = "abi_json_to_bin" sign_args = { "code": "eosio.token", "action": "transfer", "args": params } data = super_json_dumps(sign_args) res = self.http_post(params=data, api=api) return res
def http_post(self, params=None, headers=None, api=None): try: data = None url = self.http_base_url if api: url += "/v1/chain/" + api + "?apikey=" + self.http_api_key if params: data = super_json_dumps(params) response = requests.post(url, data=data, headers=headers, timeout=3600) if response.status_code in (200, 201): return response.json() else: raise Exception("http code: " + str(response.status_code)) except Exception as e: raise_logger("Exception http_post: " + str(e), "wallet", "error") return {}
def end(self): """ 计时log,统计运行时间 :return: """ self.end_time = time.time() record = "%.10f seconds" % (self.end_time - self.begin_time) file_path = self.file_path line_no = self.line_no func_name = self.func_name if file_path[0] == "/": if log_server_name in file_path: file_path = file_path[file_path.rindex(log_server_name) + len(log_server_name):] file = " file:" + file_path + " line:" + line_no + " func:" + func_name record = super_json_dumps({ "position": file, "msg": record }) timing_logger.info(record)
def rpc_post(self, api, params=None, headers=None, form=None, unit=None, format_str=None): try: data = None if params: data = json.dumps(params) if form: data = form if format_str: data = super_json_dumps(params) print(data) url = None if not unit: url = self.rpc_base_url + api elif unit == "wallet": url = self.rpc_base_wallet_url + api response = requests.post(url, data=data, headers=headers, timeout=3600) if response.status_code in (200, 201): return response.json() else: raise Exception("http code: " + str(response.status_code)) except Exception as e: print(e) return