From f6aa72b9ef43b6e9feccd24751219012c8f05e11 Mon Sep 17 00:00:00 2001 From: zebra-lucky Date: Fri, 1 Nov 2024 18:00:12 +0200 Subject: [PATCH] add JMBaseCodeMixin.get_wif_path --- electrum/plugins/joinmarket/jm_base_code.py | 10 +++++++++- electrum/plugins/joinmarket/jmclient/wallet_utils.py | 5 ++--- electrum/plugins/joinmarket/notes.txt | 1 - electrum/plugins/joinmarket/tests/test_jm_base_code.py | 7 +++++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/electrum/plugins/joinmarket/jm_base_code.py b/electrum/plugins/joinmarket/jm_base_code.py index 115e63d8a..c2c0912d6 100644 --- a/electrum/plugins/joinmarket/jm_base_code.py +++ b/electrum/plugins/joinmarket/jm_base_code.py @@ -12,7 +12,7 @@ import electrum_ecc as ecc from electrum.bip32 import convert_bip32_intpath_to_strpath from electrum.bitcoin import (script_to_scripthash, address_to_script, - construct_script, opcodes) + construct_script, opcodes, serialize_privkey) from electrum.crypto import sha256 from electrum.descriptor import get_singlesig_descriptor_from_legacy_leaf from electrum.transaction import (get_address_from_output_script, @@ -345,6 +345,14 @@ class JMBaseCodeMixin: privk, _ = w.keystore.get_private_key(path, None) return privk + # jmclient/wallet.py BaseWallet.get_wif_path + def get_wif_path(self, path, password): + w = self.wallet + addr = self.get_address_from_path(path) + privk, compressed = w.keystore.get_private_key(path, password) + txin_type = w.get_txin_type(addr) + return serialize_privkey(privk, compressed, txin_type) + # jmclient/wallet.py BaseWallet/BIP32Wallet get_script_from_path def get_script_from_path(self, path) -> bytes: addr = self.get_address_from_path(path) diff --git a/electrum/plugins/joinmarket/jmclient/wallet_utils.py b/electrum/plugins/joinmarket/jmclient/wallet_utils.py index bd7fb7d51..12c9cc993 100644 --- a/electrum/plugins/joinmarket/jmclient/wallet_utils.py +++ b/electrum/plugins/joinmarket/jmclient/wallet_utils.py @@ -351,7 +351,7 @@ def get_utxo_status_string(utxos, utxos_enabled, path): def wallet_display(jmman, showprivkey, displayall=False, serialized=True, summarized=False, mixdepth=None, - jsonified=False): + jsonified=False, password=None): """build the walletview object, then return its serialization directly if serialized, else return the WalletView object. @@ -415,8 +415,7 @@ def wallet_display(jmman, showprivkey, displayall=False, balance, status = get_addr_status( path, utxos[m], utxos_enabled[m], is_new, address_type) if showprivkey: - # privkey = jmman.get_wif_path(path) FIXME no get_wif_path - privkey = '' # FIXME + privkey = jmman.jmw.get_wif_path(path, password) else: privkey = '' if (displayall or balance > 0 or diff --git a/electrum/plugins/joinmarket/notes.txt b/electrum/plugins/joinmarket/notes.txt index aabe4e9c0..c57e2a714 100644 --- a/electrum/plugins/joinmarket/notes.txt +++ b/electrum/plugins/joinmarket/notes.txt @@ -1,7 +1,6 @@ ------------------------------------------------------------------------------- plugin: - покращення покриття тестами - - jm_base_code.py: add get_wif_path (need password if wallet/ks encrypted) - потрібно якось документувати - qml gui - jm_qt_obwatch: advanced sorting by columns, filter by text diff --git a/electrum/plugins/joinmarket/tests/test_jm_base_code.py b/electrum/plugins/joinmarket/tests/test_jm_base_code.py index 0b5e54e09..b540f6b6e 100644 --- a/electrum/plugins/joinmarket/tests/test_jm_base_code.py +++ b/electrum/plugins/joinmarket/tests/test_jm_base_code.py @@ -245,6 +245,13 @@ class JMBaseCodeMixinTestCase(JMTestCase): assert await jmw.make_keypairs_cache(None, None) assert jmw.get_key_from_addr(addr) == keypair[1] + async def test_get_wif_path(self): + jmw = self.jmw + w = jmw.wallet + idx = w.get_address_index('tb1qpjkqrhz3kxsg93c5cw2axhdy39wqy36u9ygzdk') + wif = 'p2wpkh:cUFGYhBPap7YEr4yq1BX1iVGHqmYK9udFnXmQz2LxRKBv11PXyf3' + assert jmw.get_wif_path(idx, None) == wif + async def test_get_script_from_path(self): jmw = self.jmw w = jmw.wallet