Skip to content

Commit

Permalink
Enable importing joinmarket wallet as watch-only
Browse files Browse the repository at this point in the history
  • Loading branch information
Wukong committed May 11, 2022
1 parent 7254149 commit 64eb2a3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion jmclient/jmclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
load_program_config, jm_single, get_network, update_persist_config,
validate_address, is_burn_destination, get_mchannels,
get_blockchain_interface_instance, set_config, is_segwit_mode,
is_native_segwit_mode, JMPluginService, get_interest_rate,
is_native_segwit_mode, display_ypub_zpub, JMPluginService, get_interest_rate,
get_bondless_makers_allowance, check_and_start_tor)
from .blockchaininterface import (BlockchainInterface,
RegtestBitcoinCoreInterface, BitcoinCoreInterface)
Expand Down
3 changes: 3 additions & 0 deletions jmclient/jmclient/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,9 @@ def is_native_segwit_mode():
return False
return jm_single().config.get('POLICY', 'native') != 'false'

def display_ypub_zpub():
return jm_single().config.get('POLICY', 'display_ypub_zpub') != 'false'

def process_shutdown(mode="command-line"):
if mode=="command-line":
from twisted.internet import reactor
Expand Down
2 changes: 1 addition & 1 deletion jmclient/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
packages=['jmclient'],
install_requires=['joinmarketbase==0.9.7dev', 'mnemonic', 'argon2_cffi',
'bencoder.pyx>=2.0.0', 'pyaes', 'klein==20.6.0',
'pyjwt==2.1.0', 'autobahn==20.12.3'],
'pyjwt==2.1.0', 'autobahn==20.12.3', 'base58'],
python_requires='>=3.6',
zip_safe=False)
45 changes: 39 additions & 6 deletions scripts/joinmarket-qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import sys, datetime, os, logging
import platform, json, threading, time
from optparse import OptionParser
import base58

from PySide2 import QtCore

Expand Down Expand Up @@ -73,7 +74,7 @@
parse_payjoin_setup, send_payjoin, JMBIP78ReceiverManager, \
detect_script_type, general_custom_change_warning, \
nonwallet_custom_change_warning, sweep_custom_change_warning, EngineError,\
TYPE_P2WPKH, check_and_start_tor
TYPE_P2WPKH, check_and_start_tor, is_segwit_mode, is_native_segwit_mode, display_ypub_zpub
from jmclient.wallet import BaseWallet

from qtsupport import ScheduleWizard, TumbleRestartWizard, config_tips,\
Expand Down Expand Up @@ -1462,10 +1463,11 @@ def create_menu(self, position):
txt = str(item.text(0))
if validate_address(txt)[0]:
address_valid = True
if "EXTERNAL" in txt:
parsed = txt.split()
if len(parsed) > 1:
xpub = parsed[1]

parsed = txt.split()
if len(parsed) > 1:
if parsed[-1].startswith("xpub") or parsed[-1].startswith("ypub") or parsed[-1].startswith("zpub"):
xpub = parsed[-1]
xpub_exists = True

menu = QMenu()
Expand Down Expand Up @@ -1566,7 +1568,20 @@ def updateWalletInfo(self, walletinfo=None):
continue

if address_type == BaseWallet.ADDRESS_TYPE_EXTERNAL:
heading = "EXTERNAL " + xpubs[mixdepth][address_type]
xpub = xpubs[mixdepth][address_type]
if display_ypub_zpub():
# Convert xpub to ypub or zpub for display
if is_segwit_mode():
if is_native_segwit_mode():
# zpub format
zpub_prefix = b'\x04\xb2\x47\x46'
xpub = base58.b58encode_check(zpub_prefix + base58.b58decode_check(xpub)[4:]).decode('ascii')
else:
# ypub format
ypub_prefix = b'\x04\x9d\x7c\xb2'
xpub = base58.b58encode_check(ypub_prefix + base58.b58decode_check(xpub)[4:]).decode('ascii')

heading = "EXTERNAL " + xpub
elif address_type == BaseWallet.ADDRESS_TYPE_INTERNAL:
heading = "INTERNAL"
elif address_type == FidelityBondMixin.BIP32_TIMELOCK_ID:
Expand Down Expand Up @@ -2327,6 +2342,24 @@ def get_wallet_printout(wallet_service):
entry.serialize_amounts(),
entry.serialize_status(),
entry.serialize_label()])
# Append the account xpub to the end of the list
FBONDS_PUBKEY_PREFIX = "fbonds-mpk-"
account_xpub = acct.xpub
if account_xpub.startswith(FBONDS_PUBKEY_PREFIX):
account_xpub = account_xpub[len(FBONDS_PUBKEY_PREFIX):]
if display_ypub_zpub():
# Convert xpub to ypub or zpub for display
if is_segwit_mode():
if is_native_segwit_mode():
# zpub format
zpub_prefix = b'\x04\xb2\x47\x46'
account_xpub = base58.b58encode_check(zpub_prefix + base58.b58decode_check(account_xpub)[4:]).decode('ascii')
else:
# ypub format
ypub_prefix = b'\x04\x9d\x7c\xb2'
account_xpub = base58.b58encode_check(ypub_prefix + base58.b58decode_check(account_xpub)[4:]).decode('ascii')
xpubs[j].append(account_xpub)

# in case the wallet is not yet synced, don't return an incorrect
# 0 balance, but signal incompleteness:
total_bal = walletview.get_fmt_balance() if wallet_service.synced else None
Expand Down

0 comments on commit 64eb2a3

Please sign in to comment.