1
It appears that there are many way to traverse Bitcoin addresses. I am looking best practice, and I am also looking for the documented logic of how common wallets do it so I can replicate their behaviour.
For example, Trezor creates the first address at this location: m/49'/0'/0'/0/0, and then the next address will be m/49'/0'/0'/0/1, and so on. So, it appears that it would be easy to just use an iterator over the last digit.
But, when you spend from m/49'/0'/0'/0/0, it moves the leftover to m/49'/0'/0'/1/0 . So, suddenly, I not only have to iterate over the last digit, I also have to iterate over the penultimate digit. I could have said "second last", but I said penultimate because it sounds more intelligent.
Is there standard practice for traversing addresses? Something like, keep traversing over addresses until you hit an address with no transactions? Or possibly say three addresses in a row with no transactions? Or is this really the wild west and we just do whatever we feel like?
I believe you might be looking for https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#account-discovery, but I'm not sure it fully answers your question
– MeshCollider – 2018-01-08T00:24:07.580I think answers my question as long as there are no gotchas. Are there corner cases that are not covered here? I actually found that Ledger is not 100% with Trezor and Vice Versa - i.e. they don't follow the same algorithm, so one must not be following the spec correctly. – Melbourne Developer – 2018-01-08T00:49:01.057
Would you mind clarifying what the difference between the two is? – MeshCollider – 2018-01-08T00:51:17.250
I don't know. It's just that when I restored my Trezor wallet on to the Ledger, the Ledger was missing some addresses, and therefore the balances didn't add up. – Melbourne Developer – 2018-01-08T02:24:09.253
@MeshCollider, but actually, this document is for BIP0044, and yet Trezor creates addresses at 49 which is different to what BIP0044 recommends. I'm so confused. – Melbourne Developer – 2018-01-08T02:27:45.810
@MeshCollider, BIP0044 matches the Trezor, as long as you apply the BIP0049 amendment. https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki
– Melbourne Developer – 2018-01-08T02:29:40.180@MeshCollider , if you want to write this up in more detail, I will mark your answer as the correct one. – Melbourne Developer – 2018-01-08T02:30:00.977