Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Commit

Permalink
Merge #28
Browse files Browse the repository at this point in the history
28: Releasing 0.20.1 Python Client r=sacherjj a=sacherjj

Documentation updates.
Bug fixing for missing entry_point_name and version lost with merging account_hash.


Co-authored-by: Medha Parlikar <[email protected]>
Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
Co-authored-by: Joe Sacher <[email protected]>
  • Loading branch information
3 people authored Jul 30, 2020
2 parents ed5645a + 4720d9f commit 93797bf
Show file tree
Hide file tree
Showing 23 changed files with 884 additions and 182 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ flake8 = "*"
protobuf = "==3.12.2"
pycryptodome = "==3.9.4"
coverage = "*"
asn1tools = "*"
pytest-mock = "*"

[requires]
python_version = "3.7"
211 changes: 136 additions & 75 deletions Pipfile.lock

Large diffs are not rendered by default.

45 changes: 30 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,41 @@
Note, the name of the package available on PyPi is `casperlabs-client` (with hyphen),
but the name of the library as well as the CLI is written with underscore: `casperlabs_client`.

## Installation
## Linux Installation

These instructions are for Ubuntu 18.04 and 20.04.
Note: The default versions of Python are different for both versions of Ubuntu.
These steps are required prior to activating the Python environment every time the client is used.

`casperlabs-client` is a Python 3.7+ module, it does not support Python 2.7.

