Skip to content

Commit

Permalink
Merge #1662: Minor quality improvements in wallet code
Browse files Browse the repository at this point in the history
c4414e8 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 c4414e8

Tree-SHA512: df227ca7316ad9cc4b7cb3133df940bd3a3132a521f552756906f090b82b1b08c6e11775c47698685be23017ea8e9893ba5e9467c415158aeec7075839e32ea4
  • Loading branch information
kristapsk committed Feb 11, 2024
2 parents e04fe68 + c4414e8 commit 74a0b10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/jmclient/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,8 @@ def add_new_utxos(self, tx, height=None):
'address': self._ENGINE.script_to_address(spk)}
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(index, Integral)
assert isinstance(script, bytes)
Expand Down Expand Up @@ -2613,7 +2614,8 @@ def yield_fidelity_bond_paths(self):
for timenumber in range(self.TIMENUMBER_COUNT):
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)
#dont use coin control freeze if wallet readonly
if self._storage.read_only:
Expand Down
8 changes: 4 additions & 4 deletions src/jmclient/wallet_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,19 +867,19 @@ def sync_unspent(self):
et = time.time()
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.
Note that these are returned as little endian outpoint txids, so
are converted.
params:
utxo: single utxo dict as returned by listunspent
current_blockheight: blockheight as integer, used to
set the block in which a confirmed utxo is included.
height: blockheight as integer, used to set the block in which
a confirmed utxo is included.
"""
txid = hextobin(utxo['txid'])
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)
# if we start up with unconfirmed outputs, they must be
# put into the transaction monitor state, so we can recognize
Expand Down

0 comments on commit 74a0b10

Please sign in to comment.