From d2ba17c76a84e4a62db08e35af7dbdfd9835427b Mon Sep 17 00:00:00 2001 From: manfromsiberia Date: Fri, 6 Dec 2019 15:25:16 +0300 Subject: [PATCH 1/2] add correct handling for param fee in prepare_transaction when fee is 0 +sanity check for fee type, should fix #90 --- bit/wallet.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bit/wallet.py b/bit/wallet.py index 5a29cec..301b19b 100644 --- a/bit/wallet.py +++ b/bit/wallet.py @@ -766,10 +766,12 @@ def prepare_transaction(cls, address, outputs, compressed=True, fee=None, :returns: JSON storing data required to create an offline transaction. :rtype: ``str`` """ + if not isinstance(fee, (int, type(None))): + raise TypeError('Invalid fee type.') unspents, outputs = sanitize_tx_data( unspents or NetworkAPI.get_unspent_testnet(address), outputs, - fee or get_fee_cached(), + fee if isinstance(fee, int) else get_fee_cached(), leftover or address, combine=combine, message=message, From e5b3b4c33ad22eebe12f3e92f7cf7072e43e78ea Mon Sep 17 00:00:00 2001 From: manfromsiberia Date: Fri, 6 Dec 2019 17:53:06 +0300 Subject: [PATCH 2/2] add correct handling for param fee in prepare_transaction when fee is 0 for other classes --- bit/wallet.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bit/wallet.py b/bit/wallet.py index 301b19b..515aaa1 100644 --- a/bit/wallet.py +++ b/bit/wallet.py @@ -400,10 +400,12 @@ def prepare_transaction(cls, address, outputs, compressed=True, fee=None, :returns: JSON storing data required to create an offline transaction. :rtype: ``str`` """ + if not isinstance(fee, (int, type(None))): + raise TypeError('Invalid fee type.') unspents, outputs = sanitize_tx_data( unspents or NetworkAPI.get_unspent(address), outputs, - fee or get_fee_cached(), + fee if isinstance(fee, int) else get_fee_cached(), leftover or address, combine=combine, message=message, @@ -1120,10 +1122,12 @@ def prepare_transaction(cls, address, outputs, compressed=True, fee=None, :returns: JSON storing data required to create an offline transaction. :rtype: ``str`` """ + if not isinstance(fee, (int, type(None))): + raise TypeError('Invalid fee type.') unspents, outputs = sanitize_tx_data( unspents or NetworkAPI.get_unspent(address), outputs, - fee or get_fee_cached(), + fee if isinstance(fee, int) else get_fee_cached(), leftover or address, combine=combine, message=message, @@ -1423,10 +1427,12 @@ def prepare_transaction(cls, address, outputs, compressed=True, fee=None, :returns: JSON storing data required to create an offline transaction. :rtype: ``str`` """ + if not isinstance(fee, (int, type(None))): + raise TypeError('Invalid fee type.') unspents, outputs = sanitize_tx_data( unspents or NetworkAPI.get_unspent_testnet(address), outputs, - fee or get_fee_cached(), + fee if isinstance(fee, int) else get_fee_cached(), leftover or address, combine=combine, message=message,