Browse Source

Merge JoinMarket-Org/joinmarket-clientserver#1662: Minor quality improvements in wallet code

c4414e8c9c Minor quality improvements in wallet code (Kristaps Kaupe)

Pull request description:

  Was looking at #1278 changes in context of #1588. Couldn't find any errors there, that seems correct and should be working. But in process I corrected wrong comment, changed to use `btc_to_sat()` helper function for unit conversion and added some type hints.

ACKs for top commit:
  AdamISZ:
    utACK c4414e8c9c

Tree-SHA512: df227ca7316ad9cc4b7cb3133df940bd3a3132a521f552756906f090b82b1b08c6e11775c47698685be23017ea8e9893ba5e9467c415158aeec7075839e32ea4
master
Kristaps Kaupe 2 years ago
parent
commit
74a0b10503
No known key found for this signature in database
GPG Key ID: 33E472FE870C7E5D
  1. 6
      src/jmclient/wallet.py
  2. 8
      src/jmclient/wallet_service.py

6
src/jmclient/wallet.py

@ -765,7 +765,8 @@ class BaseWallet(object):
'address': self._ENGINE.script_to_address(spk)} 'address': self._ENGINE.script_to_address(spk)}
return added_utxos return added_utxos
def add_utxo(self, txid, index, script, value, height=None): def add_utxo(self, txid: bytes, index: int, script: bytes, value: int,
height: Optional[int] = None) -> None:
assert isinstance(txid, bytes) assert isinstance(txid, bytes)
assert isinstance(index, Integral) assert isinstance(index, Integral)
assert isinstance(script, bytes) assert isinstance(script, bytes)
@ -2613,7 +2614,8 @@ class FidelityBondMixin(object):
for timenumber in range(self.TIMENUMBER_COUNT): for timenumber in range(self.TIMENUMBER_COUNT):
yield self.get_path(md, address_type, timenumber) yield self.get_path(md, address_type, timenumber)
def add_utxo(self, txid, index, script, value, height=None): def add_utxo(self, txid: bytes, index: int, script: bytes, value: int,
height: Optional[int] = None) -> None:
super().add_utxo(txid, index, script, value, height) super().add_utxo(txid, index, script, value, height)
#dont use coin control freeze if wallet readonly #dont use coin control freeze if wallet readonly
if self._storage.read_only: if self._storage.read_only:

8
src/jmclient/wallet_service.py

@ -867,19 +867,19 @@ class WalletService(Service):
et = time.time() et = time.time()
jlog.debug('bitcoind sync_unspent took ' + str((et - st)) + 'sec') jlog.debug('bitcoind sync_unspent took ' + str((et - st)) + 'sec')
def _add_unspent_txo(self, utxo, height): def _add_unspent_txo(self, utxo: dict, height: Optional[int]) -> None:
""" """
Add a UTXO as returned by rpc's listunspent call to the wallet. Add a UTXO as returned by rpc's listunspent call to the wallet.
Note that these are returned as little endian outpoint txids, so Note that these are returned as little endian outpoint txids, so
are converted. are converted.
params: params:
utxo: single utxo dict as returned by listunspent utxo: single utxo dict as returned by listunspent
current_blockheight: blockheight as integer, used to height: blockheight as integer, used to set the block in which
set the block in which a confirmed utxo is included. a confirmed utxo is included.
""" """
txid = hextobin(utxo['txid']) txid = hextobin(utxo['txid'])
script = hextobin(utxo['scriptPubKey']) script = hextobin(utxo['scriptPubKey'])
value = int(Decimal(str(utxo['amount'])) * Decimal('1e8')) value = btc.btc_to_sat(utxo['amount'])
self.add_utxo(txid, int(utxo['vout']), script, value, height) self.add_utxo(txid, int(utxo['vout']), script, value, height)
# if we start up with unconfirmed outputs, they must be # if we start up with unconfirmed outputs, they must be
# put into the transaction monitor state, so we can recognize # put into the transaction monitor state, so we can recognize

Loading…
Cancel
Save