Skip to content

Commit 74a15b9

Browse files
committed
fix bugs when missing rpc reply
1 parent 3bbd793 commit 74a15b9

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

src/misc.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,24 @@ def printDbg_msg(what):
343343
return log_line
344344

345345

346+
def printError_msg(what):
347+
what = clean_for_html(what)
348+
timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(now()))
349+
log_line = '<b style="color: yellow">{}</b> : <em style="color: red">{}</em><br>'.format(timestamp, what)
350+
return log_line
351+
352+
346353

347354
def printDbg(what):
348355
log_line = printDbg_msg(what)
349356
append_to_logfile(log_line)
350357
print(log_line)
351358

352-
359+
360+
def printError(what):
361+
log_line = printError_msg(what)
362+
append_to_logfile(log_line)
363+
print(log_line)
353364

354365

355366
def printException_msg(

src/qt/dlg_findCollTx.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def load_utxos_thread(self, ctrl):
8383
self.apiConnected = True
8484
self.blockCount = self.mainTab.caller.rpcClient.getBlockCount()
8585
utxos = self.mainTab.caller.apiClient.getAddressUtxos(self.pivx_addr)['unspent_outputs']
86-
printDbg("loading utxos\nblockCount=%s\n%s" % (str(self.blockCount), str(self.utxos)))
8786
self.utxos = [utxo for utxo in utxos if round(int(utxo.get('value', 0))/1e8, 8) == 10000.00000000 ]
8887

8988
except Exception as e:

src/qt/dlg_sweepAll.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ def display_utxos(self):
7777

7878
# update fee per Kb
7979
if self.main_tab.caller.rpcConnected:
80-
self.feePerKb = self.main_tab.caller.rpcClient.getFeePerKb()
80+
self.feePerKb = self.main_tab.caller.rpcClient.getFeePerKb()
81+
if self.feePerKb is None:
82+
self.feePerKb = MINIMUM_FEE
83+
else:
84+
self.feePerKb = MINIMUM_FEE
8185

8286
def item(value):
8387
item = QTableWidgetItem(value)
@@ -211,6 +215,8 @@ def FinishSend(self, serialized_tx, amount_to_send):
211215

212216
else:
213217
decodedTx = self.main_tab.caller.rpcClient.decodeRawTransaction(tx_hex)
218+
if decodedTx is None:
219+
raise Exception("Unable to decode TX - connection to RPC server lost.")
214220
destination = decodedTx.get("vout")[0].get("scriptPubKey").get("addresses")[0]
215221
amount = decodedTx.get("vout")[0].get("value")
216222
message = '<p>Broadcast signed transaction?</p><p>Destination address:<br><b>%s</b></p>' % destination
@@ -223,6 +229,8 @@ def FinishSend(self, serialized_tx, amount_to_send):
223229
reply = mess1.exec_()
224230
if reply == QMessageBox.Yes:
225231
txid = self.main_tab.caller.rpcClient.sendRawTransaction(tx_hex, self.useSwiftX())
232+
if txid is None:
233+
raise Exception("Unable to send TX - connection to RPC server lost.")
226234
mess2_text = "<p>Transaction successfully sent.</p>"
227235
mess2 = QMessageBox(QMessageBox.Information, 'transaction Sent', mess2_text)
228236
mess2.setDetailedText(txid)
@@ -235,7 +243,7 @@ def FinishSend(self, serialized_tx, amount_to_send):
235243

236244
except Exception as e:
237245
err_msg = "Exception in FinishSend"
238-
printException(getCallerName(), getFunctionName(), err_msg, e.args)
246+
printException(getCallerName(), getFunctionName(), err_msg, e)
239247

240248

241249

src/tabRewards.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from apiClient import ApiClient
1212
from constants import MPATH, MINIMUM_FEE
1313
from hwdevice import DisconnectedException
14-
from misc import printDbg, printException, getCallerName, getFunctionName, persistCacheSetting, myPopUp, myPopUp_sb
14+
from misc import printDbg, printError, printException, getCallerName, getFunctionName, persistCacheSetting, myPopUp, myPopUp_sb
1515
from qt.gui_tabRewards import TabRewards_gui
1616
from threads import ThreadFuns
1717
from utils import checkPivxAddr
@@ -74,6 +74,10 @@ def display_mn_utxos(self):
7474
# update fee
7575
if self.caller.rpcConnected:
7676
self.feePerKb = self.caller.rpcClient.getFeePerKb()
77+
if self.feePerKb is None:
78+
self.feePerKb = MINIMUM_FEE
79+
else:
80+
self.feePerKb = MINIMUM_FEE
7781

7882
rewards = self.caller.parent.db.getRewardsList(self.curr_name)
7983
self.updateTotalBalance(rewards)
@@ -188,24 +192,23 @@ def load_utxos_thread(self, ctrl):
188192

189193
# If rpc is not connected warn and return.
190194
if not self.caller.rpcConnected:
191-
printDbg('PIVX daemon not connected - Unable to update UTXO list')
195+
printError('PIVX daemon not connected - Unable to update UTXO list')
192196
return
193197

194198
api_status = self.caller.apiClient.getStatus()
195199
if api_status != 200:
196-
printDbg("Wrong response from API client. Status: %s" % api_status)
200+
printError("Wrong response from API client. Status: %s" % api_status)
197201
return
198202

199203
self.apiConnected = True
200-
self.blockCount = self.caller.rpcClient.getBlockCount()
201204

202205
for mn in self.caller.masternode_list:
203206
# Load UTXOs from API client
204207
rewards = self.caller.apiClient.getAddressUtxos(
205208
mn['collateral'].get('address'))['unspent_outputs']
206209

207210
if rewards is None:
208-
printDbg('Error occurred while calling getaddressutxos method.')
211+
printError('API client not responding.')
209212
return
210213

211214
# for each UTXO
@@ -215,7 +218,7 @@ def load_utxos_thread(self, ctrl):
215218

216219
# Don't save UTXO if raw TX is unavailable
217220
if rawtx is None:
218-
printDbg("Unable to get raw TX with hash=%s from RPC server" % utxo['tx_hash'])
221+
printError("Unable to get raw TX with hash=%s from RPC server" % utxo['tx_hash'])
219222
continue
220223

221224
# Add mn_name and raw_tx to UTXO and save it to DB
@@ -412,6 +415,8 @@ def FinishSend(self, serialized_tx, amount_to_send):
412415

413416
else:
414417
decodedTx = self.caller.rpcClient.decodeRawTransaction(tx_hex)
418+
if decodedTx is None:
419+
raise Exception("Unable to decode TX - connection to RPC server lost.")
415420
destination = decodedTx.get("vout")[0].get("scriptPubKey").get("addresses")[0]
416421
amount = decodedTx.get("vout")[0].get("value")
417422
message = '<p>Broadcast signed transaction?</p><p>Destination address:<br><b>%s</b></p>' % destination
@@ -424,6 +429,9 @@ def FinishSend(self, serialized_tx, amount_to_send):
424429
reply = mess1.exec_()
425430
if reply == QMessageBox.Yes:
426431
txid = self.caller.rpcClient.sendRawTransaction(tx_hex, self.useSwiftX())
432+
if txid is None:
433+
raise Exception("Unable to send TX - connection to RPC server lost.")
434+
427435
mess2_text = "<p>Transaction successfully sent.</p>"
428436
mess2 = QMessageBox(QMessageBox.Information, 'transaction Sent', mess2_text)
429437
mess2.setDetailedText(txid)

0 commit comments

Comments
 (0)