-
Notifications
You must be signed in to change notification settings - Fork 12
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
Deploy new registries and release packages #49
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e569a3a
Implement add and update registry store
njgheorghita 773e3a9
Implement activate registry
njgheorghita 04d198a
Implement ethpm registry list
njgheorghita cb8d8dc
Integration tests for registry cli commands
njgheorghita f5da2d1
Implement ethpm registry publish
njgheorghita 20f270a
Move registry store to xdg ethpmcli root
njgheorghita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,19 @@ | |
from pathlib import Path | ||
from typing import Any, Dict | ||
|
||
from eth_account import Account | ||
from eth_utils import to_checksum_address | ||
from ethpm.constants import SUPPORTED_CHAIN_IDS | ||
from web3 import Web3 | ||
from web3.auto.infura.endpoints import build_http_headers, build_infura_url | ||
from web3.middleware import construct_sign_and_send_raw_middleware | ||
from web3.providers.auto import load_provider_from_uri | ||
|
||
from ethpm_cli._utils.filesystem import atomic_replace | ||
from ethpm_cli._utils.ipfs import get_ipfs_backend | ||
from ethpm_cli._utils.logger import cli_logger | ||
from ethpm_cli._utils.xdg import get_xdg_ethpmcli_root | ||
from ethpm_cli.auth import get_authorized_private_key, import_keyfile | ||
from ethpm_cli.constants import ( | ||
ETHPM_DIR_ENV_VAR, | ||
ETHPM_PACKAGES_DIR, | ||
|
@@ -32,6 +37,8 @@ class Config: | |
- Projects dir | ||
""" | ||
|
||
private_key = None | ||
|
||
def __init__(self, args: Namespace) -> None: | ||
# Setup IPFS backend | ||
if "local_ipfs" in args and args.local_ipfs: | ||
|
@@ -52,13 +59,20 @@ def __init__(self, args: Namespace) -> None: | |
|
||
# Setup w3 | ||
if "chain_id" in args and args.chain_id: | ||
self.w3 = get_w3(args.chain_id) | ||
chain_id = args.chain_id | ||
else: | ||
self.w3 = get_w3(1) | ||
chain_id = 1 | ||
|
||
if "keyfile_path" in args and args.keyfile_path: | ||
import_keyfile(args.keyfile_path) | ||
|
||
if "keyfile_password" in args and args.keyfile_password: | ||
self.private_key = get_authorized_private_key(args.keyfile_password) | ||
self.w3 = setup_w3(chain_id, self.private_key) | ||
|
||
# Setup xdg ethpm dir | ||
xdg_ethpmcli_root = get_xdg_ethpmcli_root() | ||
setup_xdg_ethpm_dir(xdg_ethpmcli_root, self.w3) | ||
self.xdg_ethpmcli_root = get_xdg_ethpmcli_root() | ||
setup_xdg_ethpm_dir(self.xdg_ethpmcli_root, self.w3) | ||
|
||
# Setup projects dir | ||
if "project_dir" in args and args.project_dir: | ||
|
@@ -68,7 +82,7 @@ def __init__(self, args: Namespace) -> None: | |
self.project_dir = None | ||
|
||
|
||
def get_w3(chain_id: int) -> Web3: | ||
def setup_w3(chain_id: int, private_key: str = None) -> Web3: | ||
if chain_id not in SUPPORTED_CHAIN_IDS.keys(): | ||
raise ValidationError( | ||
f"Chain ID: {chain_id} is invalid. Currently supported chain ids " | ||
|
@@ -77,7 +91,18 @@ def get_w3(chain_id: int) -> Web3: | |
infura_url = f"{SUPPORTED_CHAIN_IDS[chain_id]}.infura.io" | ||
headers = build_http_headers() | ||
infura_url = build_infura_url(infura_url) | ||
return Web3(load_provider_from_uri(infura_url, headers)) | ||
w3 = Web3(load_provider_from_uri(infura_url, headers)) | ||
|
||
if private_key is not None: | ||
owner_address = Account.from_key(private_key).address | ||
signing_middleware = construct_sign_and_send_raw_middleware(private_key) | ||
w3.middleware_onion.add(signing_middleware) | ||
w3.eth.defaultAccount = to_checksum_address(owner_address) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be a good place to issue a |
||
cli_logger.debug( | ||
"In-flight tx signing has been enabled for address: {owner_address}." | ||
) | ||
w3.enable_unstable_package_management_api() | ||
return w3 | ||
|
||
|
||
def setup_xdg_ethpm_dir(xdg_ethpmcli_root: Path, w3: Web3) -> None: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nice upstream change would be for the library to raise something less generic than a
ValueError
on authentication failure.