Note: we highly recommend using
[pipenv](https://github.com/pypa/pipenv)
or
[virtualenv](https://virtualenv.pypa.io/en/latest/).
##### For Ubuntu 18.04 follow these steps to activate the environment:
```
sudo apt install gcc
sudo apt install python3.7
sudo apt-get install python3.7-dev
virtualenv -p python3.7 env
```

##### For Ubuntu 20.04 follow these steps:
```
sudo apt install gcc
sudo apt install python3.8
sudo apt-get install python3.8-dev
virtualenv -p python3.8 env
```

### Activate the environment

Each time you use the virtual environment you need to activate it. This is done with a script inside the `env` directory you created.

`source env/bin/activate`

### Linux
You will need to do this for the install below, but also each time you open a new terminal to run the `casperlabs_client` once installed.

Due to the issue
["pip install cryptography segmentation fault (SIGSEGV)"](https://github.com/pyca/cryptography/issues/3815),
which affects popular Linux distributions like Ubuntu,
we recommend installing `casperlabs-client` in an isolated Python 3 environment created with
[pipenv](https://github.com/pypa/pipenv)
or
[virtualenv](https://virtualenv.pypa.io/en/latest/).
### Install the Client

After activating a pipenv or virtualenv environment you can install the `casperlabs_client` package with
After activating the Python environment, install the `casperlabs_client` package with

```
python -m pip install casperlabs-client
Expand Down Expand Up @@ -78,7 +93,7 @@ typing the following on the command line:
C:\Users\alice>python -m pip install casperlabs-client
```

## Command line interface
## Using the Client Command line interface (CLI)

The package `casperlabs-client` includes command line interface (CLI)
script called `casperlabs_client`.
Expand Down
2 changes: 1 addition & 1 deletion casperlabs_client/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.20.0
0.20.1
30 changes: 15 additions & 15 deletions casperlabs_client/casperlabs_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,19 @@ def make_deploy(
public_key_hex: str = None,
algorithm: str = ED25519_KEY_ALGORITHM,
payment: Union[Path, str] = None,
payment_args: bytes = None,
payment_args: Union[bytes, str] = None,
payment_amount: int = None,
payment_hash: bytes = None,
payment_hash: Union[bytes, str] = None,
payment_name: str = None,
payment_package_hash: bytes = None,
payment_package_hash: Union[bytes, str] = None,
payment_package_name: str = None,
payment_entry_point: str = None,
payment_version: int = None,
session: Union[Path, str] = None,
session_args: bytes = None,
session_hash: bytes = None,
session_args: Union[bytes, str] = None,
session_hash: Union[bytes, str] = None,
session_name: str = None,
session_package_hash: bytes = None,
session_package_hash: Union[bytes, str] = None,
session_package_name: str = None,
session_entry_point: str = None,
session_version: int = None,
Expand Down Expand Up @@ -306,19 +306,19 @@ def deploy(
private_key_hex: str = None,
algorithm: str = ED25519_KEY_ALGORITHM,
payment: Union[Path, str] = None,
payment_args: bytes = None,
payment_args: Union[bytes, str] = None,
payment_amount: int = None,
payment_hash: bytes = None,
payment_hash: Union[bytes, str] = None,
payment_name: str = None,
payment_package_hash: bytes = None,
payment_package_hash: Union[bytes, str] = None,
payment_package_name: str = None,
payment_entry_point: str = None,
payment_version: int = None,
session: Union[Path, str] = None,
session_args: bytes = None,
session_hash: bytes = None,
session_args: Union[bytes, str] = None,
session_hash: Union[bytes, str] = None,
session_name: str = None,
session_package_hash: bytes = None,
session_package_hash: Union[bytes, str] = None,
session_package_name: str = None,
session_entry_point: str = None,
session_version: int = None,
Expand Down Expand Up @@ -415,11 +415,11 @@ def transfer(
private_key_hex: str = None,
algorithm: str = ED25519_KEY_ALGORITHM,
payment: str = None,
payment_args: bytes = None,
payment_args: Union[bytes, str] = None,
payment_amount: int = None,
payment_hash: bytes = None,
payment_hash: Union[bytes, str] = None,
payment_name: str = None,
payment_package_hash: bytes = None,
payment_package_hash: Union[bytes, str] = None,
payment_package_name: str = None,
payment_entry_point: str = None,
payment_version: int = None,
Expand Down
18 changes: 8 additions & 10 deletions casperlabs_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
deploy_cmd,
keygen_cmd,
make_deploy_cmd,
propose_cmd,
stream_events_cmd,
transfer_cmd,
sign_deploy_cmd,
Expand All @@ -31,7 +30,7 @@
)


def cli(*arguments) -> int:
def cli(*arguments, client=None) -> int:
"""
Parse list of method line arguments and call appropriate method.
"""
Expand Down Expand Up @@ -107,19 +106,19 @@ def add_command(
for (args, options) in argument_list:
command_parser.add_argument(*args, **options)

def run(self, argv):
def run(self, argv, client=None):
# Using dict rather than namespace to allow dual interface with library
args = vars(self.parser.parse_args(argv))
return args["function"](
CasperLabsClient(
if client is None:
client = CasperLabsClient(
args.get("host"),
args.get("port"),
args.get("port_internal"),
args.get("node_id"),
args.get("certificate_file"),
),
args,
)
)

return args["function"](client, args,)

parser = Parser()

Expand All @@ -129,7 +128,6 @@ def run(self, argv):
deploy_cmd,
keygen_cmd,
make_deploy_cmd,
propose_cmd,
query_state_cmd,
send_deploy_cmd,
show_block_cmd,
Expand All @@ -145,7 +143,7 @@ def run(self, argv):
):
parser.add_command(command.NAME, command.method, command.HELP, command.OPTIONS)

return parser.run([str(a) for a in arguments])
return parser.run([str(a) for a in arguments], client=client)


def main():
Expand Down
12 changes: 8 additions & 4 deletions casperlabs_client/commands/deploy_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,28 @@
def method(casperlabs_client: CasperLabsClient, args: Dict):
deploy_hash = casperlabs_client.deploy(
from_addr=args.get("from"),
payment=args.get("payment"),
session=args.get("session"),
private_key=args.get("private_key"),
session_args=args.get("session_args"),
algorithm=args.get("algorithm"),
payment=args.get("payment"),
payment_args=args.get("payment_args"),
payment_amount=args.get("payment_amount"),
payment_hash=args.get("payment_hash"),
payment_name=args.get("payment_name"),
payment_package_hash=args.get("payment_package_hash"),
payment_package_name=args.get("payment_package_name"),
payment_entry_point=args.get("payment_entry_point"),
payment_version=args.get("payment_version"),
session=args.get("session"),
session_args=args.get("session_args"),
session_hash=args.get("session_hash"),
session_name=args.get("session_name"),
session_package_hash=args.get("session_package_hash"),
session_package_name=args.get("session_package_name"),
session_entry_point=args.get("session_entry_point"),
session_version=args.get("session_version"),
ttl_millis=args.get("ttl_millis"),
dependencies=args.get("dependencies"),
chain_name=args.get("chain_name"),
algorithm=args.get("algorithm"),
)
print(f"Success! Deploy {deploy_hash} deployed")
if args.get("wait_for_processed", False):
Expand Down
29 changes: 18 additions & 11 deletions casperlabs_client/commands/make_deploy_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@

NAME: str = "make-deploy"
HELP: str = "Constructs a deploy that can be signed and sent to a node."
OPTIONS = [
OPTIONS = (
[
("-o", "--deploy-path"),
dict(
required=False,
help=(
"Path to the file where deploy will be saved. "
"Optional, if not provided the deploy will be printed to STDOUT."
[
("-o", "--deploy-path"),
dict(
required=False,
help=(
"Path to the file where deploy will be saved. "
"Optional, if not provided the deploy will be printed to STDOUT."
),
),
),
],
public_key_option(required=False),
] + DEPLOY_OPTIONS
]
]
+ [public_key_option(required=False)]
+ DEPLOY_OPTIONS
)


@guarded_command
Expand All @@ -38,10 +41,14 @@ def method(casperlabs_client: CasperLabsClient, args: Dict):
payment_name=args.get("payment_name"),
payment_package_hash=args.get("payment_package_hash"),
payment_package_name=args.get("payment_package_name"),
payment_entry_point=args.get("payment_entry_point"),
payment_version=args.get("payment_version"),
session_hash=args.get("session_hash"),
session_name=args.get("session_name"),
session_package_hash=args.get("session_package_hash"),
session_package_name=args.get("session_package_name"),
session_entry_point=args.get("session_entry_point"),
session_version=args.get("session_version"),
ttl_millis=args.get("ttl_millis"),
dependencies=args.get("dependencies"),
chain_name=args.get("chain_name"),
Expand Down
18 changes: 0 additions & 18 deletions casperlabs_client/commands/propose_cmd.py

This file was deleted.

2 changes: 1 addition & 1 deletion casperlabs_client/commands/stream_events_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

def _add_to_list(maybe_value) -> List:
if maybe_value:
return [maybe_value]
return maybe_value
else:
return []

Expand Down
5 changes: 3 additions & 2 deletions casperlabs_client/commands/transfer_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def method(casperlabs_client: CasperLabsClient, args: dict):
target_account=args.get("target_account"),
target_purse=args.get("target_purse"),
source_purse=args.get("source_purse"),
from_addr=args.get("from_addr"),
from_addr=args.get("from"),
private_key=args.get("private_key"),
ttl_millis=args.get("ttl_millis"),
dependencies=args.get("dependencies"),
Expand All @@ -80,12 +80,13 @@ def method(casperlabs_client: CasperLabsClient, args: dict):
payment_hash=args.get("payment_hash"),
payment_name=args.get("payment_name"),
payment_entry_point=args.get("payment_entry_point"),
payment_version=args.get("payment_version"),
payment_package_hash=args.get("payment_package_hash"),
payment_package_name=args.get("payment_package_name"),
)
print(f"Success! Deploy {deploy_hash} deployed")
if args.get("wait_for_processed", False):
deploy_info = casperlabs_client.showDeploy(
deploy_info = casperlabs_client.show_deploy(
deploy_hash,
full_view=False,
wait_for_processed=True,
Expand Down
17 changes: 13 additions & 4 deletions casperlabs_client/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from . import consensus_pb2 as consensus

from .abi import ABI
from .reformat import optional_base64_base16_to_bytes


@dataclass
Expand Down Expand Up @@ -140,9 +141,13 @@ def validate(self) -> None:
def from_args(args: Dict) -> "SessionCode":
""" Creates SessionCode from CLI args """
wasm_file_path = args.get("session")
contract_hash = args.get("session_hash")
contract_hash = optional_base64_base16_to_bytes(
args.get("session_hash"), "session_hash"
)
contract_name = args.get("session_name")
package_hash = args.get("session_package_hash")
package_hash = optional_base64_base16_to_bytes(
args.get("session_package_hash"), "session_package_hash"
)
package_name = args.get("session_package_name")
entry_point = args.get("session_entry_point")
version = args.get("session_version")
Expand Down Expand Up @@ -204,9 +209,13 @@ def validate(self) -> None:
def from_args(args: Dict) -> "PaymentCode":
wasm_file_path = args.get("payment")
payment_amount = args.get("payment_amount")
contract_hash = args.get("payment_hash")
contract_hash = optional_base64_base16_to_bytes(
args.get("payment_hash"), "payment_hash"
)
contract_name = args.get("payment_name")
package_hash = args.get("payment_package_hash")
package_hash = optional_base64_base16_to_bytes(
args.get("payment_package_hash"), "payment_package_hash"
)
package_name = args.get("payment_package_name")
entry_point = args.get("payment_entry_point")
version = args.get("payment_version")
Expand Down
7 changes: 4 additions & 3 deletions casperlabs_client/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from casperlabs_client import crypto
from .contract import PaymentCode, SessionCode
from .key_holders import ED25519Key, SECP256K1Key
from .reformat import optional_base64_base16_to_bytes


def sign_deploy(deploy, key_holder):
Expand Down Expand Up @@ -43,9 +44,9 @@ def from_args(args: Dict) -> "DeployData":
"""

# `from` isn't good for dict creation, but used from CLI, so handle both `from` and `from_addr`
from_addr = args.get("from", args.get("from_addr"))
if from_addr and not isinstance(from_addr, bytes):
from_addr = bytes.fromhex(from_addr)
from_addr = optional_base64_base16_to_bytes(
args.get("from", args.get("from_addr")), "from"
)

payment_code = PaymentCode.from_args(args)
session_code = SessionCode.from_args(args)
Expand Down
Loading

0 comments on commit 93797bf

Please sign in to comment.