Skip to content

Commit

Permalink
account: Use relayFee setting.
Browse files Browse the repository at this point in the history
Remove the realyFee method from dcrdata and have all relay fees passed
in order to separate functions cleanly. Relay fees now depend upon the
account calling the dcrdata method.
  • Loading branch information
JoeGruffins committed Apr 23, 2020
1 parent 41db3e8 commit 6a8caec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
12 changes: 6 additions & 6 deletions decred/decred/dcr/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@ def addressSignal(self, addr, txid):
# signal the balance update
self.signals.balance(self.calcBalance())

def sendToAddress(self, value, address, feeRate=None):
def sendToAddress(self, value, address):
"""
Send the value to the address.
Expand All @@ -1880,7 +1880,7 @@ def sendToAddress(self, value, address, feeRate=None):
priv=self.privKeyForAddress, internal=self.nextInternalAddress,
)
tx, spentUTXOs, newUTXOs = self.blockchain.sendToAddress(
value, address, keysource, self.getUTXOs, feeRate
value, address, keysource, self.getUTXOs, self.relayFee
)
self.addMempoolTx(tx)
self.spendUTXOs(spentUTXOs)
Expand All @@ -1907,13 +1907,13 @@ def purchaseTickets(self, qty, price):
spendLimit=int(round(price * qty * 1.1 * 1e8)), # convert to atoms here
poolAddress=pi.poolAddress,
votingAddress=pi.ticketAddress,
ticketFee=0, # use network default
ticketFee=DefaultRelayFeePerKb,
poolFees=pi.poolFees,
count=qty,
txFee=0, # use network default
txFee=self.relayFee,
)
txs, spentUTXOs, newUTXOs = self.blockchain.purchaseTickets(
keysource, self.getUTXOs, req
keysource, self.getUTXOs, req, self.relayFee
)
# Add the split transactions
self.addMempoolTx(txs[0])
Expand Down Expand Up @@ -1962,7 +1962,7 @@ def revokeTickets(self):
priv=lambda _: self._votingKey,
internal=lambda: "",
)
self.blockchain.revokeTicket(tx, keysource, redeemScript)
self.blockchain.revokeTicket(tx, keysource, redeemScript, self.relayFee)

def sync(self):
"""
Expand Down
27 changes: 9 additions & 18 deletions decred/decred/dcr/dcrdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,15 +841,6 @@ def updateTip(self):
log.error("failed to retrieve tip from blockchain: %s" % formatTraceback(e))
raise DecredError("no tip data retrieved")

def relayFee(self):
"""
Return the current transaction fee.
Returns:
int: Atoms per kB of encoded transaction.
"""
return txscript.DefaultRelayFeePerKb

def saveBlockHeader(self, header):
"""
Save the block header to the database.
Expand All @@ -861,7 +852,7 @@ def saveBlockHeader(self, header):
self.heightMap[header.height] = bHash
self.headerDB[bHash] = header

def sendToAddress(self, value, address, keysource, utxosource, feeRate=None):
def sendToAddress(self, value, address, keysource, utxosource, relayFee):
"""
Send the amount in atoms to the specified address.
Expand All @@ -880,7 +871,7 @@ def sendToAddress(self, value, address, keysource, utxosource, feeRate=None):
"""
self.updateTip()
outputs = makeOutputs([(address, value)], self.netParams)
return self.sendOutputs(outputs, keysource, utxosource, feeRate)
return self.sendOutputs(outputs, keysource, utxosource, relayFee)

def broadcast(self, txHex):
"""
Expand Down Expand Up @@ -962,7 +953,7 @@ def confirmUTXO(self, utxo, block=None, tx=None):
pass
return False

def sendOutputs(self, outputs, keysource, utxosource, feeRate=None):
def sendOutputs(self, outputs, keysource, utxosource, relayFee):
"""
Send the `TxOut`s to the address.
Expand Down Expand Up @@ -998,7 +989,7 @@ def sendOutputs(self, outputs, keysource, utxosource, feeRate=None):
changeScriptVersion = txscript.DefaultScriptVersion
changeScriptSize = txscript.P2PKHPkScriptSize

relayFeePerKb = feeRate * 1e3 if feeRate else self.relayFee()
relayFeePerKb = relayFee * 1e3
for (i, txout) in enumerate(outputs):
checkOutput(txout, relayFeePerKb)

Expand Down Expand Up @@ -1110,7 +1101,7 @@ def sendOutputs(self, outputs, keysource, utxosource, feeRate=None):

return newTx, utxos, newUTXOs

def purchaseTickets(self, keysource, utxosource, req):
def purchaseTickets(self, keysource, utxosource, req, relayFee):
"""
Based on dcrwallet (*Wallet).purchaseTickets.
purchaseTickets indicates to the wallet that a ticket should be
Expand Down Expand Up @@ -1207,7 +1198,7 @@ def purchaseTickets(self, keysource, utxosource, req):

ticketFeeIncrement = req.ticketFee
if ticketFeeIncrement == 0:
ticketFeeIncrement = self.relayFee()
ticketFeeIncrement = relayFee

# Make sure that we have enough funds. Calculate different
# ticket required amounts depending on whether or not a
Expand Down Expand Up @@ -1272,7 +1263,7 @@ def purchaseTickets(self, keysource, utxosource, req):

txFeeIncrement = req.txFee
if txFeeIncrement == 0:
txFeeIncrement = self.relayFee()
txFeeIncrement = relayFee

# Send the split transaction.
# sendOutputs takes the fee rate in atoms/byte
Expand Down Expand Up @@ -1373,7 +1364,7 @@ def purchaseTickets(self, keysource, utxosource, req):
)
return (splitTx, tickets), splitSpent, internalOutputs

def revokeTicket(self, tx, keysource, redeemScript):
def revokeTicket(self, tx, keysource, redeemScript, relayFee):
"""
Revoke a ticket by signing the supplied redeem script and broadcasting
the raw transaction.
Expand All @@ -1389,7 +1380,7 @@ def revokeTicket(self, tx, keysource, redeemScript):
MsgTx: the signed revocation.
"""

revocation = txscript.makeRevocation(tx, self.relayFee())
revocation = txscript.makeRevocation(tx, relayFee)

signedScript = txscript.signTxOutput(
self.netParams,
Expand Down
4 changes: 2 additions & 2 deletions decred/tests/integration/dcr/test_dcrdata_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def utxosource(amt, filter):
)

ticket, spent, newUTXOs = blockchain.purchaseTickets(
KeySource(), utxosource, request
KeySource(), utxosource, request, 1e4
)
finally:
blockchain.close()
Expand Down Expand Up @@ -248,5 +248,5 @@ def __init__(
internal=lambda: "",
)
redeemScript = ByteArray(test.redeemScript)
revocation = blockchain.revokeTicket(ticket, keysource, redeemScript)
revocation = blockchain.revokeTicket(ticket, keysource, redeemScript, 1e4)
assert test.revocation == revocation.txHex()

0 comments on commit 6a8caec

Please sign in to comment.