Browse Source

Minor quality improvements in wallet code

master
Kristaps Kaupe 2 years ago
parent
commit
c4414e8c9c
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