Author

Topic: Looking for useful wallet address documentation (Read 207 times)

legendary
Activity: 4592
Merit: 1851
Linux since 1997 RedHat 4
Thanks for the details - much appreciated!

Maybe raise a git issue to add your replies to the main documentation? Smiley
staff
Activity: 3458
Merit: 6793
Just writing some code
One reason for this is someone wanting to supply a 'bc' address and I was curious about under what conditions it is possible to determine an equivalent '3' address.
But of course in general the requirements of the 'addresses' to be able to convert any to another.
In general, you shouldn't be doing address conversions like this. A person gives you an address that they know their wallet is tracking and so they can easily spend the UTXOs associated with that address. By converting the address to a different type, you may make it much more difficult for the person to spend those Bitcoin and they may consider you to have not paid them because the transaction does not appear in their wallet. Not all wallets track all address types that they are able to spend.

You can always convert a bech32 address  (begins with 'bc') to the corresponding P2SH wrapped segwit address (begins with a '3'). A bech32 address maps to a specific scriptPubKey, just treat that scriptPubKey as a redeemScript and get the resulting P2SH address for that redeemScript (i.e. hash it with hash160 and base58 check encode that hash).

Any legacy address (begins with a '1') can be converted to bech32 (and thus p2sh-segwit). Legacy addresses encode the hash160 of the public key which is exactly the same thing that bech32 addresses encode. Just decode the address, extract the hash160, and re-encode that as bech32 with witness version 0. From there you can also go to p2sh-segwit as described above. You can do the same thing in reverse to go from bech32 to legacy.

P2sh-segwit however cannot be converted to any other address type unless you know the redeemScript. If you know the redeemScript, then you can get the bech32 address from the redeemScript and from there convert to a legacy address.
legendary
Activity: 4592
Merit: 1851
Linux since 1997 RedHat 4
Well I guess that answers most of the questions Smiley

Do you happen to know of the rules by which you can convert 'address' types.

I'm not looking for how, more just the requirements that allow them to be converted.

One reason for this is someone wanting to supply a 'bc' address and I was curious about under what conditions it is possible to determine an equivalent '3' address.
But of course in general the requirements of the 'addresses' to be able to convert any to another.
staff
Activity: 3458
Merit: 6793
Just writing some code
None of this information is really documented anywhere... They're primarily in some version's release notes. The information that you are looking for can probably be found in the 0.16.0 Release Notes

1) Which wallet versions are required before core will generate each type of address
Being able to choose address types was introduced in Bitcoin Core 0.16.0, all current address types (legacy, p2sh-segwit, and bech32) were introduced in this version.

1a) or under what circumstances (e.g. with a unfinished keypool) it will not generate certain types
If the wallet still contains uncompressed public keys in the keypool, only legacy type addresses will be generated for those keys. Otherwise all address types can be generated if there are any keys in the keypool.

2) Which addresses can be converted to other types (within what restrictions) and how to do that
Bitcoin Core does not allow you to convert addresses to other types. You cannot do this in Bitcoin Core.

3) Which versions of core support which addresses and which wallets
All addresses are supported for all wallet types (HD and non-HD) so long as the individual keys are compressed. If a key is uncompressed, only a legacy type address will be returned.

This information SHOULD be somewhere in the core version but alas I've been unable to find it (with google help either)
Unfortunately it isn't. Like a lot of things in Bitcoin Core, it isn't really documented.
legendary
Activity: 4592
Merit: 1851
Linux since 1997 RedHat 4
The getnewaddress command of course returns 'new' addresses.
However I can't seem to find some place where core has actually documented it properly.

There are 3 types of 'addresses'
There are multiple types of wallets
There are (of course) multiple versions of bitcoin core

Can someone point me to the core written documentation that clearly explains them - which must include:

1) Which wallet versions are required before core will generate each type of address
1a) or under what circumstances (e.g. with a unfinished keypool) it will not generate certain types

2) Which addresses can be converted to other types (within what restrictions) and how to do that

3) Which versions of core support which addresses and which wallets

Of course there's a large matrix of multiple versions, but clearly anyone who knows what core is doing will know the change over versions related to this
Obviously it doesn't need to list every version, just that it's supported since version X ... (or ... god forbid ... we dropped support at version Y)

This information SHOULD be somewhere in the core version but alas I've been unable to find it (with google help either)
Jump to: