Skip to content

Commit 6a8caec

Browse files
committed
account: Use relayFee setting.
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.
1 parent 41db3e8 commit 6a8caec

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

decred/decred/dcr/account.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ def addressSignal(self, addr, txid):
18651865
# signal the balance update
18661866
self.signals.balance(self.calcBalance())
18671867

1868-
def sendToAddress(self, value, address, feeRate=None):
1868+
def sendToAddress(self, value, address):
18691869
"""
18701870
Send the value to the address.
18711871
@@ -1880,7 +1880,7 @@ def sendToAddress(self, value, address, feeRate=None):
18801880
priv=self.privKeyForAddress, internal=self.nextInternalAddress,
18811881
)
18821882
tx, spentUTXOs, newUTXOs = self.blockchain.sendToAddress(
1883-
value, address, keysource, self.getUTXOs, feeRate
1883+
value, address, keysource, self.getUTXOs, self.relayFee
18841884
)
18851885
self.addMempoolTx(tx)
18861886
self.spendUTXOs(spentUTXOs)
@@ -1907,13 +1907,13 @@ def purchaseTickets(self, qty, price):
19071907
spendLimit=int(round(price * qty * 1.1 * 1e8)), # convert to atoms here
19081908
poolAddress=pi.poolAddress,
19091909
votingAddress=pi.ticketAddress,
1910-
ticketFee=0, # use network default
1910+
ticketFee=DefaultRelayFeePerKb,
19111911
poolFees=pi.poolFees,
19121912
count=qty,
1913-
txFee=0, # use network default
1913+
txFee=self.relayFee,
19141914
)
19151915
txs, spentUTXOs, newUTXOs = self.blockchain.purchaseTickets(
1916-
keysource, self.getUTXOs, req
1916+
keysource, self.getUTXOs, req, self.relayFee
19171917
)
19181918
# Add the split transactions
19191919
self.addMempoolTx(txs[0])
@@ -1962,7 +1962,7 @@ def revokeTickets(self):
19621962
priv=lambda _: self._votingKey,
19631963
internal=lambda: "",
19641964
)
1965-
self.blockchain.revokeTicket(tx, keysource, redeemScript)
1965+
self.blockchain.revokeTicket(tx, keysource, redeemScript, self.relayFee)
19661966

19671967
def sync(self):
19681968
"""

decred/decred/dcr/dcrdata.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -841,15 +841,6 @@ def updateTip(self):
841841
log.error("failed to retrieve tip from blockchain: %s" % formatTraceback(e))
842842
raise DecredError("no tip data retrieved")
843843

844-
def relayFee(self):
845-
"""
846-
Return the current transaction fee.
847-
848-
Returns:
849-
int: Atoms per kB of encoded transaction.
850-
"""
851-
return txscript.DefaultRelayFeePerKb
852-
853844
def saveBlockHeader(self, header):
854845
"""
855846
Save the block header to the database.
@@ -861,7 +852,7 @@ def saveBlockHeader(self, header):
861852
self.heightMap[header.height] = bHash
862853
self.headerDB[bHash] = header
863854

864-
def sendToAddress(self, value, address, keysource, utxosource, feeRate=None):
855+
def sendToAddress(self, value, address, keysource, utxosource, relayFee):
865856
"""
866857
Send the amount in atoms to the specified address.
867858
@@ -880,7 +871,7 @@ def sendToAddress(self, value, address, keysource, utxosource, feeRate=None):
880871
"""
881872
self.updateTip()
882873
outputs = makeOutputs([(address, value)], self.netParams)
883-
return self.sendOutputs(outputs, keysource, utxosource, feeRate)
874+
return self.sendOutputs(outputs, keysource, utxosource, relayFee)
884875

885876
def broadcast(self, txHex):
886877
"""
@@ -962,7 +953,7 @@ def confirmUTXO(self, utxo, block=None, tx=None):
962953
pass
963954
return False
964955

965-
def sendOutputs(self, outputs, keysource, utxosource, feeRate=None):
956+
def sendOutputs(self, outputs, keysource, utxosource, relayFee):
966957
"""
967958
Send the `TxOut`s to the address.
968959
@@ -998,7 +989,7 @@ def sendOutputs(self, outputs, keysource, utxosource, feeRate=None):
998989
changeScriptVersion = txscript.DefaultScriptVersion
999990
changeScriptSize = txscript.P2PKHPkScriptSize
1000991

1001-
relayFeePerKb = feeRate * 1e3 if feeRate else self.relayFee()
992+
relayFeePerKb = relayFee * 1e3
1002993
for (i, txout) in enumerate(outputs):
1003994
checkOutput(txout, relayFeePerKb)
1004995

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

11111102
return newTx, utxos, newUTXOs
11121103

1113-
def purchaseTickets(self, keysource, utxosource, req):
1104+
def purchaseTickets(self, keysource, utxosource, req, relayFee):
11141105
"""
11151106
Based on dcrwallet (*Wallet).purchaseTickets.
11161107
purchaseTickets indicates to the wallet that a ticket should be
@@ -1207,7 +1198,7 @@ def purchaseTickets(self, keysource, utxosource, req):
12071198

12081199
ticketFeeIncrement = req.ticketFee
12091200
if ticketFeeIncrement == 0:
1210-
ticketFeeIncrement = self.relayFee()
1201+
ticketFeeIncrement = relayFee
12111202

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

12731264
txFeeIncrement = req.txFee
12741265
if txFeeIncrement == 0:
1275-
txFeeIncrement = self.relayFee()
1266+
txFeeIncrement = relayFee
12761267

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

1376-
def revokeTicket(self, tx, keysource, redeemScript):
1367+
def revokeTicket(self, tx, keysource, redeemScript, relayFee):
13771368
"""
13781369
Revoke a ticket by signing the supplied redeem script and broadcasting
13791370
the raw transaction.
@@ -1389,7 +1380,7 @@ def revokeTicket(self, tx, keysource, redeemScript):
13891380
MsgTx: the signed revocation.
13901381
"""
13911382

1392-
revocation = txscript.makeRevocation(tx, self.relayFee())
1383+
revocation = txscript.makeRevocation(tx, relayFee)
13931384

13941385
signedScript = txscript.signTxOutput(
13951386
self.netParams,

decred/tests/integration/dcr/test_dcrdata_live.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def utxosource(amt, filter):
138138
)
139139

140140
ticket, spent, newUTXOs = blockchain.purchaseTickets(
141-
KeySource(), utxosource, request
141+
KeySource(), utxosource, request, 1e4
142142
)
143143
finally:
144144
blockchain.close()
@@ -248,5 +248,5 @@ def __init__(
248248
internal=lambda: "",
249249
)
250250
redeemScript = ByteArray(test.redeemScript)
251-
revocation = blockchain.revokeTicket(ticket, keysource, redeemScript)
251+
revocation = blockchain.revokeTicket(ticket, keysource, redeemScript, 1e4)
252252
assert test.revocation == revocation.txHex()

0 commit comments

Comments
 (0)