From 30aa64ef7627a15f3fa4ecf21f59c61e25c4fc88 Mon Sep 17 00:00:00 2001 From: Aklix Date: Fri, 17 Dec 2021 17:34:18 +0300 Subject: [PATCH 1/3] [rev] review use of logging functions in the code base and refactor accordingly [fix] marmaracreditloop search with txid is not covering all results, resulting in fill of the respective fields [rem] removed decode(uft8) to decode() --- src/main/python/configuration.py | 4 +-- src/main/python/mainApp.py | 56 +++++++++++++++++++---------- src/main/python/marmarachain_rpc.py | 18 ++++------ 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/main/python/configuration.py b/src/main/python/configuration.py index df297df..f87c010 100644 --- a/src/main/python/configuration.py +++ b/src/main/python/configuration.py @@ -28,8 +28,8 @@ log_file_path = os.path.join(config_directory_path, "marmara-connector.log") # configure log file directory logging.getLogger(__name__) stream_handler = logging.StreamHandler() # create stream handler and set level to debug -stream_handler.setLevel(logging.DEBUG) # set stream handler level to debug -logging.basicConfig(level=logging.DEBUG, +stream_handler.setLevel(logging.INFO) # set stream handler level to debug +logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s:%(module)s %(funcName)s:%(lineno)s %(message)s', handlers=[logging.FileHandler(filename=log_file_path, mode='a+'), stream_handler]) diff --git a/src/main/python/mainApp.py b/src/main/python/mainApp.py index 9e1d828..a837b58 100644 --- a/src/main/python/mainApp.py +++ b/src/main/python/mainApp.py @@ -573,8 +573,6 @@ def check_marmara_path(self): @pyqtSlot(str) def check_marmara_path_output(self, output): - logging.info('Checking marmara path') - logging.info('login:' + output) if output == 'get marmarad path': self.login_page_info(self.tr('Getting marmara chain path from config file')) logging.info('Getting marmara chain path from config file') @@ -989,12 +987,12 @@ def toggle_staking(self): if message_box == QMessageBox.Yes: self.mining_button.setChecked(False) # Close mining and set staking mode self.cpu_core_selection_off() - logging.debug('setgenerate True 0') + logging.info('setgenerate True 0') self.setgenerate([True, 0]) if message_box == QMessageBox.No: # Abort selecting staking and continue mining self.staking_button.setChecked(False) else: # set staking mode - logging.debug('setgenerate True 0') + logging.info('setgenerate True 0') self.setgenerate([True, 0]) else: # Staking button status is False message_box = self.custom_message(self.tr('Turning off Staking'), @@ -1002,7 +1000,7 @@ def toggle_staking(self): QMessageBox.Question) if message_box == QMessageBox.Yes: - logging.debug('setgenerate False') + logging.info('setgenerate False') self.setgenerate([False]) if message_box == QMessageBox.No: self.staking_button.setChecked(True) # Abort selecting staking button @@ -1018,13 +1016,13 @@ def toggle_mining(self): QMessageBox.Question) if message_box == QMessageBox.Yes: self.staking_button.setChecked(False) # Close staking and turn on mining - logging.debug('setgenerate True 1') + logging.info('setgenerate True 1') self.setgenerate([True, 1]) self.cpu_core_selection_on() if message_box == QMessageBox.No: # Abort selecting mining and continue staking self.mining_button.setChecked(False) else: # Staking is off turn on Mining mode - logging.debug('setgenerate True 1') + logging.info('setgenerate True 1') self.cpu_core_selection_on() self.setgenerate([True, 1]) else: # Mining button status is False. @@ -1032,7 +1030,7 @@ def toggle_mining(self): self.tr('You are about to turn off mining. Are you sure?'), "question", QMessageBox.Question) if message_box == QMessageBox.Yes: - logging.debug('setgenerate False') + logging.info('setgenerate False') self.cpu_core_selection_off() self.setgenerate([False]) if message_box == QMessageBox.No: @@ -1058,7 +1056,7 @@ def setgenerate(self, arg): @pyqtSlot(tuple) def setgenerate_result(self, result_out): if result_out[0]: - logging.debug('\n---- getgenerate result------\n' + str(json.loads(result_out[0]))) + logging.info('\n---- getgenerate result------\n' + str(json.loads(result_out[0]))) result = json.loads(result_out[0]) if result.get('staking') is True and result.get('generate') is False: self.bottom_info(self.tr('Staking ON')) @@ -1257,8 +1255,8 @@ def set_pubkey_result(self, result_out): def start_chain_with_pubkey(self): button = self.sender() index = self.addresses_tableWidget.indexAt(button.pos()) - logging.debug(index.row()) - logging.debug(index.column()) + logging.info(index.row()) + logging.info(index.column()) if index.isValid(): pubkey = self.addresses_tableWidget.item(index.row(), 3).text() self.start_chain_settings(pubkey) @@ -1886,7 +1884,7 @@ def getaddresstxids_result(self, result_out): for txid in result_out[0]: self.bottom_info(self.tr("fetched transactions between selected dates.")) row_number = result_out[0].index(txid) - btn_explorer = QPushButton(qta.icon('mdi.firefox'), '') + btn_explorer = QPushButton(qta.icon('mdi.firefox', color='#728FCE'), '') btn_explorer.setIconSize(QSize(24, 24)) txid_date = datetime.fromtimestamp(txid[2]).date() self.transactions_tableWidget.setCellWidget(row_number, 0, btn_explorer) @@ -2008,7 +2006,7 @@ def set_credit_request_table(self, credit_request_list): self.loop_request_tableWidget.setColumnHidden(5, True) for row in credit_request_list: row_number = credit_request_list.index(row) - btn_review = QPushButton(qta.icon('mdi.text-box-check-outline'), '') + btn_review = QPushButton(qta.icon('mdi.text-box-check-outline', color='#728FCE'), '') btn_review.setIconSize(QSize(24, 24)) self.loop_request_tableWidget.setCellWidget(row_number, 0, btn_review) self.loop_request_tableWidget.setItem(row_number, 1, QTableWidgetItem(str(row[0]))) @@ -2037,7 +2035,7 @@ def set_transfer_request_table(self, transfer_request_list): self.transferrequests_tableWidget.setColumnHidden(5, True) for row in transfer_request_list: row_number = transfer_request_list.index(row) - btn_review = QPushButton(qta.icon('mdi.text-box-check-outline'), '') + btn_review = QPushButton(qta.icon('mdi.text-box-check-outline', color='#728FCE'), '') btn_review.setIconSize(QSize(24, 24)) self.transferrequests_tableWidget.setCellWidget(row_number, 0, btn_review) self.transferrequests_tableWidget.setItem(row_number, 1, QTableWidgetItem(str(row[0]))) @@ -2225,6 +2223,7 @@ def loops_details_result(self, result_out): if result_out[2] == 0: self.set_activeloops_table(result_out[0]) self.set_loop_amount_result(result_out[1]) + self.refresh_loopinfo_button.setVisible(True) if result_out[2] == 1: print(result_out[1]) self.bottom_err_info(result_out[1]) @@ -2421,14 +2420,33 @@ def search_loop_txid_result(self, result_out): if result.get('result') == "error": self.bottom_info(result.get('error')) self.clear_lq_txid_search_result() - if result.get('result') == "success": + else: creditloop = result.get('creditloop') - self.loopquery_baton_value.setText(str(result.get('batontxid'))) - self.loopquery_amount_value.setText(str(result.get('amount'))) + if str(result.get('funcid')) == 'S': + baton = str(result.get('settlement')) + batonpk = str(result.get('pubkey')) + amount = str(result.get('collected')) + self.loopquery_baton_label.setText(self.tr('Txid (Settlement)')) + issuerpk = str((creditloop[0]).get('issuerpk')) + elif str(result.get('funcid')) == 'B': + issuerpk = str(result.get('issuerpk')) + amount = str(result.get('amount')) + baton = str(result.get('createtxid')) + batonpk = str(self.tr('Not issued yet!')) + self.loopquery_baton_label.setText(self.tr('Txid (baton)')) + else: + baton = str(result.get('batontxid')) + batonpk = str(result.get('batonpk')) + amount = str(result.get('amount')) + issuerpk = str((creditloop[0]).get('issuerpk')) + self.loopquery_baton_label.setText(self.tr('Txid (baton)')) + + self.loopquery_baton_value.setText(baton) + self.loopquery_amount_value.setText(amount) self.loopquery_currency_value.setText(result.get('currency')) self.loopquery_matures_value.setText(str(result.get('matures'))) - self.loopquery_batonpk_value.setText(str(result.get('batonpk'))) - self.loopquery_issuer_value.setText(str((creditloop[0]).get('issuerpk'))) + self.loopquery_batonpk_value.setText(batonpk) + self.loopquery_issuer_value.setText(issuerpk) self.loopquery_transfercount_value.setText(str(result.get('n'))) self.bottom_info(self.tr('credit loop info finished')) logging.info('credit loop info finished') diff --git a/src/main/python/marmarachain_rpc.py b/src/main/python/marmarachain_rpc.py index 82c32b7..d272ac4 100644 --- a/src/main/python/marmarachain_rpc.py +++ b/src/main/python/marmarachain_rpc.py @@ -68,7 +68,7 @@ def do_search_path(cmd): mcl_path = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) mcl_path.wait() mcl_path.terminate() - return mcl_path.stdout.read().decode("utf8").split('\n'), mcl_path.stdout.read().decode("utf8").split('\n') + return mcl_path.stdout.read().decode().split('\n'), mcl_path.stdout.read().decode().split('\n') except Exception as error: logging.error(error) else: @@ -197,7 +197,7 @@ def mcl_chain_status(): marmarad_pid = subprocess.Popen(marmara_pid, shell=True, stdout=subprocess.PIPE) marmarad_pid.wait() marmarad_pid.terminate() - return marmarad_pid.stdout.read().decode("utf8"), marmarad_pid.stdout.read().decode("utf8") + return marmarad_pid.stdout.read().decode(), marmarad_pid.stdout.read().decode() except Exception as error: logging.error(error) else: @@ -517,13 +517,11 @@ def extract_bootstrap(self): def do_execute_extract(self, cmd_list): pwd_home = str(pathlib.Path.home()) for cmd in cmd_list: - print(cmd) proc = subprocess.Popen(cmd, cwd=pwd_home, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) retvalue = proc.poll() while True: stdout = proc.stdout.readline().replace(b'\n', b'').replace(b'\r', b'').decode() self.output.emit(str(stdout)) - print(stdout) logging.info(str(stdout)) if not stdout: break @@ -549,7 +547,7 @@ def get_loop_detail(self, txid, holder=False): break return [txid, loop_amount, pubkey, loop_matures, loop_create_block, loop_address] else: - print(loop_detail[1]) + logging.error(loop_detail[1]) return False @pyqtSlot() @@ -566,7 +564,6 @@ def active_loops_details(self): issuer_details_list.append(issuance_details) else: logging.error('some error in getting loopdetail') - print('some error in getting loopdetail') self.finished.emit() break result = issuer_details_list, marmarainfo_result, 0 @@ -591,7 +588,6 @@ def holder_loop_detail(self): holder_details_list.append(issuance_details) else: logging.error('some error in getting loopdetail') - print('some error in getting loopdetail') self.finished.emit() break result = holder_details_list, holer_result, 0 @@ -669,7 +665,7 @@ def linux_install(self): cmd = self.linux_command_list[i] if cmd.startswith('sudo'): cmd = 'sudo -k -S -- ' + cmd + '\n' - logging.debug(cmd) + logging.info(cmd) if is_local: proc = subprocess.Popen(cmd, cwd=str(pathlib.Path.home()), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) @@ -686,7 +682,7 @@ def linux_install(self): if not out: proc.stdout.close() exit_status = proc.poll() - logging.debug('exit_status :' + str(exit_status)) + logging.info('exit_status :' + str(exit_status)) proc.terminate() i = i + 1 if i >= len(self.linux_command_list): @@ -740,7 +736,7 @@ def windows_install(self): self.progress.emit(10) else: cwd = str(pathlib.Path.home()) + '\marmara' - logging.debug(cwd) + logging.info(cwd) proc = subprocess.Popen(cmd, cwd=cwd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while not proc.stdout.closed: @@ -749,7 +745,6 @@ def windows_install(self): out_d = out.decode() except: out_d = '*-*-' - print(out_d) self.out_text.emit(out_d) if not out: proc.stdout.close() @@ -807,7 +802,6 @@ def remote_chain_update(self): self.mcl_linux_zipname, 'unzip -o ' + marmara_path + self.mcl_linux_zipname + ' -d ' + marmara_path] sshclient = remote_connection.server_ssh_connect() for cmd in cmd_list: - print(cmd) session = sshclient.get_transport().open_session() session.set_combine_stderr(True) session.get_pty() From a42c7d5de0e45cfc9472d55b6a6377345dca384f Mon Sep 17 00:00:00 2001 From: Aklix Date: Fri, 17 Dec 2021 17:57:20 +0300 Subject: [PATCH 2/3] version updated. --- requirements | 2 +- src/build/settings/base.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements b/requirements index 5d379b4..6846b13 100644 --- a/requirements +++ b/requirements @@ -1,4 +1,4 @@ -pip==21.2.4 +pip==21.3.1 fbs==0.9.0 qrcode==7.2 paramiko==2.7.2 diff --git a/src/build/settings/base.json b/src/build/settings/base.json index fbc1d1a..18d34c2 100755 --- a/src/build/settings/base.json +++ b/src/build/settings/base.json @@ -2,6 +2,6 @@ "app_name": "MarmaraConnector", "author": "Marmara Credit Loops", "main_module": "src/main/python/mainApp.py", - "version": "0.3.4-alpha", + "version": "0.3.5-alpha", "public_settings": ["app_name", "author", "version"] } From 48f133f183fa610a5461a87c4e222b183854fd97 Mon Sep 17 00:00:00 2001 From: Aklix Date: Fri, 17 Dec 2021 18:17:27 +0300 Subject: [PATCH 3/3] [ref] code comment changed. --- src/main/python/configuration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/python/configuration.py b/src/main/python/configuration.py index f87c010..0e60751 100644 --- a/src/main/python/configuration.py +++ b/src/main/python/configuration.py @@ -27,8 +27,8 @@ log_file_path = os.path.join(config_directory_path, "marmara-connector.log") # configure log file directory logging.getLogger(__name__) -stream_handler = logging.StreamHandler() # create stream handler and set level to debug -stream_handler.setLevel(logging.INFO) # set stream handler level to debug +stream_handler = logging.StreamHandler() # create stream handler and set level to info +stream_handler.setLevel(logging.INFO) # set stream handler level to info logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s:%(module)s %(funcName)s:%(lineno)s %(message)s', handlers=[logging.FileHandler(filename=log_file_path, mode='a+'), stream_handler])