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

[ethpm] Allow registry uri to namespace package assets #1576

Merged

Conversation

njgheorghita
Copy link
Contributor

@njgheorghita njgheorghita commented Feb 7, 2020

What was wrong?

Updated the ethpm uri parsing functions to support namespaced assets.
ethpm://compound.ethpm.eth:1/[email protected]/deployments/cDai

This will be useful in the ethpm widget - so that all the data needed to fetch the contract address of a deployment is in a single url.

Todo:

Cute Animal Picture

image

@njgheorghita njgheorghita changed the title Allow registry uri to namespace package assets [ethpm] Allow registry uri to namespace package assets Feb 7, 2020
@njgheorghita njgheorghita force-pushed the ethpm-registry-uri-update branch 2 times, most recently from 6e98b8f to 5ad7647 Compare February 7, 2020 11:57
RegistryURI = namedtuple("RegistryURI", ["address", "chain_id", "name", "version", "ens"])
RegistryURI = namedtuple(
"RegistryURI",
["address", "chain_id", "name", "version", "namespaced_asset", "ens"]
Copy link
Member

Choose a reason for hiding this comment

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

FYI, if you aren't aware, what you are calling namespace_asset is a JSON Pointer

Copy link
Contributor Author

@njgheorghita njgheorghita Feb 8, 2020

Choose a reason for hiding this comment

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

Oh, good to know! I'm not sure if it's strictly a JSON pointer? Essentially, when trying to specify a certain deployment - I'm trying to avoid requiring the entire blockchain URI. Do you think that's a bad idea?

Basically...
ethpm://maker.ethpm.eth:1/[email protected]/deployments/DeploymentName
Is what you would need to fetch the DeploymentName deployment on the mainnet . . . . It seems like there might be some edge cases where this isn't ideal - in terms of forked chains that share a chain ID? Since this is for the widget - I was thinking of just specifying that a registry URI with a pointer/namespaced asset only supports the 5 main chains.

def _parse_pkg_path(pkg_path: str) -> Tuple[str, Optional[str]]:
if "/" in pkg_path:
pkg_id = pkg_path.split("/")[0]
namespaced_asset = "/".join(pkg_path.split("/")[1:])
Copy link
Member

Choose a reason for hiding this comment

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

These two lines can be replaced with:

pkg_id, _, namespaced_asset = pkg_path.partition('/')


def _parse_pkg_id(pkg_id: str) -> Tuple[str, Optional[str]]:
if "@" not in pkg_id:
return pkg_id, None
pkg_name, safe_pkg_version = pkg_id.split("@")
Copy link
Member

Choose a reason for hiding this comment

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

This call still jumps out to me as a minor problem. It relies on validation that happens outside of this function. If you change this to pkg_name, _, safe_pkg_version = pkg_id.partition('@') then this code would be slightly more robust. Totally a nitpick on my part.

@njgheorghita njgheorghita merged commit 1a6804a into ethereum:master Feb 10, 2020
@njgheorghita njgheorghita deleted the ethpm-registry-uri-update branch February 10, 2020 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants