Skip to content

Commit a06b98b

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 a06b98b

File tree

3 files changed

+20
-30
lines changed

3 files changed

+20
-30
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: 12 additions & 22 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,14 +989,13 @@ 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()
1002992
for (i, txout) in enumerate(outputs):
1003-
checkOutput(txout, relayFeePerKb)
993+
checkOutput(txout, relayFee)
1004994

1005995
signedSize = txscript.estimateSerializeSize(
1006996
[txscript.RedeemP2PKHSigScriptSize], outputs, changeScriptSize
1007997
)
1008-
targetFee = txscript.calcMinRequiredTxRelayFee(relayFeePerKb, signedSize)
998+
targetFee = txscript.calcMinRequiredTxRelayFee(relayFee, signedSize)
1009999
targetAmount = sum(txo.value for txo in outputs)
10101000

10111001
while True:
@@ -1034,7 +1024,7 @@ def sendOutputs(self, outputs, keysource, utxosource, feeRate=None):
10341024
signedSize = txscript.estimateSerializeSize(
10351025
scriptSizes, outputs, changeScriptSize
10361026
)
1037-
requiredFee = txscript.calcMinRequiredTxRelayFee(relayFeePerKb, signedSize)
1027+
requiredFee = txscript.calcMinRequiredTxRelayFee(relayFee, signedSize)
10381028
remainingAmount = total - targetAmount
10391029
if remainingAmount < requiredFee:
10401030
targetFee = requiredFee
@@ -1055,7 +1045,7 @@ def sendOutputs(self, outputs, keysource, utxosource, feeRate=None):
10551045
changeVout = -1
10561046
changeAmount = round(total - targetAmount - requiredFee)
10571047
if changeAmount != 0 and not txscript.isDustAmount(
1058-
changeAmount, changeScriptSize, relayFeePerKb
1048+
changeAmount, changeScriptSize, relayFee
10591049
):
10601050
if len(changeScript) > txscript.MaxScriptElementSize:
10611051
raise DecredError(
@@ -1110,7 +1100,7 @@ def sendOutputs(self, outputs, keysource, utxosource, feeRate=None):
11101100

11111101
return newTx, utxos, newUTXOs
11121102

1113-
def purchaseTickets(self, keysource, utxosource, req):
1103+
def purchaseTickets(self, keysource, utxosource, req, relayFee):
11141104
"""
11151105
Based on dcrwallet (*Wallet).purchaseTickets.
11161106
purchaseTickets indicates to the wallet that a ticket should be
@@ -1207,7 +1197,7 @@ def purchaseTickets(self, keysource, utxosource, req):
12071197

12081198
ticketFeeIncrement = req.ticketFee
12091199
if ticketFeeIncrement == 0:
1210-
ticketFeeIncrement = self.relayFee()
1200+
ticketFeeIncrement = relayFee
12111201

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

12731263
txFeeIncrement = req.txFee
12741264
if txFeeIncrement == 0:
1275-
txFeeIncrement = self.relayFee()
1265+
txFeeIncrement = relayFee
12761266

12771267
# Send the split transaction.
12781268
# sendOutputs takes the fee rate in atoms/byte
@@ -1373,7 +1363,7 @@ def purchaseTickets(self, keysource, utxosource, req):
13731363
)
13741364
return (splitTx, tickets), splitSpent, internalOutputs
13751365

1376-
def revokeTicket(self, tx, keysource, redeemScript):
1366+
def revokeTicket(self, tx, keysource, redeemScript, relayFee):
13771367
"""
13781368
Revoke a ticket by signing the supplied redeem script and broadcasting
13791369
the raw transaction.
@@ -1389,7 +1379,7 @@ def revokeTicket(self, tx, keysource, redeemScript):
13891379
MsgTx: the signed revocation.
13901380
"""
13911381

1392-
revocation = txscript.makeRevocation(tx, self.relayFee())
1382+
revocation = txscript.makeRevocation(tx, relayFee)
13931383

13941384
signedScript = txscript.signTxOutput(
13951385
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)