Skip to content

Commit

Permalink
Add pipy entrypoints for console scripts
Browse files Browse the repository at this point in the history
- Update README
  • Loading branch information
Uxio0 committed Mar 4, 2022
1 parent d364c15 commit c645327
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 65 deletions.
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ Command line utility for **Gnosis Safe** contracts. Use it to manage your **Gnos
**Python >= 3.7** is required. **Python 3.10** is recommended.

```bash
git clone https://github.com/gnosis/safe-cli.git
cd safe-cli
stat venv 2>/dev/null || python -m venv venv
source venv/bin/activate && pip install -r requirements.txt
pip3 -U safe-cli
```

## Using
```bash
cd safe-cli
source venv/bin/activate
python safe_cli.py <checksummed_safe_address> <ethereum_node_url>
safe-cli <checksummed_safe_address> <ethereum_node_url>
```

Then you should be on the prompt and see information about the Safe, like the owners, version, etc.
Expand Down Expand Up @@ -108,11 +103,11 @@ the information about the Safe using:
```

## Creating a new Safe
Use `safe_creator.py <node_url> <private_key> --owners <checksummed_address_1> <checksummed_address_2> --threshold <uint> --salt-nonce <uint256>`.
Use `safe-creator <node_url> <private_key> --owners <checksummed_address_1> <checksummed_address_2> --threshold <uint> --salt-nonce <uint256>`.

Example:
```
python safe_creator.py https://rinkeby.infura.io/v3/token $PRIVATE_KEY --owners 0x848EF06Bb9d1bc79Bb3B04b7Ea0e251C6E788d7c --threshold 1
safe-creator https://rinkeby.infura.io/v3/token $PRIVATE_KEY --owners 0x848EF06Bb9d1bc79Bb3B04b7Ea0e251C6E788d7c --threshold 1
```

## Demo
Expand All @@ -135,6 +130,17 @@ to an invalid Safe Master Copy.
- [Safe contracts](https://github.com/gnosis/safe-contracts)
- [Safe contracts deployment info and addreses](https://github.com/gnosis/safe-deployments/tree/main/src/assets)

## Setting up for developing
If you miss something and want to send us a PR:

```bash
git clone https://github.com/gnosis/safe-cli.git
cd safe-cli
stat venv 2>/dev/null || python3 -m venv venv
source venv/bin/activate && pip install -r requirements-dev.txt
pre-commit install -f
```

## Contributors
- [Pedro Arias Ruiz](https://github.com/AsiganTheSunk)
- [Uxío Fuentefría](https://github.com/uxio0) (uxio@gnosis.pm)
- [Uxío Fuentefría](https://github.com/uxio0) (uxio@gnosis.io)
5 changes: 4 additions & 1 deletion safe_cli.py → safe_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ def loop(self):
pass


if __name__ == "__main__":
def main(*args, **kwgars):
"""
Entry point for the Safe-CLI
"""
safe_cli = SafeCli()
safe_cli.print_startup_info()
safe_cli.loop()
106 changes: 57 additions & 49 deletions safe_creator.py → safe_cli/safe_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,57 +49,65 @@ def check_private_key(private_key: str) -> str:
return private_key


parser = argparse.ArgumentParser()
parser.add_argument("node_url", help="Ethereum node url")
parser.add_argument("private_key", help="Deployer private_key", type=check_private_key)
parser.add_argument(
"--threshold",
help="Number of owners required to execute transactions on the created Safe. It must"
"be greater than 0 and less or equal than the number of owners",
type=positive_integer,
default=1,
)
parser.add_argument(
"--owners",
help="Owners. By default it will be just the deployer",
nargs="+",
type=check_ethereum_address,
)
parser.add_argument(
"--safe-contract",
help="Use a custom Safe master copy",
default=None,
type=check_ethereum_address,
)
parser.add_argument(
"--proxy-factory",
help="Use a custom proxy factory",
default=LAST_PROXY_FACTORY_CONTRACT,
type=check_ethereum_address,
)
parser.add_argument(
"--callback-handler",
help="Use a custom fallback handler. It is not required for Safe Master Copies "
"with version < 1.1.0",
default=LAST_DEFAULT_CALLBACK_HANDLER,
type=check_ethereum_address,
)
parser.add_argument(
"--salt-nonce",
help="Use a custom nonce for the deployment. Same nonce with same deployment configuration will "
"lead to the same Safe address ",
default=secrets.SystemRandom().randint(0, 2**256 - 1), # TODO Add support for CPK
type=int,
)
def setup_argument_parser():
parser = argparse.ArgumentParser()
parser.add_argument("node_url", help="Ethereum node url")
parser.add_argument(
"private_key", help="Deployer private_key", type=check_private_key
)
parser.add_argument(
"--threshold",
help="Number of owners required to execute transactions on the created Safe. It must"
"be greater than 0 and less or equal than the number of owners",
type=positive_integer,
default=1,
)
parser.add_argument(
"--owners",
help="Owners. By default it will be just the deployer",
nargs="+",
type=check_ethereum_address,
)
parser.add_argument(
"--safe-contract",
help="Use a custom Safe master copy",
default=None,
type=check_ethereum_address,
)
parser.add_argument(
"--proxy-factory",
help="Use a custom proxy factory",
default=LAST_PROXY_FACTORY_CONTRACT,
type=check_ethereum_address,
)
parser.add_argument(
"--callback-handler",
help="Use a custom fallback handler. It is not required for Safe Master Copies "
"with version < 1.1.0",
default=LAST_DEFAULT_CALLBACK_HANDLER,
type=check_ethereum_address,
)
parser.add_argument(
"--salt-nonce",
help="Use a custom nonce for the deployment. Same nonce with same deployment configuration will "
"lead to the same Safe address ",
default=secrets.SystemRandom().randint(
0, 2**256 - 1
), # TODO Add support for CPK
type=int,
)

parser.add_argument(
"--l2",
help="Use L2 deployment of the Safe instead of the regular one. Recommended for every network but mainnet",
default=False,
action="store_true",
)
return parser

parser.add_argument(
"--l2",
help="Use L2 deployment of the Safe instead of the regular one. Recommended for every network but mainnet",
default=False,
action="store_true",
)

if __name__ == "__main__":
def main(*args, **kwargs):
parser = setup_argument_parser()
print_formatted_text(
pyfiglet.figlet_format("Gnosis Safe Creator")
) # Print fancy text
Expand Down
12 changes: 7 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name="safe_cli",
version="0.2.0",
version="0.3.0",
author="Uxío Fuentefría",
author_email="uxio@gnosis.io",
description="Command Line Interface for Gnosis Safe",
Expand All @@ -28,10 +28,12 @@
"typing_extensions>=4; python_version < '3.8'",
],
packages=setuptools.find_packages(),
# scripts=[
# 'safe_cli.py',
# 'safe_creator.py',
# ],
entry_points={
"console_scripts": [
"safe-cli=safe_cli.main:main",
"safe-creator=safe_cli.safe_creator:main",
],
},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down

0 comments on commit c645327

Please sign in to comment.