-
Notifications
You must be signed in to change notification settings - Fork 18
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
base: master
Are you sure you want to change the base?
Conversation
lib/extendedkey.ex
Outdated
try do | ||
{:ok, %__MODULE__{child_nums: tfrom_string(String.split(pathstr, "/"))}} | ||
{:ok, tto_bin(child_nums, <<>>)} |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this 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/extendedkey.ex
Outdated
(used for PSBT encoding) | ||
""" | ||
@spec serialize(t(), atom) :: binary | ||
def serialize(xkey = %__MODULE__{}, :no_checksum) do |
There was a problem hiding this comment.
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
There was a problem hiding this 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
pathstr | ||
|> String.split("/") | ||
|> path_from_string([]) | ||
|> Enum.reverse() |
There was a problem hiding this comment.
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,
#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