Conversation
|
Would prefer to have simply sending-to (maybe validating/analyzing too?) as a separate PR, before wallet upgrades. I'm not sure when it would make sense to convert between P2SH and BIP173... |
|
@luke-jr I agree, but I consider
I think you're right. I'll remove that. |
|
addwitnessaddress is very much not actual support, it's a test shim. |
|
But it modifies the wallet, no? Seems useful to review independently from the rest. Especially since it has the additional considerations of what happens if you try to use it and then downgrade to an older version... |
|
@luke-jr Consider that we've since 0.13.1 had support for receiving and spending native witness outputs in the wallet (without that, testing the consensus logic for it would have been much harder), just no way to encode such outputs as strings. So I think the encoding is somewhat orthogonal. It does modify the wallet, but I'm not sure it's worth trying to separate the logic. We only have one data type ( Wallet backward compatibility is only affected when you use an import or |
|
Added support in Python framework, and some integrated some functional tests into the |
src/bech32.cpp
Outdated
There was a problem hiding this comment.
IMO bool Decode(const std::string& str, const std::string& hrp, data& d) feels better, and this way below it can early return.
There was a problem hiding this comment.
It's not often used in the Bitcoin Core codebase, but using pairs for multiple returned values is very typical in C++ (see the return type of std::map::insert for example). In C++03 it was a bit verbose to use, but with C++11's auto types and std::tie for assigning to multiple variables, it's pretty convenient. I'd rather stick with the current approach.
src/base58.cpp
Outdated
src/base58.cpp
Outdated
src/bech32.h
Outdated
src/base58.cpp
Outdated
There was a problem hiding this comment.
Must come first? If not which is the cheapest?
There was a problem hiding this comment.
bech32 is far cheaper (no basis conversion, no SHA256).
src/base58.cpp
Outdated
There was a problem hiding this comment.
Must come first? If not which is the cheapest?
There was a problem hiding this comment.
I haven't benchmarked, but Bech32 should be far cheaper (no SHA256, no basis conversion). There should never be overlap between the addresses, so the order shouldn't matter.
There was a problem hiding this comment.
Right, in terms of functionality the order doesn't matter. But at the moment most addresses (don't know numbers) are base58 so for now move bech32::Decode() after DecodeBase58Check()?
It would be cool to move this out of base58.cpp, follow up maybe?
There was a problem hiding this comment.
Right, in terms of functionality the order doesn't matter. But at the moment most addresses (don't know numbers) are base58 so for now move bech32::Decode() after DecodeBase58Check()?
I was using a fail-fast approach, making the thing that most quickly fails first. You're right that as long as there are hardly any bech32 addresses, putting Base58 would be overall faster. But none of this is performance critical anyway...
src/chainparams.cpp
Outdated
There was a problem hiding this comment.
I arbitrarily chose a bech32 prefix for regtest. Feel free to bikeshed (it doesn't even need to be just 2 characters).
src/bech32.cpp
Outdated
src/bech32.cpp
Outdated
src/bech32.cpp
Outdated
src/bech32.h
Outdated
There was a problem hiding this comment.
Could you leave a comment referring the reader to more complete documentation on bech32 (either the BIP or reference repo)? Also would be nice to document somewhere in the codebase what hrp stands for.
I'm thinking something as simple as: "Bech32 is a data encoding used for some newer address formats. Output consists of a human-readable part (HRP) followed by a separator, then the data itself with a checksum. For more details, see documentation of BIP 173."
There was a problem hiding this comment.
Done again - I somehow lost this change.
There was a problem hiding this comment.
I don't see the comment... I think you lost it again.
There was a problem hiding this comment.
It's there, just a bit higher up in the file.
src/test/base58_tests.cpp
Outdated
There was a problem hiding this comment.
nit: Maybe use toupper here to be more descriptive and succinct.
There was a problem hiding this comment.
Unfortunately, toupper is locale-dependent, so it can't be used for consistent behaviour.
There was a problem hiding this comment.
std::toupper(c, std::locale::classic())?
d7dd8a5 to
f77636b
Compare
|
Include a test with v1+ address? |
92f1f8b Split off key_io_tests from base58_tests (Pieter Wuille) 119b0f8 Split key_io (address/key encodings) off from base58 (Pieter Wuille) ebfe217 Stop using CBase58Data for ext keys (Pieter Wuille) 32e69fa Replace CBitcoinSecret with {Encode,Decode}Secret (Pieter Wuille) Pull request description: This PR contains some of the changes left as TODO in #11167 (and built on top of that PR). They are not intended for backporting. This removes the `CBase58`, `CBitcoinSecret`, `CBitcoinExtKey`, and `CBitcoinExtPubKey` classes, in favor of simple `Encode`/`Decode` functions. Furthermore, all Bitcoin-specific logic (addresses, WIF, BIP32) is moved to `key_io.{h,cpp}`, leaving `base58.{h,cpp}` as a pure utility that implements the base58 encoding/decoding logic. Tree-SHA512: a5962c0ed27ad53cbe00f22af432cf11aa530e3efc9798e25c004bc9ed1b5673db5df3956e398ee2c085e3a136ac8da69fe7a7d97a05fb2eb3be0b60d0479655
Bech32 encoding support and t-addr encoding refactor Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#7922 - bitcoin/bitcoin#7825 - bitcoin/bitcoin#8317 - bitcoin/bitcoin#9804 - Only the commit that changed `base58.cpp` - bitcoin/bitcoin#11117 - bitcoin/bitcoin#11259 - bitcoin/bitcoin#11167 - Only the first three commits (the fourth commit depends on #2390, later ones are SegWit-specific). Part of #3058.
Refactor t-address encoding Includes code cherry-picked from the following upstream PRs: - bitcoin/bitcoin#11117 - bitcoin/bitcoin#11259 - Only the second commit (first is for QT code) - bitcoin/bitcoin#11167 - Only the first commit (the rest are not part of the t-address encoding refactor). Part of #3058. Precursor to #3202.
Bech32 encoding support Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#8578 - bitcoin/bitcoin#11167 - Only the second and third commits (first is in #3228, fourth depends on #2390, later ones are SegWit-specific). - bitcoin/bitcoin#12757 - Only the change to `src/bech32.h` Part of #3058.
Bech32 encoding support Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#8578 - bitcoin/bitcoin#11167 - Only the second and third commits (first is in #3228, fourth depends on #2390, later ones are SegWit-specific). - bitcoin/bitcoin#12757 - Only the change to `src/bech32.h` Part of #3058.
Function extracted from upstream: PR bitcoin/bitcoin#11167 Commit c091b99
Sapling address encodings This PR enables Sapling keys and addresses to be passed in anywhere Sprout keys and addresses are used. Doing so will cause crashes until those places are updated with Sapling support. Includes code cherry-picked from the following upstream PRs: - bitcoin/bitcoin#11167 - bitcoin/bitcoin#11630 Closes #3058.
Sapling address encodings This PR enables Sapling keys and addresses to be passed in anywhere Sprout keys and addresses are used. Doing so will cause crashes until those places are updated with Sapling support. Includes code cherry-picked from the following upstream PRs: - bitcoin/bitcoin#11167 - Only the `ConvertBits()` function. - bitcoin/bitcoin#11630 Closes #3058.
Builds on top of #11117.
This adds support for:
addwitnessaddress, though by default it still produces P2SH versions)validateaddress)It includes a reformatted version of the C++ Bech32 reference code and an independent implementation of the address encoding/decoding logic (integrated with CTxDestination). All BIP173 test vectors are included.
Not included (and intended for other PRs):