-
Notifications
You must be signed in to change notification settings - Fork 101
backend/btc/address: be explicit about chainIndex/addressIndex #3325
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
base: master
Are you sure you want to change the base?
Conversation
5d93dbb
to
f42c977
Compare
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.
Overall LGTM with one minor comment on docs
@@ -47,22 +47,28 @@ type AccountAddress struct { | |||
} | |||
|
|||
// NewAccountAddress creates a new account address. | |||
// The chainIndex is 0 for receive and 1 for change. |
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.
It's not clear what "chainIndex" is here; it's not one of the argument (though I assume you refer to the one accessed via derivation.SimpleChainIndex()
? ) maybe we can make it clearer
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.
Ah it's a leftover comment from before I introduced the Derivation struct. Removed.
The relative keypath always has two elements, the first element indicating change and the second indicating the address index. A relative keypath of arbitrary length is harder to handle. E.g. it is not compatible with output descriptors with multipath indices (`xpub/<0;1>/*`), where also two elements are required to derive an address (the multipath index selecting between `<X;Y>` and the address index). The unit tests change because the GetAddress test function used an empty relative path instead of a chainIndex and addressIndex, which now was forced to change with the stricter types. I considered keeping `ChainIndex uint32` instead of `Change bool`, because in multipaths, one could have more than two, e.g. `xpub/<X;Y;Z>/*`, but I prefer the stricter type and it's not likely we will ever need more than two (receive & change).
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.
LGTM
The relative keypath always has two elements, the first element indicating change and the second indicating the address index.
A relative keypath of arbitrary length is harder to handle. E.g. it is not compatible with output descriptors with multipath indices (
xpub/<0;1>/*
), where also two elements are required to derive an address (the multipath index selecting between<X;Y>
and the address index).The unit tests change because the GetAddress test function used an empty relative path instead of a chainIndex and addressIndex, which now was forced to change with the stricter types.
I considered keeping
ChainIndex uint32
instead ofChange bool
,because in multipaths, one could have more than two,
e.g.
xpub/<X;Y;Z>/*
, but I prefer the stricter type and it's notlikely we will ever need more than two (receive & change).