Skip to content

Commit 5302606

Browse files
authored
Merge pull request #10317 from f321x/fix_payto
cli: payto: fix feerate parsing
2 parents dabf5bb + 114c48e commit 5302606

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

electrum/commands.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,8 @@ async def sweep(self, privkey, destination, fee=None, feerate=None, nocheck=Fals
880880
881881
arg:str:privkey:Private key. Type \'?\' to get a prompt.
882882
arg:str:destination:Bitcoin address, contact or alias
883-
arg:str:fee:Transaction fee (absolute, in BTC)
884-
arg:str:feerate:Transaction fee rate (in sat/vbyte)
883+
arg:decimal:fee:Transaction fee (absolute, in BTC)
884+
arg:decimal:feerate:Transaction fee rate (in sat/vbyte)
885885
arg:int:imax:Maximum number of inputs
886886
arg:bool:nocheck:Do not verify aliases
887887
"""
@@ -925,15 +925,15 @@ async def verifymessage(self, address, signature, message):
925925
message = util.to_bytes(message)
926926
return bitcoin.verify_usermessage_with_address(address, sig, message)
927927

928-
def _get_fee_policy(self, fee, feerate):
928+
def _get_fee_policy(self, fee: str, feerate: str):
929929
if fee is not None and feerate is not None:
930930
raise Exception('Cannot set both fee and feerate')
931931
if fee is not None:
932932
fee_sats = satoshis(fee)
933933
fee_policy = FeePolicy(f'fixed:{fee_sats}')
934934
elif feerate is not None:
935-
feerate_per_byte = 1000 * feerate
936-
fee_policy = FeePolicy(f'feerate:{feerate_per_byte}')
935+
sat_per_kvbyte = int(1000 * to_decimal(feerate))
936+
fee_policy = FeePolicy(f'feerate:{sat_per_kvbyte}')
937937
else:
938938
fee_policy = FeePolicy(self.config.FEE_POLICY)
939939
return fee_policy
@@ -946,7 +946,7 @@ async def payto(self, destination, amount, fee=None, feerate=None, from_addr=Non
946946
arg:str:destination:Bitcoin address, contact or alias
947947
arg:decimal_or_max:amount:Amount to be sent (in BTC). Type '!' to send the maximum available.
948948
arg:decimal:fee:Transaction fee (absolute, in BTC)
949-
arg:float:feerate:Transaction fee rate (in sat/vbyte)
949+
arg:decimal:feerate:Transaction fee rate (in sat/vbyte)
950950
arg:str:from_addr:Source address (must be a wallet address; use sweep to spend from non-wallet address)
951951
arg:str:change_addr:Change address. Default is a spare address, or the source address if it's not in the wallet
952952
arg:bool:rbf:Whether to signal opt-in Replace-By-Fee in the transaction (true/false)
@@ -979,8 +979,8 @@ async def paytomany(self, outputs, fee=None, feerate=None, from_addr=None, from_
979979
980980
arg:json:outputs:json list of ["address", "amount in BTC"]
981981
arg:bool:rbf:Whether to signal opt-in Replace-By-Fee in the transaction (true/false)
982-
arg:str:fee:Transaction fee (absolute, in BTC)
983-
arg:str:feerate:Transaction fee rate (in sat/vbyte)
982+
arg:decimal:fee:Transaction fee (absolute, in BTC)
983+
arg:decimal:feerate:Transaction fee rate (in sat/vbyte)
984984
arg:str:from_addr:Source address (must be a wallet address; use sweep to spend from non-wallet address)
985985
arg:str:change_addr:Change address. Default is a spare address, or the source address if it's not in the wallet
986986
arg:bool:addtransaction:Whether transaction is to be used for broadcasting afterwards. Adds transaction to the wallet

tests/test_commands.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ async def test_payto(self, mock_save_db):
313313
locktime=1972344,
314314
wallet=wallet)
315315

316+
tx_str_2 = await cmds.payto(
317+
destination="tb1qsyzgpwa0vg2940u5t6l97etuvedr5dejpf9tdy",
318+
amount="0.00123456",
319+
feerate="50.000", # test that passing a string feerate results in the same tx
320+
locktime=1972344,
321+
wallet=wallet)
322+
323+
self.assertEqual(tx_str, tx_str_2)
316324
tx = tx_from_any(tx_str)
317325
self.assertEqual(2, len(tx.outputs()))
318326
txout = TxOutput.from_address_and_value("tb1qsyzgpwa0vg2940u5t6l97etuvedr5dejpf9tdy", 123456)

0 commit comments

Comments
 (0)