mirror of https://github.com/nucypher/nucypher.git
Adapt nucypher to merged Operator, without Ritualist.
parent
48757c180f
commit
0f29569568
|
@ -89,13 +89,13 @@ class ActiveRitualTracker:
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
ritualist: "actors.Ritualist",
|
||||
operator: "actors.Operator",
|
||||
persistent: bool = False, # TODO: use persistent storage?
|
||||
):
|
||||
self.log = Logger("RitualTracker")
|
||||
|
||||
self.ritualist = ritualist
|
||||
self.coordinator_agent = ritualist.coordinator_agent
|
||||
self.operator = operator
|
||||
self.coordinator_agent = operator.coordinator_agent
|
||||
|
||||
# Restore/create persistent event scanner state
|
||||
self.persistent = persistent
|
||||
|
@ -104,8 +104,8 @@ class ActiveRitualTracker:
|
|||
|
||||
# Map events to handlers
|
||||
self.actions = {
|
||||
self.contract.events.StartRitual: self.ritualist.perform_round_1,
|
||||
self.contract.events.StartAggregationRound: self.ritualist.perform_round_2,
|
||||
self.contract.events.StartRitual: self.operator.perform_round_1,
|
||||
self.contract.events.StartAggregationRound: self.operator.perform_round_2,
|
||||
}
|
||||
|
||||
self.events = [
|
||||
|
@ -241,7 +241,7 @@ class ActiveRitualTracker:
|
|||
"""
|
||||
participants = self.coordinator_agent.get_participants(ritual_id=ritual_id)
|
||||
for p in participants:
|
||||
if p.provider == self.ritualist.checksum_address:
|
||||
if p.provider == self.operator.checksum_address:
|
||||
return p
|
||||
|
||||
return None
|
||||
|
@ -277,7 +277,7 @@ class ActiveRitualTracker:
|
|||
|
||||
def _get_participation_state(self, event: AttributeDict) -> ParticipationState:
|
||||
"""
|
||||
Returns the current participation state of the Ritualist as it pertains to
|
||||
Returns the current participation state of the Operator as it pertains to
|
||||
the ritual associated with the provided event.
|
||||
"""
|
||||
self._purge_expired_participation_states_as_needed()
|
||||
|
@ -304,7 +304,7 @@ class ActiveRitualTracker:
|
|||
# need to determine if participating in this ritual or not
|
||||
if event_type == self.contract.events.StartRitual:
|
||||
participation_state = self.ParticipationState(
|
||||
participating=(self.ritualist.checksum_address in args.participants)
|
||||
participating=(self.operator.checksum_address in args.participants)
|
||||
)
|
||||
self._participation_states[ritual_id] = participation_state
|
||||
return participation_state
|
||||
|
@ -429,5 +429,5 @@ class ActiveRitualTracker:
|
|||
|
||||
end_block = self.scanner.get_suggested_scan_end_block()
|
||||
self.__scan(
|
||||
suggested_start_block, end_block, self.ritualist.transacting_power.account
|
||||
suggested_start_block, end_block, self.operator.transacting_power.account
|
||||
)
|
||||
|
|
|
@ -52,11 +52,11 @@ class Vladimir(Ursula):
|
|||
cls.attach_transacting_key(blockchain=blockchain)
|
||||
|
||||
# Vladimir does not care about payment.
|
||||
bogus_payment_method = FreeReencryptions()
|
||||
bogus_payment_method.provider = Mock()
|
||||
bogus_payment_method.agent = Mock()
|
||||
bogus_payment_method.network = TEMPORARY_DOMAIN
|
||||
bogus_payment_method.agent.blockchain.client.chain_id = (
|
||||
bogus_pre_payment_method = FreeReencryptions()
|
||||
bogus_pre_payment_method.provider = Mock()
|
||||
bogus_pre_payment_method.agent = Mock()
|
||||
bogus_pre_payment_method.network = TEMPORARY_DOMAIN
|
||||
bogus_pre_payment_method.agent.blockchain.client.chain_id = (
|
||||
blockchain.client.chain_id
|
||||
)
|
||||
mock.patch(
|
||||
|
@ -64,7 +64,8 @@ class Vladimir(Ursula):
|
|||
new_callable=mock.PropertyMock(return_value=blockchain.client.chain_id),
|
||||
)
|
||||
|
||||
vladimir = cls(is_me=True,
|
||||
vladimir = cls(
|
||||
is_me=True,
|
||||
crypto_power=crypto_power,
|
||||
domain=TEMPORARY_DOMAIN,
|
||||
rest_host=target_ursula.rest_interface.host,
|
||||
|
@ -75,7 +76,7 @@ class Vladimir(Ursula):
|
|||
operator_address=cls.fraud_address,
|
||||
signer=Web3Signer(blockchain.client),
|
||||
eth_provider_uri=blockchain.eth_provider_uri,
|
||||
payment_method=bogus_payment_method,
|
||||
pre_payment_method=bogus_pre_payment_method,
|
||||
)
|
||||
|
||||
# Let's use the target's public info, and try to make some changes.
|
||||
|
|
|
@ -26,7 +26,7 @@ from nucypher.cli.literature import (
|
|||
DEVELOPMENT_MODE_WARNING,
|
||||
FORCE_MODE_WARNING,
|
||||
SELECT_OPERATOR_ACCOUNT,
|
||||
SELECT_PAYMENT_NETWORK,
|
||||
SELECT_PRE_PAYMENT_NETWORK,
|
||||
)
|
||||
from nucypher.cli.options import (
|
||||
group_options,
|
||||
|
@ -43,11 +43,11 @@ from nucypher.cli.options import (
|
|||
option_max_gas_price,
|
||||
option_min_stake,
|
||||
option_network,
|
||||
option_payment_method,
|
||||
option_payment_network,
|
||||
option_payment_provider,
|
||||
option_poa,
|
||||
option_policy_registry_filepath,
|
||||
option_pre_payment_method,
|
||||
option_pre_payment_network,
|
||||
option_pre_payment_provider,
|
||||
option_registry_filepath,
|
||||
option_signer_uri,
|
||||
option_teacher_uri,
|
||||
|
@ -89,9 +89,9 @@ class UrsulaConfigOptions:
|
|||
signer_uri: str,
|
||||
availability_check: bool,
|
||||
lonely: bool,
|
||||
payment_method: str,
|
||||
payment_provider: str,
|
||||
payment_network: str,
|
||||
pre_payment_method: str,
|
||||
pre_payment_provider: str,
|
||||
pre_payment_network: str,
|
||||
):
|
||||
|
||||
self.eth_provider_uri = eth_provider_uri
|
||||
|
@ -109,9 +109,9 @@ class UrsulaConfigOptions:
|
|||
self.max_gas_price = max_gas_price
|
||||
self.availability_check = availability_check
|
||||
self.lonely = lonely
|
||||
self.payment_method = payment_method
|
||||
self.payment_provider = payment_provider
|
||||
self.payment_network = payment_network
|
||||
self.pre_payment_method = pre_payment_method
|
||||
self.pre_payment_provider = pre_payment_provider
|
||||
self.pre_payment_network = pre_payment_network
|
||||
|
||||
def create_config(self, emitter, config_file):
|
||||
if self.dev:
|
||||
|
@ -131,9 +131,9 @@ class UrsulaConfigOptions:
|
|||
rest_host=self.rest_host,
|
||||
rest_port=self.rest_port,
|
||||
availability_check=self.availability_check,
|
||||
payment_method=self.payment_method,
|
||||
payment_provider=self.payment_provider,
|
||||
payment_network=self.payment_network,
|
||||
pre_payment_method=self.pre_payment_method,
|
||||
pre_payment_provider=self.pre_payment_provider,
|
||||
pre_payment_network=self.pre_payment_network,
|
||||
)
|
||||
else:
|
||||
if not config_file:
|
||||
|
@ -156,9 +156,9 @@ class UrsulaConfigOptions:
|
|||
poa=self.poa,
|
||||
light=self.light,
|
||||
availability_check=self.availability_check,
|
||||
payment_method=self.payment_method,
|
||||
payment_provider=self.payment_provider,
|
||||
payment_network=self.payment_network,
|
||||
pre_payment_method=self.pre_payment_method,
|
||||
pre_payment_provider=self.pre_payment_provider,
|
||||
pre_payment_network=self.pre_payment_network,
|
||||
)
|
||||
except FileNotFoundError:
|
||||
return handle_missing_configuration_file(character_config_class=UrsulaConfiguration, config_file=config_file)
|
||||
|
@ -209,9 +209,9 @@ class UrsulaConfigOptions:
|
|||
poa=self.poa,
|
||||
light=self.light,
|
||||
availability_check=self.availability_check,
|
||||
payment_method=self.payment_method,
|
||||
payment_provider=self.payment_provider,
|
||||
payment_network=self.payment_network,
|
||||
pre_payment_method=self.pre_payment_method,
|
||||
pre_payment_provider=self.pre_payment_provider,
|
||||
pre_payment_network=self.pre_payment_network,
|
||||
)
|
||||
|
||||
def get_updates(self) -> dict:
|
||||
|
@ -229,9 +229,9 @@ class UrsulaConfigOptions:
|
|||
poa=self.poa,
|
||||
light=self.light,
|
||||
availability_check=self.availability_check,
|
||||
payment_method=self.payment_method,
|
||||
payment_provider=self.payment_provider,
|
||||
payment_network=self.payment_network,
|
||||
pre_payment_method=self.pre_payment_method,
|
||||
pre_payment_provider=self.pre_payment_provider,
|
||||
pre_payment_network=self.pre_payment_network,
|
||||
)
|
||||
# Depends on defaults being set on Configuration classes, filtrates None values
|
||||
updates = {k: v for k, v in payload.items() if v is not None}
|
||||
|
@ -268,9 +268,9 @@ group_config_options = group_options(
|
|||
dev=option_dev,
|
||||
availability_check=click.option('--availability-check/--disable-availability-check', help="Enable or disable self-health checks while running", is_flag=True, default=None),
|
||||
lonely=option_lonely,
|
||||
payment_provider=option_payment_provider,
|
||||
payment_network=option_payment_network,
|
||||
payment_method=option_payment_method,
|
||||
pre_payment_provider=option_pre_payment_provider,
|
||||
pre_payment_network=option_pre_payment_network,
|
||||
pre_payment_method=option_pre_payment_method,
|
||||
)
|
||||
|
||||
|
||||
|
@ -347,11 +347,12 @@ def init(general_config, config_options, force, config_root, key_material):
|
|||
"--eth-provider is required to initialize a new ursula.", fg="red"
|
||||
),
|
||||
)
|
||||
if not config_options.payment_provider:
|
||||
if not config_options.pre_payment_provider:
|
||||
raise click.BadOptionUsage(
|
||||
"--payment-provider",
|
||||
"--pre-payment-provider",
|
||||
message=click.style(
|
||||
"--payment-provider is required to initialize a new ursula.", fg="red"
|
||||
"--pre-payment-provider is required to initialize a new ursula.",
|
||||
fg="red",
|
||||
),
|
||||
)
|
||||
if not config_options.domain:
|
||||
|
@ -360,10 +361,10 @@ def init(general_config, config_options, force, config_root, key_material):
|
|||
message="Select Staking Network",
|
||||
network_type=NetworksInventory.ETH,
|
||||
)
|
||||
if not config_options.payment_network:
|
||||
config_options.payment_network = select_network(
|
||||
if not config_options.pre_payment_network:
|
||||
config_options.pre_payment_network = select_network(
|
||||
emitter,
|
||||
message=SELECT_PAYMENT_NETWORK,
|
||||
message=SELECT_PRE_PAYMENT_NETWORK,
|
||||
network_type=NetworksInventory.POLYGON,
|
||||
)
|
||||
ursula_config = config_options.generate_config(
|
||||
|
|
|
@ -45,7 +45,7 @@ nucypher {init_command}
|
|||
|
||||
SELECT_NETWORK = "Select Network"
|
||||
|
||||
SELECT_PAYMENT_NETWORK = "Select Payment Network"
|
||||
SELECT_PRE_PAYMENT_NETWORK = "Select PRE Payment Network"
|
||||
|
||||
NO_CONFIGURATIONS_ON_DISK = "No {name} configurations found. Run 'nucypher {command} init' then try again."
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ from nucypher.cli.types import (
|
|||
GWEI,
|
||||
MIN_AUTHORIZATION,
|
||||
NETWORK_PORT,
|
||||
PAYMENT_METHOD_CHOICES,
|
||||
PRE_PAYMENT_METHOD_CHOICES,
|
||||
STAKED_TOKENS_RANGE,
|
||||
NuCypherNetworkName,
|
||||
)
|
||||
|
@ -20,32 +20,116 @@ from nucypher.utilities.logging import Logger
|
|||
|
||||
# Alphabetical
|
||||
|
||||
option_config_file = click.option('--config-file', help="Path to configuration file", type=EXISTING_READABLE_FILE)
|
||||
option_config_root = click.option('--config-root', help="Custom configuration directory", type=click.Path(path_type=Path))
|
||||
option_dev = click.option('--dev', '-d', help="Enable development mode", is_flag=True)
|
||||
option_dry_run = click.option('--dry-run', '-x', help="Execute normally without actually starting the node", is_flag=True)
|
||||
option_etherscan = click.option('--etherscan/--no-etherscan', help="Enable/disable viewing TX in Etherscan")
|
||||
option_event_name = click.option('--event-name', help="Specify an event by name", type=click.STRING)
|
||||
option_force = click.option('--force', help="Don't ask for confirmation", is_flag=True)
|
||||
option_gas_strategy = click.option('--gas-strategy', help="Operate with a specified gas price strategy", type=click.STRING) # TODO: GAS_STRATEGY_CHOICES
|
||||
option_key_material = click.option('--key-material', help="A pre-secured hex-encoded secret to use for private key derivations", type=click.STRING)
|
||||
option_max_gas_price = click.option('--max-gas-price', help="Maximum acceptable gas price (in GWEI)", type=GWEI)
|
||||
option_hw_wallet = click.option('--hw-wallet/--no-hw-wallet')
|
||||
option_light = click.option('--light', help="Indicate that node is light", is_flag=True, default=None)
|
||||
option_lonely = click.option('--lonely', help="Do not connect to seednodes", is_flag=True)
|
||||
option_min_stake = click.option('--min-stake', help="The minimum stake the teacher must have to be locally accepted.", type=STAKED_TOKENS_RANGE, default=MIN_AUTHORIZATION)
|
||||
option_operator_address = click.option('--operator-address', help="Address to bond as an operator", type=EIP55_CHECKSUM_ADDRESS, required=True)
|
||||
option_parameters = click.option('--parameters', help="Filepath to a JSON file containing additional parameters", type=EXISTING_READABLE_FILE)
|
||||
option_payment_provider = click.option('--payment-provider', 'payment_provider', help="Connection URL for payment method", type=click.STRING, required=False)
|
||||
option_payment_network = click.option('--payment-network', help="Payment network name", type=click.STRING, required=False) # TODO: Choices
|
||||
option_payment_method = click.option('--payment-method', help="Payment method name", type=PAYMENT_METHOD_CHOICES, required=False)
|
||||
option_poa = click.option('--poa/--disable-poa', help="Inject POA middleware", is_flag=True, default=None)
|
||||
option_registry_filepath = click.option('--registry-filepath', help="Custom contract registry filepath", type=EXISTING_READABLE_FILE)
|
||||
option_policy_registry_filepath = click.option('--policy-registry-filepath', help="Custom contract registry filepath for policies", type=EXISTING_READABLE_FILE)
|
||||
option_signer_uri = click.option('--signer', 'signer_uri', '-S', default=None, type=str)
|
||||
option_staking_provider = click.option('--staking-provider', help="Staking provider ethereum address", type=EIP55_CHECKSUM_ADDRESS, required=True)
|
||||
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)
|
||||
option_config_file = click.option(
|
||||
"--config-file", help="Path to configuration file", type=EXISTING_READABLE_FILE
|
||||
)
|
||||
option_config_root = click.option(
|
||||
"--config-root",
|
||||
help="Custom configuration directory",
|
||||
type=click.Path(path_type=Path),
|
||||
)
|
||||
option_dev = click.option("--dev", "-d", help="Enable development mode", is_flag=True)
|
||||
option_dry_run = click.option(
|
||||
"--dry-run",
|
||||
"-x",
|
||||
help="Execute normally without actually starting the node",
|
||||
is_flag=True,
|
||||
)
|
||||
option_etherscan = click.option(
|
||||
"--etherscan/--no-etherscan", help="Enable/disable viewing TX in Etherscan"
|
||||
)
|
||||
option_event_name = click.option(
|
||||
"--event-name", help="Specify an event by name", type=click.STRING
|
||||
)
|
||||
option_force = click.option("--force", help="Don't ask for confirmation", is_flag=True)
|
||||
option_gas_strategy = click.option(
|
||||
"--gas-strategy",
|
||||
help="Operate with a specified gas price strategy",
|
||||
type=click.STRING,
|
||||
) # TODO: GAS_STRATEGY_CHOICES
|
||||
option_key_material = click.option(
|
||||
"--key-material",
|
||||
help="A pre-secured hex-encoded secret to use for private key derivations",
|
||||
type=click.STRING,
|
||||
)
|
||||
option_max_gas_price = click.option(
|
||||
"--max-gas-price", help="Maximum acceptable gas price (in GWEI)", type=GWEI
|
||||
)
|
||||
option_hw_wallet = click.option("--hw-wallet/--no-hw-wallet")
|
||||
option_light = click.option(
|
||||
"--light", help="Indicate that node is light", is_flag=True, default=None
|
||||
)
|
||||
option_lonely = click.option(
|
||||
"--lonely", help="Do not connect to seednodes", is_flag=True
|
||||
)
|
||||
option_min_stake = click.option(
|
||||
"--min-stake",
|
||||
help="The minimum stake the teacher must have to be locally accepted.",
|
||||
type=STAKED_TOKENS_RANGE,
|
||||
default=MIN_AUTHORIZATION,
|
||||
)
|
||||
option_operator_address = click.option(
|
||||
"--operator-address",
|
||||
help="Address to bond as an operator",
|
||||
type=EIP55_CHECKSUM_ADDRESS,
|
||||
required=True,
|
||||
)
|
||||
option_parameters = click.option(
|
||||
"--parameters",
|
||||
help="Filepath to a JSON file containing additional parameters",
|
||||
type=EXISTING_READABLE_FILE,
|
||||
)
|
||||
option_pre_payment_provider = click.option(
|
||||
"--pre-payment-provider",
|
||||
"pre_payment_provider",
|
||||
help="Connection URL for PRE payment method",
|
||||
type=click.STRING,
|
||||
required=False,
|
||||
)
|
||||
option_pre_payment_network = click.option(
|
||||
"--pre-payment-network",
|
||||
help="PRE payment network name",
|
||||
type=click.STRING,
|
||||
required=False,
|
||||
) # TODO: Choices
|
||||
option_pre_payment_method = click.option(
|
||||
"--pre-payment-method",
|
||||
help="PRE payment method name",
|
||||
type=PRE_PAYMENT_METHOD_CHOICES,
|
||||
required=False,
|
||||
)
|
||||
option_poa = click.option(
|
||||
"--poa/--disable-poa", help="Inject POA middleware", is_flag=True, default=None
|
||||
)
|
||||
option_registry_filepath = click.option(
|
||||
"--registry-filepath",
|
||||
help="Custom contract registry filepath",
|
||||
type=EXISTING_READABLE_FILE,
|
||||
)
|
||||
option_policy_registry_filepath = click.option(
|
||||
"--policy-registry-filepath",
|
||||
help="Custom contract registry filepath for policies",
|
||||
type=EXISTING_READABLE_FILE,
|
||||
)
|
||||
option_signer_uri = click.option("--signer", "signer_uri", "-S", default=None, type=str)
|
||||
option_staking_provider = click.option(
|
||||
"--staking-provider",
|
||||
help="Staking provider ethereum address",
|
||||
type=EIP55_CHECKSUM_ADDRESS,
|
||||
required=True,
|
||||
)
|
||||
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,
|
||||
)
|
||||
|
||||
#
|
||||
# Alphabetical
|
||||
|
|
|
@ -13,7 +13,7 @@ from nucypher_core.umbral import PublicKey
|
|||
from nucypher.blockchain.economics import Economics
|
||||
from nucypher.blockchain.eth.networks import NetworksInventory
|
||||
from nucypher.blockchain.eth.token import TToken
|
||||
from nucypher.policy.payment import PAYMENT_METHODS
|
||||
from nucypher.policy.payment import PRE_PAYMENT_METHODS
|
||||
from nucypher.utilities.networking import InvalidOperatorIP, validate_operator_ip
|
||||
|
||||
|
||||
|
@ -141,4 +141,4 @@ NETWORK_PORT = click.IntRange(min=0, max=65535, clamp=False)
|
|||
IPV4_ADDRESS = IPv4Address()
|
||||
OPERATOR_IP = OperatorIPAddress()
|
||||
|
||||
PAYMENT_METHOD_CHOICES = click.Choice(list(PAYMENT_METHODS))
|
||||
PRE_PAYMENT_METHOD_CHOICES = click.Choice(list(PRE_PAYMENT_METHODS))
|
||||
|
|
|
@ -35,7 +35,7 @@ from nucypher.config.util import cast_paths_from
|
|||
from nucypher.crypto.keystore import Keystore
|
||||
from nucypher.crypto.powers import CryptoPower, CryptoPowerUp
|
||||
from nucypher.network.middleware import RestMiddleware
|
||||
from nucypher.policy.payment import PAYMENT_METHODS
|
||||
from nucypher.policy.payment import PRE_PAYMENT_METHODS
|
||||
from nucypher.utilities.logging import Logger
|
||||
|
||||
|
||||
|
@ -321,8 +321,8 @@ class CharacterConfiguration(BaseConfiguration):
|
|||
DEFAULT_GAS_STRATEGY = 'fast'
|
||||
|
||||
# Payments
|
||||
DEFAULT_PAYMENT_METHOD = 'SubscriptionManager'
|
||||
DEFAULT_PAYMENT_NETWORK = 'polygon'
|
||||
DEFAULT_PRE_PAYMENT_METHOD = "SubscriptionManager"
|
||||
DEFAULT_PRE_PAYMENT_NETWORK = "polygon"
|
||||
|
||||
# Fields specified here are *not* passed into the Character's constructor
|
||||
# and can be understood as configuration fields only.
|
||||
|
@ -335,8 +335,8 @@ class CharacterConfiguration(BaseConfiguration):
|
|||
"max_gas_price", # gwei
|
||||
"signer_uri",
|
||||
"keystore_path",
|
||||
"payment_provider",
|
||||
"payment_network",
|
||||
"pre_payment_provider",
|
||||
"pre_payment_network",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
|
@ -375,9 +375,9 @@ class CharacterConfiguration(BaseConfiguration):
|
|||
signer_uri: Optional[str] = None,
|
||||
# Payments
|
||||
# TODO: Resolve code prefixing below, possibly with the use of nested configuration fields
|
||||
payment_method: Optional[str] = None,
|
||||
payment_provider: Optional[str] = None,
|
||||
payment_network: Optional[str] = None,
|
||||
pre_payment_method: Optional[str] = None,
|
||||
pre_payment_provider: Optional[str] = None,
|
||||
pre_payment_network: Optional[str] = None,
|
||||
# Registries
|
||||
registry: Optional[BaseContractRegistry] = None,
|
||||
registry_filepath: Optional[Path] = None,
|
||||
|
@ -463,7 +463,7 @@ class CharacterConfiguration(BaseConfiguration):
|
|||
# TODO: this is potential fix for multichain connection, if we want to use it build it out into a loop
|
||||
# for uri in eth_provider_uri (list of uris fom config):
|
||||
BlockchainInterfaceFactory.get_or_create_interface(
|
||||
eth_provider_uri=payment_provider,
|
||||
eth_provider_uri=pre_payment_provider,
|
||||
poa=self.poa,
|
||||
light=self.is_light,
|
||||
emitter=emitter,
|
||||
|
@ -495,11 +495,15 @@ class CharacterConfiguration(BaseConfiguration):
|
|||
from nucypher.config.characters import BobConfiguration
|
||||
|
||||
if not isinstance(self, BobConfiguration):
|
||||
# if not payment_provider:
|
||||
# if not pre_payment_provider:
|
||||
# raise self.ConfigurationError("payment provider is required.")
|
||||
self.payment_method = payment_method or self.DEFAULT_PAYMENT_METHOD
|
||||
self.payment_network = payment_network or self.DEFAULT_PAYMENT_NETWORK
|
||||
self.payment_provider = payment_provider or (
|
||||
self.pre_payment_method = (
|
||||
pre_payment_method or self.DEFAULT_PRE_PAYMENT_METHOD
|
||||
)
|
||||
self.pre_payment_network = (
|
||||
pre_payment_network or self.DEFAULT_PRE_PAYMENT_NETWORK
|
||||
)
|
||||
self.pre_payment_provider = pre_payment_provider or (
|
||||
self.eth_provider_uri or None
|
||||
) # default to L1 payments
|
||||
|
||||
|
@ -509,7 +513,7 @@ class CharacterConfiguration(BaseConfiguration):
|
|||
self.log.info("Fetching latest policy registry from source.")
|
||||
self.policy_registry = (
|
||||
InMemoryContractRegistry.from_latest_publication(
|
||||
network=self.payment_network
|
||||
network=self.pre_payment_network
|
||||
)
|
||||
)
|
||||
else:
|
||||
|
@ -834,16 +838,16 @@ class CharacterConfiguration(BaseConfiguration):
|
|||
node_storage = storage_class.from_payload(payload=storage_payload)
|
||||
return node_storage
|
||||
|
||||
def configure_payment_method(self):
|
||||
def configure_pre_payment_method(self):
|
||||
# TODO: finalize config fields
|
||||
#
|
||||
# Strategy-Based (current implementation, inflexible & hardcoded)
|
||||
# 'payment_strategy': 'SubscriptionManager'
|
||||
# 'payment_network': 'matic'
|
||||
# 'payment_provider': 'https:///matic.infura.io....'
|
||||
# 'pre_payment_strategy': 'SubscriptionManager'
|
||||
# 'pre_payment_network': 'matic'
|
||||
# 'pre_payment_provider': 'https:///matic.infura.io....'
|
||||
#
|
||||
# Contract-Targeted (alternative implementation, flexible & generic)
|
||||
# 'payment': {
|
||||
# 'pre_payment': {
|
||||
# 'contract': '0xdeadbeef'
|
||||
# 'abi': '/home/abi/sm.json'
|
||||
# 'function': 'isPolicyActive'
|
||||
|
@ -852,15 +856,17 @@ class CharacterConfiguration(BaseConfiguration):
|
|||
#
|
||||
|
||||
try:
|
||||
payment_class = PAYMENT_METHODS[self.payment_method]
|
||||
pre_payment_class = PRE_PAYMENT_METHODS[self.pre_payment_method]
|
||||
except KeyError:
|
||||
raise KeyError(f'Unknown payment method "{self.payment_method}"')
|
||||
raise KeyError(f'Unknown PRE payment method "{self.pre_payment_method}"')
|
||||
|
||||
if payment_class.ONCHAIN:
|
||||
if pre_payment_class.ONCHAIN:
|
||||
# on-chain payment strategies require a blockchain connection
|
||||
payment_strategy = payment_class(network=self.payment_network,
|
||||
eth_provider=self.payment_provider,
|
||||
registry=self.policy_registry)
|
||||
pre_payment_strategy = pre_payment_class(
|
||||
network=self.pre_payment_network,
|
||||
eth_provider=self.pre_payment_provider,
|
||||
registry=self.policy_registry,
|
||||
)
|
||||
else:
|
||||
payment_strategy = payment_class()
|
||||
return payment_strategy
|
||||
pre_payment_strategy = pre_payment_class()
|
||||
return pre_payment_strategy
|
||||
|
|
|
@ -72,8 +72,10 @@ class UrsulaConfiguration(CharacterConfiguration):
|
|||
"""Configure default condition provider URIs for mainnet and polygon network."""
|
||||
|
||||
# Polygon
|
||||
polygon_chain_id = NetworksInventory.get_polygon_chain_id(self.payment_network)
|
||||
self.condition_provider_uris[polygon_chain_id] = [self.payment_provider]
|
||||
polygon_chain_id = NetworksInventory.get_polygon_chain_id(
|
||||
self.pre_payment_network
|
||||
)
|
||||
self.condition_provider_uris[polygon_chain_id] = [self.pre_payment_provider]
|
||||
|
||||
# Ethereum
|
||||
staking_chain_id = NetworksInventory.get_ethereum_chain_id(self.domain)
|
||||
|
@ -107,9 +109,9 @@ class UrsulaConfiguration(CharacterConfiguration):
|
|||
|
||||
# PRE Payments
|
||||
# TODO: Resolve variable prefixing below (uses nested configuration fields?)
|
||||
payment_method=self.payment_method,
|
||||
payment_provider=self.payment_provider,
|
||||
payment_network=self.payment_network,
|
||||
pre_payment_method=self.pre_payment_method,
|
||||
pre_payment_provider=self.pre_payment_provider,
|
||||
pre_payment_network=self.pre_payment_network,
|
||||
)
|
||||
return {**super().static_payload(), **payload}
|
||||
|
||||
|
@ -118,7 +120,7 @@ class UrsulaConfiguration(CharacterConfiguration):
|
|||
payload = dict(
|
||||
network_middleware=self.network_middleware,
|
||||
certificate=self.certificate,
|
||||
payment_method=self.configure_payment_method()
|
||||
pre_payment_method=self.configure_pre_payment_method(),
|
||||
)
|
||||
return {**super().dynamic_payload, **payload}
|
||||
|
||||
|
@ -170,9 +172,9 @@ class AliceConfiguration(CharacterConfiguration):
|
|||
payload = dict(
|
||||
threshold=self.threshold,
|
||||
shares=self.shares,
|
||||
payment_network=self.payment_network,
|
||||
payment_provider=self.payment_provider,
|
||||
payment_method=self.payment_method,
|
||||
pre_payment_network=self.pre_payment_network,
|
||||
pre_payment_provider=self.pre_payment_provider,
|
||||
pre_payment_method=self.pre_payment_method,
|
||||
rate=self.rate,
|
||||
duration=self.duration,
|
||||
)
|
||||
|
@ -180,7 +182,7 @@ class AliceConfiguration(CharacterConfiguration):
|
|||
|
||||
@property
|
||||
def dynamic_payload(self) -> dict:
|
||||
payload = dict(payment_method=self.configure_payment_method())
|
||||
payload = dict(pre_payment_method=self.configure_pre_payment_method())
|
||||
return {**super().dynamic_payload, **payload}
|
||||
|
||||
|
||||
|
|
|
@ -7,8 +7,20 @@ from nucypher.config.migrations.common import perform_migration
|
|||
def __migration(config: Dict) -> Dict:
|
||||
eth_provider = config["eth_provider_uri"]
|
||||
eth_chain_id = NetworksInventory.get_ethereum_chain_id(config["domain"])
|
||||
|
||||
polygon_provider = config["payment_provider"]
|
||||
polygon_chain_id = NetworksInventory.get_polygon_chain_id(config["payment_network"])
|
||||
del config["payment_provider"]
|
||||
config["pre_payment_provider"] = polygon_provider
|
||||
|
||||
pre_payment_network = config["payment_network"]
|
||||
del config["payment_network"]
|
||||
config["pre_payment_network"] = pre_payment_network
|
||||
|
||||
pre_payment_method = config["pre_payment_method"]
|
||||
del config["pre_payment_method"]
|
||||
config["pre_payment_method"] = pre_payment_method
|
||||
|
||||
polygon_chain_id = NetworksInventory.get_polygon_chain_id(pre_payment_network)
|
||||
if "condition_provider_uris" in config:
|
||||
return config
|
||||
config["condition_provider_uris"] = {
|
||||
|
|
|
@ -8,13 +8,27 @@ def __migration(config: Dict) -> Dict:
|
|||
eth_provider = config["eth_provider_uri"]
|
||||
eth_chain_id = NetworksInventory.get_ethereum_chain_id(config["domain"])
|
||||
polygon_provider = config["payment_provider"]
|
||||
del config["payment_provider"]
|
||||
|
||||
polygon_chain_id = NetworksInventory.get_polygon_chain_id(config["payment_network"])
|
||||
|
||||
if "condition_provider_uris" in config:
|
||||
return config
|
||||
config["condition_provider_uris"] = {
|
||||
eth_chain_id: [eth_provider],
|
||||
polygon_chain_id: [polygon_provider],
|
||||
}
|
||||
|
||||
config["pre_payment_provider"] = polygon_provider
|
||||
|
||||
pre_payment_network = config["payment_network"]
|
||||
del config["payment_network"]
|
||||
config["pre_payment_network"] = pre_payment_network
|
||||
|
||||
pre_payment_method = config["pre_payment_method"]
|
||||
del config["pre_payment_method"]
|
||||
config["pre_payment_method"] = pre_payment_method
|
||||
|
||||
return config
|
||||
|
||||
|
||||
|
|
|
@ -304,7 +304,9 @@ def _make_rest_app(this_node, log: Logger) -> Flask:
|
|||
return Response(message, status=HTTPStatus.BAD_REQUEST)
|
||||
|
||||
# Enforce Subscription Manager Payment
|
||||
paid = this_node.payment_method.verify(payee=this_node.checksum_address, request=reenc_request)
|
||||
paid = this_node.pre_payment_method.verify(
|
||||
payee=this_node.checksum_address, request=reenc_request
|
||||
)
|
||||
if not paid:
|
||||
message = f"{bob_identity_message} Policy {bytes(hrac)} is unpaid."
|
||||
return Response(message, status=HTTPStatus.PAYMENT_REQUIRED)
|
||||
|
|
|
@ -32,7 +32,7 @@ class PaymentMethod(ABC):
|
|||
@property
|
||||
@abstractmethod
|
||||
def rate(self) -> int:
|
||||
"""The cost of this payment method per unit."""
|
||||
"""The cost of this PRE payment method per unit."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
|
@ -44,7 +44,7 @@ class PaymentMethod(ABC):
|
|||
value: Optional[int] = None,
|
||||
rate: Optional[int] = None
|
||||
) -> Quote:
|
||||
"""Generates a valid quote for this payment method using pricing details."""
|
||||
"""Generates a valid quote for this PRE payment method using pricing details."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
|
@ -204,7 +204,7 @@ class FreeReencryptions(PaymentMethod):
|
|||
return True
|
||||
|
||||
|
||||
PAYMENT_METHODS = {
|
||||
PRE_PAYMENT_METHODS = {
|
||||
SubscriptionManagerPayment.NAME: SubscriptionManagerPayment,
|
||||
FreeReencryptions.NAME: FreeReencryptions
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class Policy:
|
|||
value: int,
|
||||
rate: int,
|
||||
duration: int,
|
||||
payment_method: "payment.PaymentMethod",
|
||||
pre_payment_method: "payment.PaymentMethod",
|
||||
):
|
||||
self.threshold = threshold
|
||||
self.shares = len(kfrags)
|
||||
|
@ -63,8 +63,10 @@ class Policy:
|
|||
self.hrac = HRAC(publisher_verifying_key=self.publisher.stamp.as_umbral_pubkey(),
|
||||
bob_verifying_key=self.bob.stamp.as_umbral_pubkey(),
|
||||
label=self.label)
|
||||
self.payment_method = payment_method
|
||||
self.payment_method.validate_price(shares=self.shares, value=value, duration=duration)
|
||||
self.pre_payment_method = pre_payment_method
|
||||
self.pre_payment_method.validate_price(
|
||||
shares=self.shares, value=value, duration=duration
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.__class__.__name__}:{bytes(self.hrac).hex()[:6]}"
|
||||
|
@ -79,7 +81,7 @@ class Policy:
|
|||
|
||||
def _publish(self, ursulas: List["characters.lawful.Ursula"]) -> Dict:
|
||||
self.nodes = [ursula.checksum_address for ursula in ursulas]
|
||||
receipt = self.payment_method.pay(policy=self)
|
||||
receipt = self.pre_payment_method.pay(policy=self)
|
||||
return receipt
|
||||
|
||||
def _ping_node(
|
||||
|
|
Loading…
Reference in New Issue