Skip to content

Commit

Permalink
transaction: put full derivation paths into PSBT by default
Browse files Browse the repository at this point in the history
There are three export options for exporting a PSBT.
The default option previously only put derivation path suffixes for pubkeys
(paths relative to the intermediate xpub), now it puts the full path
(if is known by the keystore).

The "export for hardware device; include xpubs" option works same as before:
it puts both full paths and also global xpubs into the PSBT.
Hence the difference between the default option and the "include xpubs" option
is now only that the latter puts global xpubs into the PSBT.

This change is largely made for user-convenient in mind.
Now exporting a PSBT should be less error-prone: particularly for the
single-signer coldcard with sdcard usage, the default option will now work.

closes #5969
related #5955
  • Loading branch information
SomberNight committed Dec 10, 2020
1 parent c3c64a3 commit c815512
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 46 deletions.
2 changes: 1 addition & 1 deletion electrum/gui/qt/transaction_dialog.py
Expand Up @@ -270,7 +270,7 @@ def _gettx_for_hardware_device(self) -> PartialTransaction:
if not isinstance(self.tx, PartialTransaction):
raise Exception("Can only export partial transactions for hardware device.")
tx = copy.deepcopy(self.tx)
tx.add_info_from_wallet(self.wallet, include_xpubs_and_full_paths=True)
tx.add_info_from_wallet(self.wallet, include_xpubs=True)
# log warning if PSBT_*_BIP32_DERIVATION fields cannot be filled with full path due to missing info
from electrum.keystore import Xpub
def is_ks_missing_info(ks):
Expand Down
24 changes: 18 additions & 6 deletions electrum/keystore.py
Expand Up @@ -349,8 +349,12 @@ def get_root_fingerprint(self) -> Optional[str]:
pass

@abstractmethod
def get_fp_and_derivation_to_be_used_in_partial_tx(self, der_suffix: Sequence[int], *,
only_der_suffix: bool = True) -> Tuple[bytes, Sequence[int]]:
def get_fp_and_derivation_to_be_used_in_partial_tx(
self,
der_suffix: Sequence[int],
*,
only_der_suffix: bool,
) -> Tuple[bytes, Sequence[int]]:
"""Returns fingerprint and derivation path corresponding to a derivation suffix.
The fingerprint is either the root fp or the intermediate fp, depending on what is available
and 'only_der_suffix', and the derivation path is adjusted accordingly.
Expand Down Expand Up @@ -449,8 +453,12 @@ def get_derivation_prefix(self) -> Optional[str]:
def get_root_fingerprint(self) -> Optional[str]:
return self._root_fingerprint

def get_fp_and_derivation_to_be_used_in_partial_tx(self, der_suffix: Sequence[int], *,
only_der_suffix: bool = True) -> Tuple[bytes, Sequence[int]]:
def get_fp_and_derivation_to_be_used_in_partial_tx(
self,
der_suffix: Sequence[int],
*,
only_der_suffix: bool,
) -> Tuple[bytes, Sequence[int]]:
fingerprint_hex = self.get_root_fingerprint()
der_prefix_str = self.get_derivation_prefix()
if not only_der_suffix and fingerprint_hex is not None and der_prefix_str is not None:
Expand Down Expand Up @@ -721,8 +729,12 @@ def get_root_fingerprint(self) -> str:
self._root_fingerprint = xfp.hex().lower()
return self._root_fingerprint

def get_fp_and_derivation_to_be_used_in_partial_tx(self, der_suffix: Sequence[int], *,
only_der_suffix: bool = True) -> Tuple[bytes, Sequence[int]]:
def get_fp_and_derivation_to_be_used_in_partial_tx(
self,
der_suffix: Sequence[int],
*,
only_der_suffix: bool,
) -> Tuple[bytes, Sequence[int]]:
fingerprint_hex = self.get_root_fingerprint()
der_prefix_str = self.get_derivation_prefix()
fingerprint_bytes = bfh(fingerprint_hex)
Expand Down

0 comments on commit c815512

Please sign in to comment.