ethereum / eth-utils

Utility functions for working with ethereum related codebases.
https://eth-utils.readthedocs.io/en/latest/
MIT License
312 stars 148 forks source link

Add Network name utility #255

Closed DavidRomanovizc closed 10 months ago

DavidRomanovizc commented 11 months ago

What was wrong?

Related to Issue #253 Closes #253

How was it fixed?

Created dictionaries network_names and network_short_names and the list networks that contains objects of the Network class with data about the network, including chain_id, name, shortName, and symbol. And implemented three functions: the first one extracts data from Network, the second one returns the Network name, and the third one returns the short network name. Additionally, I covered the code with parameterized tests.

Todo:

Cute Animal Picture

image
reedsa commented 11 months ago

Hey @DavidRomanovizc nice work here and great to see the tests. Thinking about long term maintenance, I think we should just load and parse the JSON straight from https://chainid.network/chains_mini.json and then just loop over those to initialize each Network object.

If you have a chance to update how the initialization is done we'll get these merged! Thanks.

DavidRomanovizc commented 11 months ago

Hey @DavidRomanovizc nice work here and great to see the tests. Thinking about long term maintenance, I think we should just load and parse the JSON straight from https://chainid.network/chains_mini.json and then just loop over those to initialize each Network object.

If you have a chance to update how the initialization is done we'll get these merged! Thanks.

Hello! I have updated the code. Now we load data from JSON, but our ChainId is not updating. If we have to load a new network from JSON and there is no ChainId present, it will raise a ValueError. Maybe we need update class ChainId

reedsa commented 10 months ago

Got it, that makes sense. I'll make sure to update eth-typings with the latest networks periodically.

DavidRomanovizc commented 10 months ago

Got it, that makes sense. I'll make sure to update eth-typings with the latest networks periodically.

Also I've been thinking about the fact that we can get the symbol from the JSON, so we won't need the ChainId. Can we do that or we need use ChainId in this task?

reedsa commented 10 months ago

@DavidRomanovizc that's a good thought, though the Network typings are better off if we keep ChainId. It shouldn't take much to maintain the list in eth-typing, where I'll be adding a script to update that list for us.

reedsa commented 10 months ago

@DavidRomanovizc one more thank you! Appreciate the contribution.