@@ -852,13 +852,25 @@ def saveBlockHeader(self, header):
852852 self .heightMap [header .height ] = bHash
853853 self .headerDB [bHash ] = header
854854
855- def sendToAddress (self , value , address , keysource , utxosource , relayFee ):
855+ def checkFeeRate (self , relayFee ):
856+ """
857+ Check that the relay fee is lower than the allowed max of
858+ txscript.HighFeeRate.
859+ """
860+ if relayFee > txscript .HighFeeRate :
861+ raise DecredError (
862+ f"relay fee of { relayFee } is above the allowed max of { txscript .HighFeeRate } "
863+ )
864+
865+ def sendToAddress (
866+ self , value , address , keysource , utxosource , relayFee , allowHighFees = False
867+ ):
856868 """
857869 Send the amount in atoms to the specified address.
858870
859871 Args:
860- value int: The amount to send, in atoms.
861- address str: The base-58 encoded address.
872+ value ( int) : The amount to send, in atoms.
873+ address ( str) : The base-58 encoded address.
862874 keysource func(str) -> PrivateKey: A function that returns the
863875 private key for an address.
864876 utxosource func(int, func(UTXO) -> bool) -> list(UTXO): A function
@@ -867,11 +879,18 @@ def sendToAddress(self, value, address, keysource, utxosource, relayFee):
867879 amount. If the filtering function is provided, UTXOs for which
868880 the function return a falsey value will not be included in the
869881 returned UTXO list.
870- MsgTx: The newly created transaction on success, `False` on failure.
882+ relayFee (int): Transaction fees in atoms per kb.
883+ allowHighFees (bool): Optional. Default is False. Whether to allow
884+ fees higher than txscript.HighFeeRate.
885+
886+ Returns:
887+ MsgTx: The newly created transaction. Raises an exception on error.
871888 """
889+ if not allowHighFees :
890+ self .checkFeeRate (relayFee )
872891 self .updateTip ()
873892 outputs = makeOutputs ([(address , value )], self .netParams )
874- return self .sendOutputs (outputs , keysource , utxosource , relayFee )
893+ return self .sendOutputs (outputs , keysource , utxosource , relayFee , allowHighFees )
875894
876895 def broadcast (self , txHex ):
877896 """
@@ -953,7 +972,9 @@ def confirmUTXO(self, utxo, block=None, tx=None):
953972 pass
954973 return False
955974
956- def sendOutputs (self , outputs , keysource , utxosource , relayFee ):
975+ def sendOutputs (
976+ self , outputs , keysource , utxosource , relayFee , allowHighFees = False
977+ ):
957978 """
958979 Send the `TxOut`s to the address.
959980
@@ -973,12 +994,17 @@ def sendOutputs(self, outputs, keysource, utxosource, relayFee):
973994 sufficient to complete the transaction. If the filtering
974995 function is provided, UTXOs for which the function return a
975996 falsey value will not be included in the returned UTXO list.
997+ relayFee (int): Transaction fees in atoms per kb.
998+ allowHighFees (bool): Optional. Default is False. Whether to allow
999+ fees higher than txscript.HighFeeRate.
9761000
9771001 Returns:
9781002 newTx MsgTx: The sent transaction.
9791003 utxos list(UTXO): The spent UTXOs.
9801004 newUTXOs list(UTXO): Length 1 array containing the new change UTXO.
9811005 """
1006+ if not allowHighFees :
1007+ self .checkFeeRate (relayFee )
9821008 total = 0
9831009 inputs = []
9841010 scripts = []
@@ -1100,7 +1126,9 @@ def sendOutputs(self, outputs, keysource, utxosource, relayFee):
11001126
11011127 return newTx , utxos , newUTXOs
11021128
1103- def purchaseTickets (self , keysource , utxosource , req , relayFee ):
1129+ def purchaseTickets (
1130+ self , keysource , utxosource , req , relayFee , allowHighFees = False
1131+ ):
11041132 """
11051133 Based on dcrwallet (*Wallet).purchaseTickets.
11061134 purchaseTickets indicates to the wallet that a ticket should be
@@ -1115,6 +1143,9 @@ def purchaseTickets(self, keysource, utxosource, req, relayFee):
11151143 UTXOs. The filterFunc is an optional function to filter UTXOs,
11161144 and is of the form func(UTXO) -> bool.
11171145 req account.TicketRequest: the ticket data.
1146+ relayFee (int): Transaction fees in atoms per kb.
1147+ allowHighFees (bool): Optional. Default is False. Whether to allow
1148+ fees higher than txscript.HighFeeRate.
11181149
11191150 Returns:
11201151 (splitTx, tickets) tuple: first element is the split transaction.
@@ -1125,6 +1156,8 @@ def purchaseTickets(self, keysource, utxosource, req, relayFee):
11251156 addresses.
11261157
11271158 """
1159+ if not allowHighFees :
1160+ self .checkFeeRate (relayFee )
11281161 self .updateTip ()
11291162 # account minConf is zero for regular outputs for now. Need to make that
11301163 # adjustable.
@@ -1267,7 +1300,7 @@ def purchaseTickets(self, keysource, utxosource, req, relayFee):
12671300 # Send the split transaction.
12681301 # sendOutputs takes the fee rate in atoms/byte
12691302 splitTx , splitSpent , internalOutputs = self .sendOutputs (
1270- splitOuts , keysource , utxosource , int ( txFeeIncrement / 1000 )
1303+ splitOuts , keysource , utxosource , txFeeIncrement // 1000 , allowHighFees
12711304 )
12721305
12731306 # Generate the tickets individually.
@@ -1363,7 +1396,7 @@ def purchaseTickets(self, keysource, utxosource, req, relayFee):
13631396 )
13641397 return (splitTx , tickets ), splitSpent , internalOutputs
13651398
1366- def revokeTicket (self , tx , keysource , redeemScript , relayFee ):
1399+ def revokeTicket (self , tx , keysource , redeemScript , relayFee , allowHighFees = False ):
13671400 """
13681401 Revoke a ticket by signing the supplied redeem script and broadcasting
13691402 the raw transaction.
@@ -1374,10 +1407,15 @@ def revokeTicket(self, tx, keysource, redeemScript, relayFee):
13741407 the private key used for signing.
13751408 redeemScript (byte-like): the 1-of-2 multisig script that delegates
13761409 voting rights for the ticket.
1410+ relayFee (int): Transaction fees in atoms per kb.
1411+ allowHighFees (bool): Optional. Default is False. Whether to allow
1412+ fees higher than txscript.HighFeeRate.
13771413
13781414 Returns:
13791415 MsgTx: the signed revocation.
13801416 """
1417+ if not allowHighFees :
1418+ self .checkFeeRate (relayFee )
13811419
13821420 revocation = txscript .makeRevocation (tx , relayFee )
13831421
0 commit comments