Skip to content

Conversation

@SachinMeier
Copy link
Contributor

@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

def to_bin(%__MODULE__{child_nums: child_nums}) do
try do
{:ok, %__MODULE__{child_nums: tfrom_string(String.split(pathstr, "/"))}}
{:ok, tto_bin(child_nums, <<>>)}
Copy link
Contributor

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
Contributor 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

@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
Contributor

@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
Contributor

@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
Contributor 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.

4 participants