Skip to content

Conversation

@furszy
Copy link

@furszy furszy commented May 3, 2020

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), 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.

@furszy furszy self-assigned this May 3, 2020
@furszy furszy force-pushed the 2020_refactor_addresses branch 2 times, most recently from c8f0f9e to f45da49 Compare May 11, 2020 02:35
@furszy
Copy link
Author

furszy commented May 11, 2020

Rebased + rpc files CBitcoinAddress migration added.

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

Big PR. Good job 👍 We can (should) probably simplify and abstract some of the ugliness due to staking addresses with a better definition of them (either as variant or child class) in the future.

Anyway, looking good from visual inspection: concept and code ACK modulo some questions, comments and/or nits inlined.
Mostly around:

  1. IsValidDestinationString formula for staking addresses with &&

  2. The extra overridden version of IsValidDestinationString: we don't need params to be passed as an external argument to IsValid (at the moment). We should probably include that only when we remove the dependency from CChainParams

  3. The usage of !boost::get<CNoDestination>(&address) instead of IsValidDestination(address). There are many instances, I haven't commented all of them.

  4. a few double decoding operations due to the general path

    if (!IsValidDestinationString(address_string) {
        // return some error
    } 
    CTxDestination dest = DecodeDestination(address_string);
    ...
    

    which should be

    CTxDestination dest = DecodeDestination(address_string);
    if (!IsValidDestination(dest)) {
        // return some error
    }
    ...
    

furszy added 3 commits May 14, 2020 20:40
This patch removes the need for the intermediary Base58 type
CBitcoinAddress, by providing {Encode,Decode,IsValid}Destination
function that directly operate on the conversion between strings
and CTxDestination.

-- Not all of the CBitcoinAddress instances were ported --

Coming from btc@5c8ff0d448ffdc6340b195ddfa2128d5f21a839b
@furszy furszy force-pushed the 2020_refactor_addresses branch from f45da49 to 968d366 Compare May 15, 2020 01:15
@furszy
Copy link
Author

furszy commented May 15, 2020

Thanks for the feedback zebra, went commit by commit and solved most of them.

@furszy furszy force-pushed the 2020_refactor_addresses branch 2 times, most recently from 60966f6 to c6a3e91 Compare May 15, 2020 16:00
@furszy
Copy link
Author

furszy commented May 15, 2020

just force pushed it few times because found more boost::get to move to IsValidDestination.

It's good now.

@furszy furszy force-pushed the 2020_refactor_addresses branch 2 times, most recently from 40557f1 to 024d01c Compare May 18, 2020 21:49
@furszy furszy force-pushed the 2020_refactor_addresses branch from 024d01c to ac99512 Compare May 19, 2020 01:04
Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

Nice one. Full sync check done now.

ACK ac99512

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

ACK ac99512 and merging...

@random-zebra random-zebra merged commit f59c8fb into PIVX-Project:master May 20, 2020
furszy added a commit that referenced this pull request Jun 28, 2020
422d2d3 CBitcoinAddress to wrapper migration (furszy)
287a7b0 CompactTallyItem unused struct removed (furszy)
4b4c5a0 Replace CBitcoinSecret with {Encode,Decode}Secret (furszy)

Pull request description:

  Mixed few things here:

  1) Follow up over #1593 work. The only remaining places that are not using the destination methods are in the walletmodel and wallet objects (next PR), the rest were all already migrated.
  2) CBitcoinSecret with {Encode,Decode}Secret (adapted version of upstream@32e69fa0).
  3) Unused code removal (second commit).

ACKs for top commit:
  random-zebra:
    ACK 422d2d3
  Fuzzbawls:
    ACK 422d2d3

Tree-SHA512: de45c2d66bdb76f48be33352fb278d91294e0171cb1af5f677c5393b7beb8441640aeaf714bc01d3d576e635f3521969b122fb2ab1c7f7aff5cb0c1aeb469b09
@furszy furszy deleted the 2020_refactor_addresses branch November 29, 2022 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants