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

Refactor PSBT module & add new PSBT fields #44

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

SachinMeier
Copy link
Member

@SachinMeier SachinMeier commented Nov 2, 2021

#42

Make PSBT use Derivation Path & Xpub modules

Add Taproot fields & PSBT v2 fields

Refactor some but not all odd logic

TODO:

  • add_<field> funcs
  • Fix some weird parse/serialize logic wrt list reversal
  • add PSBT Role modules/funcs
  • Write our own tests for new Taproot fields & v2 fields

lib/extendedkey.ex Outdated Show resolved Hide resolved
try do
{:ok, %__MODULE__{child_nums: tfrom_string(String.split(pathstr, "/"))}}
{:ok, tto_bin(child_nums, <<>>)}
Copy link
Member

Choose a reason for hiding this comment

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

what's meaning of the prefix t for private function like tfrom_string, tto_bin?

Copy link
Member Author

Choose a reason for hiding this comment

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

I named the recursive helper functions differently, but there's no real reason for that. I'll remove and make them all the same.

Copy link
Contributor

@philipglazman philipglazman left a comment

Choose a reason for hiding this comment

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

Same Q as @bruteforcecat. Otherwise, lgtm

lib/psbt.ex Outdated Show resolved Hide resolved
@SachinMeier SachinMeier requested a review from kafaichoi November 4, 2021 07:58
(used for PSBT encoding)
"""
@spec serialize(t(), atom) :: binary
def serialize(xkey = %__MODULE__{}, :no_checksum) do
Copy link
Member

@kafaichoi kafaichoi Jan 1, 2023

Choose a reason for hiding this comment

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

nit. it will be great to merge &serialize/1 and &serialize/2 into one &serialize/2 with type signature like

@spec serialize(t(), list({:with_checksum?,  boolean}) :: binary
  def serialize(xkey, opts \\ []) do
     with_checksum? =  Keyword.get(opts, :with_checksum?, true)
      extended_key_without_checksum_bin = (xkey.prefix <>
       xkey.depth <> xkey.parent_fingerprint <> xkey.child_num <> xkey.chaincode <> xkey.key)
    case with_checksum? do
       true ->
          Base58.append_checksum(extended_key_without_checksum_bin)
        false ->
           extended_key_without_checksum_bin
    end
  end

I think it's more elixir-idiomatic, better typing for user using dialyzer and less code duplication

Copy link
Member

@kafaichoi kafaichoi left a comment

Choose a reason for hiding this comment

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

tACK. one nit and we need to fix merge conflict

@SachinMeier SachinMeier requested a review from kafaichoi January 27, 2023 06:33
pathstr
|> String.split("/")
|> path_from_string([])
|> Enum.reverse()
Copy link
Member Author

Choose a reason for hiding this comment

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

move split & reverse into path_from_string,

@SachinMeier SachinMeier changed the title Make PSBT use Xpub and DerivationPath Refactor PSBT module & add new PSBT fields Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants