centrifuge / centrifuge-chain

Centrifuge Chain: the layer-1 blockchain for real-world assets, built on Substrate.
https://centrifuge.io
GNU Lesser General Public License v3.0
182 stars 78 forks source link

Refactor: Unify DomainAddress and account conversions (r2) #1969

Closed lemunozm closed 4 weeks ago

lemunozm commented 4 weeks ago

This PRs overwrites https://github.com/centrifuge/centrifuge-chain/pull/1967

Description

Represents DomainAddress as:

enum DomainAddress {
    Centrifuge(AccountId32),
    Evm(EVMChainId, H160),
}

With some utility methods as:

fn account() -> AccountId32;
fn h160() -> H160;
fn bytes() -> [u8; 32];

Main changes

lemunozm commented 4 weeks ago

@wischli @cdamian I tried my best from your inputs in the other PR. I would really love to have types who knows about conversions but it's quite tedious for Monday (we also will need implement them with a lot of traits, etc).

I think this solution leaves things easier than before, but of course, it still can be improved with more sophisticated solutions.

Let me know if you agree more with the names than the before PR.

lemunozm commented 4 weeks ago

As for the naming of fn bytes(), I am not 100% on board

I wanted to not use address because it's quite generic, could be not just an array, and for that method we're specifying that we want the account as an array of bytes.

Rust names *_bytes() to actions that return an array, but I am open to other names, I can do it in a next PR if needed

lemunozm commented 4 weeks ago

I'm very happy to have this PR before the audit! 🎉