mirror of https://github.com/nucypher/nucypher.git
Accomodate the usage of --rate for granting via LCI specs; Post rebase cleanup.
parent
fcb9763959
commit
a3ee748555
|
@ -1,7 +1,8 @@
|
|||
import click
|
||||
from nucypher.cli import common_options, types
|
||||
|
||||
from nucypher.characters.control.specifications import fields
|
||||
from nucypher.characters.control.specifications.base import BaseSchema
|
||||
from nucypher.cli import options, types
|
||||
|
||||
|
||||
class PolicyBaseSchema(BaseSchema):
|
||||
|
@ -19,10 +20,10 @@ class PolicyBaseSchema(BaseSchema):
|
|||
'--bob-verifying-key', help="Bob's verifying key as a hexadecimal string"))
|
||||
m = fields.M(
|
||||
required=True, load_only=True,
|
||||
click=common_options.option_m)
|
||||
click=options.option_m)
|
||||
n = fields.N(
|
||||
required=True, load_only=True,
|
||||
click=common_options.option_n)
|
||||
click=options.option_n)
|
||||
expiration = fields.DateTime(
|
||||
required=True, load_only=True,
|
||||
click=click.option(
|
||||
|
@ -43,14 +44,20 @@ class CreatePolicy(PolicyBaseSchema):
|
|||
|
||||
label = fields.Label(
|
||||
required=True,
|
||||
click=common_options.option_label(required=True))
|
||||
click=options.option_label(required=True))
|
||||
|
||||
|
||||
class GrantPolicy(PolicyBaseSchema):
|
||||
|
||||
label = fields.Label(
|
||||
load_only=True, required=True,
|
||||
click=common_options.option_label(required=True))
|
||||
click=options.option_label(required=True))
|
||||
|
||||
rate = fields.Integer(
|
||||
load_only=True,
|
||||
required=False,
|
||||
click=options.option_rate
|
||||
)
|
||||
|
||||
# output fields
|
||||
treasure_map = fields.TreasureMap(dump_only=True)
|
||||
|
@ -61,7 +68,7 @@ class DerivePolicyEncryptionKey(BaseSchema):
|
|||
|
||||
label = fields.Label(
|
||||
required=True,
|
||||
click=common_options.option_label(required=True))
|
||||
click=options.option_label(required=True))
|
||||
|
||||
# output
|
||||
policy_encrypting_key = fields.Key(dump_only=True)
|
||||
|
@ -71,7 +78,7 @@ class Revoke(BaseSchema):
|
|||
|
||||
label = fields.Label(
|
||||
required=True, load_only=True,
|
||||
click=common_options.option_label(required=True))
|
||||
click=options.option_label(required=True))
|
||||
bob_verifying_key = fields.Key(
|
||||
required=True, load_only=True,
|
||||
click=click.option(
|
||||
|
@ -86,10 +93,10 @@ class Revoke(BaseSchema):
|
|||
class Decrypt(BaseSchema):
|
||||
label = fields.Label(
|
||||
required=True, load_only=True,
|
||||
click=common_options.option_label(required=True))
|
||||
click=options.option_label(required=True))
|
||||
message_kit = fields.UmbralMessageKit(
|
||||
load_only=True,
|
||||
click=common_options.option_message_kit(required=True))
|
||||
click=options.option_message_kit(required=True))
|
||||
|
||||
# output
|
||||
cleartexts = fields.List(fields.Cleartext(), dump_only=True)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import click
|
||||
from nucypher.cli import common_options
|
||||
from nucypher.cli import options
|
||||
from nucypher.characters.control.specifications import fields
|
||||
from nucypher.characters.control.specifications.base import BaseSchema
|
||||
|
||||
|
@ -8,7 +8,7 @@ class JoinPolicy(BaseSchema): #TODO: this doesn't have a cli implementation
|
|||
|
||||
label = fields.Label(
|
||||
load_only=True, required=True,
|
||||
click=common_options.option_label(required=True))
|
||||
click=options.option_label(required=True))
|
||||
alice_verifying_key = fields.Key(
|
||||
load_only=True, required=True,
|
||||
click=click.option(
|
||||
|
@ -24,11 +24,11 @@ class JoinPolicy(BaseSchema): #TODO: this doesn't have a cli implementation
|
|||
class Retrieve(BaseSchema):
|
||||
label = fields.Label(
|
||||
required=True, load_only=True,
|
||||
click=common_options.option_label(required=True))
|
||||
click=options.option_label(required=True))
|
||||
policy_encrypting_key = fields.Key(
|
||||
required=True,
|
||||
load_only=True,
|
||||
click=common_options.option_policy_encrypting_key(required=True))
|
||||
click=options.option_policy_encrypting_key(required=True))
|
||||
alice_verifying_key = fields.Key(
|
||||
required=True, load_only=True,
|
||||
click=click.option(
|
||||
|
@ -38,7 +38,7 @@ class Retrieve(BaseSchema):
|
|||
required=True))
|
||||
message_kit = fields.UmbralMessageKit(
|
||||
required=True, load_only=True,
|
||||
click=common_options.option_message_kit(required=True))
|
||||
click=options.option_message_kit(required=True))
|
||||
|
||||
cleartexts = fields.List(fields.Cleartext(), dump_only=True)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import click
|
||||
from nucypher.cli import common_options
|
||||
from nucypher.cli import options
|
||||
from nucypher.characters.control.specifications import fields
|
||||
from nucypher.characters.control.specifications.base import BaseSchema
|
||||
|
||||
|
@ -15,7 +15,7 @@ class EncryptMessage(BaseSchema):
|
|||
policy_encrypting_key = fields.Key(
|
||||
required=False,
|
||||
load_only=True,
|
||||
click=common_options.option_policy_encrypting_key())
|
||||
click=options.option_policy_encrypting_key())
|
||||
|
||||
# output
|
||||
message_kit = fields.UmbralMessageKit(dump_only=True)
|
||||
|
|
|
@ -38,10 +38,8 @@ from nucypher.cli.options import (
|
|||
option_force,
|
||||
option_geth,
|
||||
option_hw_wallet,
|
||||
option_label,
|
||||
option_light,
|
||||
option_m,
|
||||
option_message_kit,
|
||||
option_middleware,
|
||||
option_min_stake,
|
||||
option_n,
|
||||
|
@ -50,7 +48,7 @@ from nucypher.cli.options import (
|
|||
option_provider_uri,
|
||||
option_registry_filepath,
|
||||
option_teacher_uri,
|
||||
)
|
||||
option_rate)
|
||||
from nucypher.cli.types import EIP55_CHECKSUM_ADDRESS
|
||||
from nucypher.config.characters import AliceConfiguration
|
||||
from nucypher.config.constants import NUCYPHER_ENVVAR_ALICE_ETH_PASSWORD
|
||||
|
@ -65,7 +63,6 @@ option_bob_verifying_key = click.option(
|
|||
)
|
||||
|
||||
option_pay_with = click.option('--pay-with', help="Run with a specified account", type=EIP55_CHECKSUM_ADDRESS)
|
||||
option_rate = click.option('--rate', help="Policy rate per period (in wei)", type=types.WEI) # TODO: Is wei a sane unit here? Perhaps gwei?
|
||||
|
||||
|
||||
class AliceConfigOptions:
|
||||
|
@ -387,7 +384,7 @@ def grant(general_config,
|
|||
if any((value, rate)):
|
||||
raise click.BadOptionUsage(option_name="--value, --rate",
|
||||
message="Can't use --value or --rate with a federated Alice.")
|
||||
elif not (bool(value) ^ bool(rate)):
|
||||
if bool(value) and bool(rate):
|
||||
raise click.BadOptionUsage(option_name="--rate", message="Can't use --value if using --rate")
|
||||
|
||||
# Request
|
||||
|
@ -399,9 +396,11 @@ def grant(general_config,
|
|||
'n': n,
|
||||
'expiration': expiration,
|
||||
}
|
||||
|
||||
if not ALICE.federated_only:
|
||||
grant_request.update({'value': value, 'rate': rate})
|
||||
if value:
|
||||
grant_request['value'] = value
|
||||
elif rate:
|
||||
grant_request['rate'] = rate
|
||||
return ALICE.controller.grant(request=grant_request)
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ from nucypher.cli.types import (
|
|||
EIP55_CHECKSUM_ADDRESS,
|
||||
EXISTING_READABLE_FILE,
|
||||
NETWORK_PORT,
|
||||
)
|
||||
WEI)
|
||||
|
||||
|
||||
# Alphabetical
|
||||
|
@ -51,6 +51,9 @@ option_staking_address = click.option('--staking-address', help="Address of a Nu
|
|||
option_teacher_uri = click.option('--teacher', 'teacher_uri', help="An Ursula URI to start learning from (seednode)", type=click.STRING)
|
||||
_option_middleware = click.option('-Z', '--mock-networking', help="Use in-memory transport instead of networking", count=True)
|
||||
|
||||
# Avoid circular input
|
||||
option_rate = click.option('--rate', help="Policy rate per period (in wei)", type=WEI) # TODO: Is wei a sane unit here? Perhaps gwei?
|
||||
|
||||
|
||||
#
|
||||
# Alphabetical
|
||||
|
|
|
@ -329,7 +329,8 @@ def _cli_lifecycle(click_runner,
|
|||
if federated:
|
||||
grant_args += ('--federated-only',)
|
||||
else:
|
||||
grant_args += ('--provider', TEST_PROVIDER_URI, '--value', Web3.toWei(9, 'ether'))
|
||||
grant_args += ('--provider', TEST_PROVIDER_URI,
|
||||
'--value', Web3.toWei(9, 'ether'))
|
||||
|
||||
grant_result = click_runner.invoke(nucypher_cli, grant_args, catch_exceptions=False, env=envvars)
|
||||
assert grant_result.exit_code == 0
|
||||
|
|
Loading…
Reference in New Issue