Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isEthereum to ChainProperties #5686

Merged
merged 8 commits into from
Sep 1, 2023

Conversation

fgamundi
Copy link
Contributor

@fgamundi fgamundi commented Jul 6, 2023

Giving the growing number of Ethereum based substrate chains, the Tanssi team is proposing to add isEthereum to the chain properties so apps (such as polkadotjs-apps) can easily distinguish if the chain they're connecting to is Ethereum-based or not without having to maintain and update a manual list.

@jacogr
Copy link
Member

jacogr commented Jul 7, 2023

This gets us half-way and is a great start.

With the chain properties, we have to ensure it is correctly decorated on the registry as well (so users can just use registry.chainProperties() instead of via RPC, you no doubt saw that apps doesn't replicate all the logic again).

This part is done in the registry (where it also combines existing on-chain constants - always taking precedence, hence not applying that in eg. apps), you can find it here -

// extract additional properties from the metadata
function extractProperties (registry: TypeRegistry, metadata: Metadata): ChainProperties | undefined {
const original = registry.getChainProperties();
const constants = decorateConstants(registry, metadata.asLatest, metadata.version);
const ss58Format = constants['system'] && (constants['system']['sS58Prefix'] || constants['system']['ss58Prefix']);
if (!ss58Format) {
return original;
}
const { tokenDecimals, tokenSymbol } = original || {};
return registry.createTypeUnsafe<ChainProperties>('ChainProperties', [{ ss58Format, tokenDecimals, tokenSymbol }]);
}

And here is where it is called/used -

// setup the chain properties with format overrides
this.setChainProperties(
extractProperties(this, metadata)
);

@fgamundi
Copy link
Contributor Author

Hi @jacogr. Thanks for the review and explanation! I've updated the registry to set isEthereum

@fgamundi fgamundi marked this pull request as ready for review July 10, 2023 14:33
@girazoki
Copy link
Contributor

@jacogr any news on this side? it would be important for us as we will start having chains that need addresses being represented in ethereum format

Copy link
Member

@jacogr jacogr left a comment

Choose a reason for hiding this comment

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

Why are we using Option<Bool> instead of just Bool?

I looked through and cannot see specific benefit.

With Option<Bool>:

  • if not specified it is isNone (which is equivalent to false)
  • if specified, it returns isTrue or isFalse

With Bool:

  • If not specified, it is isFalse
  • if specified, it is either isTrue or isFalse

The benefit of using Bool is that we don't need to go through unwrapping magic on use, i.e. it is a straight flag check.

EDIT: It would also be useful to add a getter (like the other chain* retrievals) to the registry for chainIsEthereum(): boolean (This makes downstream usage aq walk in the park)

@fgamundi fgamundi requested a review from jacogr August 31, 2023 15:53
Copy link
Member

@jacogr jacogr left a comment

Choose a reason for hiding this comment

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

Thank you.

@jacogr jacogr merged commit 74a969b into polkadot-js:master Sep 1, 2023
4 checks passed
@fgamundi fgamundi deleted the fg-properties-isEthereum branch September 1, 2023 09:45
@polkadot-js-bot
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Sep 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants