Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable importing joinmarket wallet as watch-only to mobile wallets #1267

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jmclient/jmclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
StoragePasswordError, VolatileStorage)
from .cryptoengine import (BTCEngine, BTC_P2PKH, BTC_P2SH_P2WPKH, BTC_P2WPKH, EngineError,
TYPE_P2PKH, TYPE_P2SH_P2WPKH, TYPE_P2WPKH, detect_script_type,
is_extended_public_key)
is_extended_public_key, convert_xpub_if_needed)
from .configure import (load_test_config, process_shutdown,
load_program_config, jm_single, get_network, update_persist_config,
validate_address, is_burn_destination, get_mchannels,
Expand Down
9 changes: 9 additions & 0 deletions jmclient/jmclient/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ def jm_single():
# 2. You cannot change the type of a pre-existing wallet.
native = true

# In joinmarket-qt, display zpub for native segwit wallet, and ypub for
# non-native segwit wallet.
# If set to false, the extended public key will always display in the xpub
# format.
qt_display_ypub_zpub = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure default should be true, but probably. What do others think? @AdamISZ ? @chris-belcher ?


# for dust sweeping, try merge_algorithm = gradual
# for more rapid dust sweeping, try merge_algorithm = greedy
# for most rapid dust sweeping, try merge_algorithm = greediest
Expand Down Expand Up @@ -986,6 +992,9 @@ def is_native_segwit_mode():
return False
return jm_single().config.get('POLICY', 'native') != 'false'

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

def process_shutdown(mode="command-line"):
if mode=="command-line":
from twisted.internet import reactor
Expand Down
18 changes: 17 additions & 1 deletion jmclient/jmclient/cryptoengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import jmbitcoin as btc
from jmbase import bintohex
from .configure import get_network, jm_single
from .configure import get_network, jm_single, qt_display_ypub_zpub


#NOTE: before fidelity bonds and watchonly wallet, each of these types corresponded
Expand All @@ -25,7 +25,9 @@

BIP32_PUB_PREFIX = "xpub"
BIP49_PUB_PREFIX = "ypub"
BIP49_PUB_PREFIX_BYTES = b"\x04\x9d\x7c\xb2"
BIP84_PUB_PREFIX = "zpub"
BIP84_PUB_PREFIX_BYTES = b"\x04\xb2\x47\x46"
TESTNET_PUB_PREFIX = "tpub"

def detect_script_type(script_str):
Expand Down Expand Up @@ -61,6 +63,20 @@ def is_extended_public_key(key_str):
BIP32_PUB_PREFIX, BIP49_PUB_PREFIX, BIP84_PUB_PREFIX, TESTNET_PUB_PREFIX]])


def convert_xpub_if_needed(xpub, current_wallet_type):
if not xpub.startswith(BIP32_PUB_PREFIX) or not qt_display_ypub_zpub():
return xpub

# Convert xpub to ypub or zpub for display
if current_wallet_type in (TYPE_P2WPKH, TYPE_SEGWIT_WALLET_FIDELITY_BONDS):
# BIP84 format
xpub = btc.base58.encode(BIP84_PUB_PREFIX_BYTES + btc.base58.decode(xpub)[4:])
elif current_wallet_type == TYPE_P2SH_P2WPKH:
# BIP49 format
xpub = btc.base58.encode(BIP49_PUB_PREFIX_BYTES + btc.base58.decode(xpub)[4:])
return xpub


class classproperty(object):
"""
from https://stackoverflow.com/a/5192374
Expand Down
7 changes: 4 additions & 3 deletions scripts/joinmarket-qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,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, is_extended_public_key
TYPE_P2WPKH, check_and_start_tor, is_extended_public_key, convert_xpub_if_needed
from jmclient.wallet import BaseWallet

from qtsupport import ScheduleWizard, TumbleRestartWizard, config_tips,\
Expand Down Expand Up @@ -1573,7 +1573,8 @@ def updateWalletInfo(self, walletinfo=None):
continue

if address_type == BaseWallet.ADDRESS_TYPE_EXTERNAL:
heading = "EXTERNAL " + xpubs[mixdepth][address_type]
heading = "EXTERNAL " + convert_xpub_if_needed(xpubs[mixdepth][address_type],
mainWindow.wallet_service.wallet.TYPE)
elif address_type == BaseWallet.ADDRESS_TYPE_INTERNAL:
heading = "INTERNAL"
elif address_type == FidelityBondMixin.BIP32_TIMELOCK_ID:
Expand Down Expand Up @@ -2339,7 +2340,7 @@ def get_wallet_printout(wallet_service):
account_xpub = acct.xpub
if account_xpub.startswith(FBONDS_PUBKEY_PREFIX):
account_xpub = account_xpub[len(FBONDS_PUBKEY_PREFIX):]
xpubs[j].append(account_xpub)
xpubs[j].append(convert_xpub_if_needed(account_xpub, wallet_service.wallet.TYPE))
# 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