Skip to content

Commit

Permalink
compute avg fee in thread using last 200 blocks instead of 10
Browse files Browse the repository at this point in the history
  • Loading branch information
gpdionisio committed Jun 7, 2018
1 parent e361ac5 commit 82d1997
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Click on `Hide Collateral` to hide it again.
<br><img src="doc/img/17.png" width="670"><br><br>

Select those UTXOs you wish to spend.<br>
The suggested fee is automatically adjusted based on the TX size and the average fee of the last 10 blocks.<br>
The suggested fee is automatically adjusted based on the TX size and the average fee of the last 200 blocks.<br>
Adjust it as preferred.<br>
Then insert the PIVX `Destination Address` and click on `Send`
<br><img src="doc/img/18.png" width="670"><br><br>
Expand Down
6 changes: 3 additions & 3 deletions src/qt/dlg_sweepAll.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def item(value):

# update fee
estimatedTxSize = (44+numOfInputs*148)*1.0 / 1000 # kB
feePerKb = self.main_tab.caller.rpcClient.getFeePerKb()
suggestedFee = round(feePerKb * estimatedTxSize, 8)
suggestedFee = round(self.feePerKb * estimatedTxSize, 8)
self.ui.feeLine.setValue(suggestedFee)

# load last used destination from cache
Expand Down Expand Up @@ -109,7 +108,8 @@ def load_utxos_thread(self, ctrl):
print("Unable to get raw TX from RPC server\n")
self.rewards = []
return

# update fee
self.feePerKb = self.main_tab.caller.rpcClient.getFeePerKb()



Expand Down
4 changes: 2 additions & 2 deletions src/rpcClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def getBlockHash(self, blockNum):
def getFeePerKb(self):
try:
self.lock.acquire()
# get transaction data from last 10 blocks
feePerKb = float(self.conn.getfeeinfo(10)['feeperkb'])
# get transaction data from last 120 blocks
feePerKb = float(self.conn.getfeeinfo(200)['feeperkb'])
res = (feePerKb if feePerKb > MINIMUM_FEE else MINIMUM_FEE)
except Exception as e:
err_msg = 'error in getFeePerKb'
Expand Down
14 changes: 10 additions & 4 deletions src/tabRewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, caller):
self.rewards = None
self.selectedRewards = None
self.rawtransactions = {}
self.feePerKb = MINIMUM_FEE
##--- Initialize GUI
self.ui = TabRewards_gui()
self.caller.tabRewards = self.ui
Expand Down Expand Up @@ -85,6 +86,8 @@ def item(value):
self.ui.rewardsList.statusLabel.setText('<b style="color:purple">Unable to connect to API provider</b>')
self.ui.rewardsList.statusLabel.setVisible(True)






Expand Down Expand Up @@ -136,15 +139,19 @@ def load_utxos_thread(self, ctrl):
try:
if self.caller.apiClient.getStatus() != 200:
return

self.apiConnected = True
self.blockCount = self.caller.rpcClient.getBlockCount()
self.rewards = self.caller.apiClient.getAddressUtxos(self.curr_addr)['unspent_outputs']

for utxo in self.rewards:
rawtx = self.caller.rpcClient.getRawTransaction(utxo['tx_hash'])
self.rawtransactions[utxo['tx_hash']] = rawtx
if rawtx is None:
print("Unable to get raw TX from RPC server\n")

self.feePerKb = self.caller.rpcClient.getFeePerKb()

except Exception as e:
self.errorMsg = 'Error occurred while calling getaddressutxos method: ' + str(e)
printDbg(self.errorMsg)
Expand Down Expand Up @@ -379,13 +386,12 @@ def updateSelection(self, clicked_item=None):

for i in range(0, numOfInputs):
total += int(self.selectedRewards[i].get('value'))

# update suggested fee and selected rewards
estimatedTxSize = (44+numOfInputs*148)*1.0 / 1000 # kB
feePerKb = self.caller.rpcClient.getFeePerKb()
suggestedFee = round(feePerKb * estimatedTxSize, 8)
suggestedFee = round(self.feePerKb * estimatedTxSize, 8)
printDbg("estimatedTxSize is %s kB" % str(estimatedTxSize))
printDbg("suggested fee is %s PIV (%s PIV/kB)" % (str(suggestedFee), str(feePerKb)))
printDbg("suggested fee is %s PIV (%s PIV/kB)" % (str(suggestedFee), str(self.feePerKb)))

self.ui.selectedRewardsLine.setText(str(round(total/1e8, 8)))
self.ui.feeLine.setValue(suggestedFee)
Expand Down

0 comments on commit 82d1997

Please sign in to comment.