Skip to content

Conversation

sipa
Copy link
Member

@sipa sipa commented Aug 23, 2017

This patch removes the need for the intermediary Base58 type CBitcoinAddress, by providing {Encode,Decode,IsValid}Destination functions that directly operate on the conversion between std::strings and CTxDestination.

As a side, it also fixes a number of indentation issues, and removes probably several unnecessary implicit CTxDestination<->CBitcoinAddress conversions.

This change is far from complete. In follow-ups I'd like to:

  • Split off the specific address and key encoding logic from base58.h, and move it to a address.h or so.
  • Replace CTxDestination with a non-boost::variant version (which can be more efficient as boost::variant allocates everything on the heap, and remove the need for boost::get<...> and IsValidDestination calls everywhere).
  • Do the same for CBitcoinSecret, CBitcoinExtKey, and CBitcoinExtPubKey.

However, I've tried to keep this patch to be minimally invasive, but still enough to support non-Base58 addresses. Perhaps a smaller patch is possible to hack Bech32 support into CBitcoinAddress, but I would consider that a move in the wrong direction.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is this pattern

DecodeDestination();
if (!IsValidDestination()) {

What about:

CTxDestination dest;
if (!DecodeDestination(str, dest)) {

Also, to avoid more usages of CBitcoinAddress, add commit to move it to base58.cpp?

// build standard output script via GetScriptForDestination()
CScript scriptPubKey = GetScriptForDestination(addr.Get());
CTxDestination destination = DecodeDestination(strAddr);
if (!IsValidDestination(destination)) throw std::runtime_error("invalid TX output address");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block instead?

if (...) {
  throw ...;
}

if (setAddress.count(address))
throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ")+name_);
setAddress.insert(address);
if (destinations.count(destination)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to

if (!destinations.insert(destination).second) {

if (pwallet->mapAddressBook.count(address.Get())) {
std::string strOldAccount = pwallet->mapAddressBook[address.Get()].name;
if (address == GetAccountAddress(pwallet, strOldAccount)) {
if (pwallet->mapAddressBook.count(dest)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, kind of unrelated, use .find() to avoid 2nd lookup below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to keep this as much of a straightforward change as possible, as it may need backporting.

CBitcoinAddress address(request.params[0].get_str());
if (!address.IsValid())
CTxDestination dest = DecodeDestination(request.params[0].get_str());
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up, should the error message be Invalid destination address?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An address is just the string-encoded form of a CTxDestination, so no. I think the "destination" name should be internal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off topic, just Invalid address as it seems irrelevant to have Bitcoin in the error message?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sure!

if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Bitcoin address: ") + input.get_str());
}
if (destinations.count(dest)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with .insert().second like above.

@sipa
Copy link
Member Author

sipa commented Aug 23, 2017

What about:

CTxDestination dest;
if (!DecodeDestination(str, dest)) {

There are plenty of cases where the result of decoding can just be passed to something else, and Function(DecodeDestination(addr)) is far cleaner than CTxDestination dest; DecodeDestination(addr, dest); Function(dest);, so I prefer to keep that possible.

The current pattern is indeed a bit verbose, but once we rewrite CTxDestination to be a native type (rather than a boost::variant; see follow-up plans in the PR description), it could at least simplify to dest.IsValid() or so.

@sipa sipa force-pushed the 201708_nocbitcoinaddress branch from 36eb9f2 to 8363a2c Compare August 23, 2017 06:47
@promag
Copy link
Contributor

promag commented Aug 23, 2017

@sipa sure, I just wanted to question that "style" because it's used elsewhere.

ACK 8363a2c.

@laanwj laanwj added the Wallet label Aug 23, 2017
@jonasschnelli
Copy link
Contributor

utACK 8363a2ccaffba793068db4f97184121730707104

@laanwj laanwj added this to the 0.15.1 milestone Aug 23, 2017
@laanwj
Copy link
Member

laanwj commented Aug 23, 2017

Added 0.15.1 milestone

Copy link
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 8363a2ccaffba793068db4f97184121730707104
LGTM. I skipped over QT stuff as I don't know it very well.

Copy link
Member

@theuni theuni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK other than the keyID issue.

@@ -82,14 +82,14 @@ class AddressTablePriv
LOCK(wallet->cs_wallet);
for (const std::pair<CTxDestination, CAddressBookData>& item : wallet->mapAddressBook)
{
const CBitcoinAddress& address = item.first;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've stared at this for 5 min now. What trickery made this work before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was creating a temporary of type CBitcoinAddress by converting the CTxDestination initializer, using the implicit CBitcoinAddress(const CTxDestination &dest) constructor. That temporary's lifetime was then extended by taking a reference to it, named address.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I didn't know an implicit conversion could be done when extending the lifetime of a const ref. Scary!

if (!addr.GetKeyID(keyID))
{
const CKeyID* keyID = boost::get<CKeyID>(&destination);
if (keyID) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!keyID

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, thanks :S

@@ -317,3 +317,7 @@ CScript GetScriptForWitness(const CScript& redeemscript)
ret << OP_0 << ToByteVector(hash);
return ret;
}

bool IsValidDestination(const CTxDestination& dest) {
return dest.which() != 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a quick comment that this is CNoDestination so it comes up when grepping for future changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use !(operator==) instead?

*/
typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;

/** Check whether a CTxDestination is a CNoDestination. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. ignore last nit.

addressInfo.push_back(ValueFromAmount(balances[address]));
{
if (pwallet->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwallet->mapAddressBook.end()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to figure out what this CBitcoinAddress was doing. Answer: nothing at all.

@sipa sipa force-pushed the 201708_nocbitcoinaddress branch from 8363a2c to 7e7a025 Compare August 24, 2017 18:12
@sipa sipa force-pushed the 201708_nocbitcoinaddress branch from 7e7a025 to 4bc71a6 Compare August 27, 2017 17:23
@sipa
Copy link
Member Author

sipa commented Aug 27, 2017

Removed CBitcoinAddress entirely, using a commit from #11167.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is the base for Bech32, maybe move everything related to CTxDestination out of base58, including tests, to a new place. Also move CTxDestination definition and related functions from src/script/standard.h?

At least should be done in a follow up?

src/base58.cpp Outdated
@@ -12,6 +12,7 @@
#include <string.h>
#include <vector>
#include <string>
#include <algorithm>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, sort.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


if (text.isEmpty()) // Nothing entered
{
ui->labelCoinControlChangeLabel->setText("");
}
else if (!addr.IsValid()) // Invalid address
else if (!IsValidDestination(destination)) // Invalid address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, fix braces.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not going to reflow this entire function in a PR intended for backporting.


UniValue ret(UniValue::VOBJ);
ret.push_back(Pair("isvalid", isValid));
if (isValid)
{
CTxDestination dest = address.Get();
std::string currentAddress = address.ToString();
std::string currentAddress = EncodeDestination(dest);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use currentAddress = request.params[0].get_str();?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be reasons not to do that. Bech32 addresses (added in a later PR) can be uppercase or lowercase, but we always want to store and look up in lowercase form. This is an easy way of doing that, and we should probably check that it's done consistently elsewhere too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I'm +1 for clear data validation and/or sanitization. Although encode(decode(data)) is a obscure way of doing it, not to mention encode(decode(data)) should equal data?

@sipa sipa force-pushed the 201708_nocbitcoinaddress branch 3 times, most recently from f77636b to 3144af1 Compare September 3, 2017 20:14
@sipa
Copy link
Member Author

sipa commented Sep 3, 2017

Since this is the base for Bech32, maybe move everything related to CTxDestination out of base58, including tests, to a new place.

Yes, read the PR description. I plan to do this, but not in a patch that's intended for backporting.

Also move CTxDestination definition and related functions from src/script/standard.h?

Why? To where?

@sipa sipa force-pushed the 201708_nocbitcoinaddress branch from 3144af1 to 87d5c28 Compare September 5, 2017 18:53
@instagibbs
Copy link
Member

utACK 87d5c28

though I do not know the QT stuff well.

@promag
Copy link
Contributor

promag commented Sep 5, 2017

Removed CBitcoinAddress entirely, using a commit from #11167.

@sipa missing this commit as CBitcoinAddress is still around.

@sipa
Copy link
Member Author

sipa commented Sep 5, 2017

@promag Yes, I removed it again.

This PR is just the part that is likely to break easily and need non-trivial rebasing.

{
CTxDestination address = CBitcoinAddress(rec->address).Get();
if (IsValidDestination(rec->address)) {
CTxDestination address = DecodeDestination(rec->address);
Copy link
Contributor

@promag promag Sep 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This incur in a double decoding since above IsValidDestination also decodes. Maybe swap:

CTxDestination address = DecodeDestination(rec->address);
if (IsValidDestination(address)) {

This is how it's done multiples times in this PR.

@laanwj
Copy link
Member

laanwj commented Sep 6, 2017

Not sure if we support this version, but I get the following compile error with clang 3.5.0:

/home/user/src/bitcoin/src/qt/signverifymessagedialog.cpp:235:40: error: invalid operands to binary expression ('CTxDestination' (aka 'variant<CNoDestination, CKeyID, CScriptID>') and 'CTxDestination')
    if (CTxDestination(pubkey.GetID()) != destination) {

Then a lot of note: candidate function not viable like:

/usr/include/x86_64-linux-gnu/qt5/QtCore/qchar.h:544:13: note: candidate function not viable: no known conversion from 'CTxDestination' (aka 'variant<CNoDestination, CKeyID, CScriptID>') to 'QChar' for 1st argument
inline bool operator!=(QChar c1, QChar c2) { return c1.unicode() != c2.unicode(); }

Edit: Ok, to answer my own question @morcos, the 0.13.0 release notes mention:

Effectively this means GCC 4.7 or higher, or Clang 3.3 or higher.

So yes we should try to support 3.5.

@JeremyRubin
Copy link
Contributor

@laanwj

changing it to

if (!(CTxDestination(pubkey.GetID()) == destination)) {

probably fixes it. Ran into this while writing #9991

@laanwj
Copy link
Member

laanwj commented Sep 6, 2017

I confirm that @JeremyRubin's workaround makes it compile.

Edit: after discussion it seems likely that this is due to a boost version difference, not a compiler difference.

@sipa sipa force-pushed the 201708_nocbitcoinaddress branch from 87d5c28 to 8dc36db Compare September 6, 2017 00:40
niahmiah pushed a commit to owstack/bitcoin-abc that referenced this pull request May 14, 2018
niahmiah pushed a commit to owstack/bitcoin-abc that referenced this pull request May 14, 2018
niahmiah pushed a commit to owstack/bitcoin-abc that referenced this pull request May 14, 2018
mkjekk pushed a commit to mkjekk/zcash that referenced this pull request Aug 12, 2018
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 zcash#3058. Precursor to zcash#3202.
mkjekk added a commit to mkjekk/zcash that referenced this pull request Aug 12, 2018
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 zcash#3058. Precursor to zcash#3202.
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 24, 2019
864cd27 Move CBitcoinAddress to base58.cpp (Pieter Wuille)
5c8ff0d Introduce wrappers around CBitcoinAddress (Pieter Wuille)

Pull request description:

  This patch removes the need for the intermediary Base58 type `CBitcoinAddress`, by providing {`Encode`,`Decode`,`IsValid`}`Destination` functions that directly operate on the conversion between `std::string`s and `CTxDestination`.

  As a side, it also fixes a number of indentation issues, and removes probably several unnecessary implicit `CTxDestination`<->`CBitcoinAddress` conversions.

  This change is far from complete. In follow-ups I'd like to:
  * Split off the specific address and key encoding logic from base58.h, and move it to a address.h or so.
  * Replace `CTxDestination` with a non-`boost::variant` version (which can be more efficient as `boost::variant` allocates everything on the heap, and remove the need for `boost::get<...>` and `IsValidDestination` calls everywhere).
  * Do the same for `CBitcoinSecret`, `CBitcoinExtKey`, and `CBitcoinExtPubKey`.

  However, I've tried to keep this patch to be minimally invasive, but still enough to support non-Base58 addresses. Perhaps a smaller patch is possible to hack Bech32 support into `CBitcoinAddress`, but I would consider that a move in the wrong direction.

Tree-SHA512: c2c77ffb57caeadf2429b1c2562ce60e8c7be8aa9f8e51b591f354b6b441162625b2efe14c023a1ae485cf2ed417263afa35c892891dfaa7844e7fbabccab85e
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 24, 2019
864cd27 Move CBitcoinAddress to base58.cpp (Pieter Wuille)
5c8ff0d Introduce wrappers around CBitcoinAddress (Pieter Wuille)

Pull request description:

  This patch removes the need for the intermediary Base58 type `CBitcoinAddress`, by providing {`Encode`,`Decode`,`IsValid`}`Destination` functions that directly operate on the conversion between `std::string`s and `CTxDestination`.

  As a side, it also fixes a number of indentation issues, and removes probably several unnecessary implicit `CTxDestination`<->`CBitcoinAddress` conversions.

  This change is far from complete. In follow-ups I'd like to:
  * Split off the specific address and key encoding logic from base58.h, and move it to a address.h or so.
  * Replace `CTxDestination` with a non-`boost::variant` version (which can be more efficient as `boost::variant` allocates everything on the heap, and remove the need for `boost::get<...>` and `IsValidDestination` calls everywhere).
  * Do the same for `CBitcoinSecret`, `CBitcoinExtKey`, and `CBitcoinExtPubKey`.

  However, I've tried to keep this patch to be minimally invasive, but still enough to support non-Base58 addresses. Perhaps a smaller patch is possible to hack Bech32 support into `CBitcoinAddress`, but I would consider that a move in the wrong direction.

Tree-SHA512: c2c77ffb57caeadf2429b1c2562ce60e8c7be8aa9f8e51b591f354b6b441162625b2efe14c023a1ae485cf2ed417263afa35c892891dfaa7844e7fbabccab85e
FornaxA added a commit to ioncoincore/ion that referenced this pull request Dec 3, 2019
FornaxA added a commit to ioncoincore/ion that referenced this pull request Dec 3, 2019
FornaxA added a commit to ioncoincore/ion that referenced this pull request Dec 4, 2019
FornaxA added a commit to ioncoincore/ion that referenced this pull request Dec 4, 2019
FornaxA added a commit to ioncoincore/ion that referenced this pull request Dec 4, 2019
FornaxA added a commit to ioncoincore/ion that referenced this pull request Dec 4, 2019
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 17, 2020
864cd27 Move CBitcoinAddress to base58.cpp (Pieter Wuille)
5c8ff0d Introduce wrappers around CBitcoinAddress (Pieter Wuille)

Pull request description:

  This patch removes the need for the intermediary Base58 type `CBitcoinAddress`, by providing {`Encode`,`Decode`,`IsValid`}`Destination` functions that directly operate on the conversion between `std::string`s and `CTxDestination`.

  As a side, it also fixes a number of indentation issues, and removes probably several unnecessary implicit `CTxDestination`<->`CBitcoinAddress` conversions.

  This change is far from complete. In follow-ups I'd like to:
  * Split off the specific address and key encoding logic from base58.h, and move it to a address.h or so.
  * Replace `CTxDestination` with a non-`boost::variant` version (which can be more efficient as `boost::variant` allocates everything on the heap, and remove the need for `boost::get<...>` and `IsValidDestination` calls everywhere).
  * Do the same for `CBitcoinSecret`, `CBitcoinExtKey`, and `CBitcoinExtPubKey`.

  However, I've tried to keep this patch to be minimally invasive, but still enough to support non-Base58 addresses. Perhaps a smaller patch is possible to hack Bech32 support into `CBitcoinAddress`, but I would consider that a move in the wrong direction.

Tree-SHA512: c2c77ffb57caeadf2429b1c2562ce60e8c7be8aa9f8e51b591f354b6b441162625b2efe14c023a1ae485cf2ed417263afa35c892891dfaa7844e7fbabccab85e
UdjinM6 added a commit to dashpay/dash that referenced this pull request Jan 22, 2020
* Merge bitcoin#11117: Prepare for non-Base58 addresses

864cd27 Move CBitcoinAddress to base58.cpp (Pieter Wuille)
5c8ff0d Introduce wrappers around CBitcoinAddress (Pieter Wuille)

Pull request description:

  This patch removes the need for the intermediary Base58 type `CBitcoinAddress`, by providing {`Encode`,`Decode`,`IsValid`}`Destination` functions that directly operate on the conversion between `std::string`s and `CTxDestination`.

  As a side, it also fixes a number of indentation issues, and removes probably several unnecessary implicit `CTxDestination`<->`CBitcoinAddress` conversions.

  This change is far from complete. In follow-ups I'd like to:
  * Split off the specific address and key encoding logic from base58.h, and move it to a address.h or so.
  * Replace `CTxDestination` with a non-`boost::variant` version (which can be more efficient as `boost::variant` allocates everything on the heap, and remove the need for `boost::get<...>` and `IsValidDestination` calls everywhere).
  * Do the same for `CBitcoinSecret`, `CBitcoinExtKey`, and `CBitcoinExtPubKey`.

  However, I've tried to keep this patch to be minimally invasive, but still enough to support non-Base58 addresses. Perhaps a smaller patch is possible to hack Bech32 support into `CBitcoinAddress`, but I would consider that a move in the wrong direction.

Tree-SHA512: c2c77ffb57caeadf2429b1c2562ce60e8c7be8aa9f8e51b591f354b6b441162625b2efe14c023a1ae485cf2ed417263afa35c892891dfaa7844e7fbabccab85e

* CBitcoinAddress -> EncodeDestination in providertx.h

Signed-off-by: Pasta <pasta@dashboost.org>

* more CBitcoinAddress -> EncodeDestination in providertx.h

Signed-off-by: Pasta <pasta@dashboost.org>

* more CBitcoinAddress -> EncodeDestination in providertx.h

Signed-off-by: Pasta <pasta@dashboost.org>

* more CBitcoinAddress -> EncodeDestination in providertx.h

Signed-off-by: Pasta <pasta@dashboost.org>

* fix CBitcoinAddress GetKeyID check

Signed-off-by: Pasta <pasta@dashboost.org>

* fix providertx.cpp

Signed-off-by: Pasta <pasta@dashboost.org>

* hopefully fix governance-classes.cpp

Signed-off-by: Pasta <pasta@dashboost.org>

* partially fix governance-validators.cpp, unable to resolve "address.IsScript()"

Signed-off-by: Pasta <pasta@dashboost.org>

* partially fix governance-classes.cpp, unable to resolve "address.IsScript()"

Signed-off-by: Pasta <pasta@dashboost.org>

* fix governance-classes.h

Signed-off-by: Pasta <pasta@dashboost.org>

* DecodeTransaction -> DecodeDestination, fix governance-validators.cpp

Signed-off-by: Pasta <pasta@dashboost.org>

* More fixes for 3294

* Move GetIndexKey into rpc/misc.cpp near getAddressesFromParams

No need to have it in base58.cpp anymore as this is only used in getAddressesFromParams

Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Alexander Block <ablock84@gmail.com>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Feb 12, 2020
86e6dd4 Remove duplicate destination decoding (João Barbosa)
8d0041e Remove unused GetKeyID and IsScript methods from CBitcoinAddress (João Barbosa)

Pull request description:

  Follow up of bitcoin#11117, this patch removes an extra unnecessary destination decoding that was identified while reviewing bitcoin#11117. It is also the only case where `IsValidDestinationString` is called before `DecodeDestination`.

  For reference see [comment](bitcoin#11117 (comment)).

Tree-SHA512: f5ff5cb28a576ccd819a058f102188bde55654f30618520cc680c91d2f6e536fe038fc7220dd2d2dd64c6175fcb23f89b94b48444521e11ddec0b2f8ef2c05dd
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Feb 13, 2020
86e6dd4 Remove duplicate destination decoding (João Barbosa)
8d0041e Remove unused GetKeyID and IsScript methods from CBitcoinAddress (João Barbosa)

Pull request description:

  Follow up of bitcoin#11117, this patch removes an extra unnecessary destination decoding that was identified while reviewing bitcoin#11117. It is also the only case where `IsValidDestinationString` is called before `DecodeDestination`.

  For reference see [comment](bitcoin#11117 (comment)).

Tree-SHA512: f5ff5cb28a576ccd819a058f102188bde55654f30618520cc680c91d2f6e536fe038fc7220dd2d2dd64c6175fcb23f89b94b48444521e11ddec0b2f8ef2c05dd
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Feb 29, 2020
86e6dd4 Remove duplicate destination decoding (João Barbosa)
8d0041e Remove unused GetKeyID and IsScript methods from CBitcoinAddress (João Barbosa)

Pull request description:

  Follow up of bitcoin#11117, this patch removes an extra unnecessary destination decoding that was identified while reviewing bitcoin#11117. It is also the only case where `IsValidDestinationString` is called before `DecodeDestination`.

  For reference see [comment](bitcoin#11117 (comment)).

Tree-SHA512: f5ff5cb28a576ccd819a058f102188bde55654f30618520cc680c91d2f6e536fe038fc7220dd2d2dd64c6175fcb23f89b94b48444521e11ddec0b2f8ef2c05dd
akshaynexus added a commit to akshaynexus/pigeoncoin-dash that referenced this pull request May 6, 2020
86e6dd4b6 Remove duplicate destination decoding (João Barbosa)
8d0041e60 Remove unused GetKeyID and IsScript methods from CBitcoinAddress (João Barbosa)

Pull request description:

  Follow up of #11117, this patch removes an extra unnecessary destination decoding that was identified while reviewing #11117. It is also the only case where `IsValidDestinationString` is called before `DecodeDestination`.

  For reference see [comment](bitcoin/bitcoin#11117 (comment)).

Tree-SHA512: f5ff5cb28a576ccd819a058f102188bde55654f30618520cc680c91d2f6e536fe038fc7220dd2d2dd64c6175fcb23f89b94b48444521e11ddec0b2f8ef2c05dd
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request May 20, 2020
ac99512 [Model] Do not return a Destination if getNewAddress fails. (furszy)
cba200c CBitcoinAddress replacement for CTxDestionation encoding in RPC files. (furszy)
e319981 GUI CBitcoinAddress moved to the CTxDestination abstraction. (furszy)
6e29c1d Tier two related CBitcoinAddress moved to the CTxDestination abstraction (furszy)
8436183 getNewAddress moved to CTxDestination and Destination wrapper connected to the GUI (furszy)
fd5bd3d Destination wrapper class + DestinationFor method created. (furszy)
849c03a Introduce wrappers around CBitcoinAddress (furszy)

Pull request description:

  This patch removes the need for the intermediary Base58 type CBitcoinAddress, by providing {Encode,Decode,IsValid} Destination functions that directly operate on the conversion between std::strings and CTxDestination.

  As a side, it also fixes a number of indentation issues, and removes probably several unnecessary implicit CTxDestination<->CBitcoinAddress conversions.

  It's not a small change but it will give us much more flexibility once it's fully done over every current and new address type.

  The first commit is coming from upstream partially ([11117](bitcoin#11117)), the rest is purely tackling our code (we have so so many more places using the CBitcoinAddress class).

  And finally, have implemented a second abstraction (`Destination` wrapper) on top of the base58 address to {Encode,Decode,IsValid} Staking addresses as well.

  **Note:**
  This migration is not fully complete. It's first step, we still have places using the CBitcoinAddress object instead of the CTxDestination abstraction.

ACKs for top commit:
  Fuzzbawls:
    ACK ac99512
  random-zebra:
    ACK ac99512 and merging...

Tree-SHA512: 94388eb487948b4600749047fd4b63d651c2da3dc34a01746a50d0ae73e4d851e1a9afe4f1a371936581368b174de178e8a0f77032ba6606657339473513f904
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Jul 5, 2020
e07286d Remove possibly confusing IsValidDestinationString(str) (furszy)
a7bafa1 Implement {Encode,Decode}Destination without CBitcoinAddress (furszy)
7d3ba5d Remove unused GetKeyID and IsScript methods from CBitcoinAddress (furszy)
e7c5d9a Move CBitcoinAddress to base58.cpp (furszy)
548f828 Final migration from CBitcoinAddress to the destionation wrapper (furszy)

Pull request description:

  Finished the complete removal of the base58 address class from the sources, migrated to the destination wrapper.

  Plus includes bitcoin#11117 - last commit - and bitcoin#11259 as an extra.

ACKs for top commit:
  random-zebra:
    utACK e07286d
  Fuzzbawls:
    utACK e07286d

Tree-SHA512: b2bf4c5ed10f863f0de7ab57a87610fddab1bbe21a1f585006e5c370ba3c04635fb1314a9d9a80b2c15a66d5bfe34fd9590dc113f0d91d93d33eb37344c7f8fe
cryptolinux pushed a commit to cryptolinux/ion that referenced this pull request Feb 6, 2021
cryptolinux pushed a commit to cryptolinux/ion that referenced this pull request Feb 6, 2021
An overview of commits that implement an initial switch from using
CBitcoinAddress to CTxDestination using bech32 (in line with Bitcoin's
implementation). A 80% implementation (not cleaned up) can be found in our archives:
- cevap/ion-old-v3@3b30fd0
- cevap/ion-old-v3@f8ee3a8
- cevap/ion-old-v3@7f87033
- cevap/ion-old-v3@f0d2206
- cevap/ion-old-v3@dbddc7b
- cevap/ion-old-v3@e834f27
- cevap/ion-old-v3@2c467e1
- cevap/ion-old-v3@ef36201
- cevap/ion-old-v3@3d6e391

Implementing this switch in full is future work, which needs:
- bitcoin#11117
- bitcoin#11167
- bitcoin#11372
ckti pushed a commit to ckti-gitian-ion/ion that referenced this pull request Mar 29, 2021
ckti pushed a commit to ckti-gitian-ion/ion that referenced this pull request Mar 29, 2021
An overview of commits that implement an initial switch from using
CBitcoinAddress to CTxDestination using bech32 (in line with Bitcoin's
implementation). A 80% implementation (not cleaned up) can be found in our archives:
- cevap/ion-old-v3@3b30fd0
- cevap/ion-old-v3@f8ee3a8
- cevap/ion-old-v3@7f87033
- cevap/ion-old-v3@f0d2206
- cevap/ion-old-v3@dbddc7b
- cevap/ion-old-v3@e834f27
- cevap/ion-old-v3@2c467e1
- cevap/ion-old-v3@ef36201
- cevap/ion-old-v3@3d6e391

Implementing this switch in full is future work, which needs:
- bitcoin#11117
- bitcoin#11167
- bitcoin#11372
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Jun 26, 2021
* Merge bitcoin#11117: Prepare for non-Base58 addresses

864cd27 Move CBitcoinAddress to base58.cpp (Pieter Wuille)
5c8ff0d Introduce wrappers around CBitcoinAddress (Pieter Wuille)

Pull request description:

  This patch removes the need for the intermediary Base58 type `CBitcoinAddress`, by providing {`Encode`,`Decode`,`IsValid`}`Destination` functions that directly operate on the conversion between `std::string`s and `CTxDestination`.

  As a side, it also fixes a number of indentation issues, and removes probably several unnecessary implicit `CTxDestination`<->`CBitcoinAddress` conversions.

  This change is far from complete. In follow-ups I'd like to:
  * Split off the specific address and key encoding logic from base58.h, and move it to a address.h or so.
  * Replace `CTxDestination` with a non-`boost::variant` version (which can be more efficient as `boost::variant` allocates everything on the heap, and remove the need for `boost::get<...>` and `IsValidDestination` calls everywhere).
  * Do the same for `CBitcoinSecret`, `CBitcoinExtKey`, and `CBitcoinExtPubKey`.

  However, I've tried to keep this patch to be minimally invasive, but still enough to support non-Base58 addresses. Perhaps a smaller patch is possible to hack Bech32 support into `CBitcoinAddress`, but I would consider that a move in the wrong direction.

Tree-SHA512: c2c77ffb57caeadf2429b1c2562ce60e8c7be8aa9f8e51b591f354b6b441162625b2efe14c023a1ae485cf2ed417263afa35c892891dfaa7844e7fbabccab85e

* CBitcoinAddress -> EncodeDestination in providertx.h

Signed-off-by: Pasta <pasta@dashboost.org>

* more CBitcoinAddress -> EncodeDestination in providertx.h

Signed-off-by: Pasta <pasta@dashboost.org>

* more CBitcoinAddress -> EncodeDestination in providertx.h

Signed-off-by: Pasta <pasta@dashboost.org>

* more CBitcoinAddress -> EncodeDestination in providertx.h

Signed-off-by: Pasta <pasta@dashboost.org>

* fix CBitcoinAddress GetKeyID check

Signed-off-by: Pasta <pasta@dashboost.org>

* fix providertx.cpp

Signed-off-by: Pasta <pasta@dashboost.org>

* hopefully fix governance-classes.cpp

Signed-off-by: Pasta <pasta@dashboost.org>

* partially fix governance-validators.cpp, unable to resolve "address.IsScript()"

Signed-off-by: Pasta <pasta@dashboost.org>

* partially fix governance-classes.cpp, unable to resolve "address.IsScript()"

Signed-off-by: Pasta <pasta@dashboost.org>

* fix governance-classes.h

Signed-off-by: Pasta <pasta@dashboost.org>

* DecodeTransaction -> DecodeDestination, fix governance-validators.cpp

Signed-off-by: Pasta <pasta@dashboost.org>

* More fixes for 3294

* Move GetIndexKey into rpc/misc.cpp near getAddressesFromParams

No need to have it in base58.cpp anymore as this is only used in getAddressesFromParams

Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Alexander Block <ablock84@gmail.com>
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants