Rename provider_uri parameter for ContractAgents.get_agent to blockchain_endpoint.

pull/3262/head
derekpierre 2023-10-02 14:02:29 -04:00
parent 941b21f34f
commit eafe4b65a9
21 changed files with 59 additions and 49 deletions

View File

@ -35,7 +35,7 @@ registry = ContractRegistry.from_latest_publication(
)
coordinator_agent = CoordinatorAgent(
provider_uri=polygon_endpoint,
blockchain_endpoint=polygon_endpoint,
registry=registry,
)
ritual_id = 1 # got this from a side channel

View File

@ -35,7 +35,7 @@ registry = ContractRegistry.from_latest_publication(
)
coordinator_agent = CoordinatorAgent(
provider_uri=polygon_endpoint,
blockchain_endpoint=polygon_endpoint,
registry=registry,
)
ritual_id = 1 # got this from a side channel

View File

@ -138,7 +138,7 @@ class NucypherTokenActor(BaseActor):
return self.__token_agent
self.__token_agent = ContractAgency.get_agent(
NucypherTokenAgent,
provider_uri=self.eth_provider_uri,
blockchain_endpoint=self.eth_provider_uri,
registry=self.registry,
)
return self.__token_agent
@ -205,7 +205,7 @@ class Operator(BaseActor):
self.application_agent = ContractAgency.get_agent(
TACoApplicationAgent,
provider_uri=eth_endpoint,
blockchain_endpoint=eth_endpoint,
registry=self.registry,
)
@ -216,13 +216,13 @@ class Operator(BaseActor):
self.child_application_agent = ContractAgency.get_agent(
TACoChildApplicationAgent,
registry=registry,
provider_uri=polygon_endpoint,
blockchain_endpoint=polygon_endpoint,
)
self.coordinator_agent = ContractAgency.get_agent(
CoordinatorAgent,
registry=registry,
provider_uri=polygon_endpoint,
blockchain_endpoint=polygon_endpoint,
)
# track active onchain rituals
@ -746,7 +746,9 @@ class PolicyAuthor(NucypherTokenActor):
def __init__(self, eth_endpoint: str, *args, **kwargs):
super().__init__(*args, **kwargs)
self.application_agent = ContractAgency.get_agent(
TACoApplicationAgent, registry=self.registry, provider_uri=eth_endpoint
TACoApplicationAgent,
registry=self.registry,
blockchain_endpoint=eth_endpoint,
)
def create_policy(self, *args, **kwargs):

View File

@ -81,7 +81,7 @@ class EthereumContractAgent:
def __init__(
self,
provider_uri: str,
blockchain_endpoint: str,
registry: ContractRegistry,
contract: Optional[Contract] = None,
transaction_gas: Optional[Wei] = None,
@ -91,7 +91,7 @@ class EthereumContractAgent:
self.registry = registry
self.blockchain = BlockchainInterfaceFactory.get_or_create_interface(
blockchain_endpoint=provider_uri
blockchain_endpoint=blockchain_endpoint
)
if not contract: # Fetch the contract
@ -847,13 +847,13 @@ class ContractAgency:
cls,
agent_class: Type[types.Agent],
registry: Optional[ContractRegistry],
provider_uri: Optional[str],
blockchain_endpoint: Optional[str],
contract_version: Optional[str] = None,
) -> types.Agent:
if not issubclass(agent_class, EthereumContractAgent):
raise TypeError("Only agent subclasses can be used from the agency.")
if not provider_uri:
if not blockchain_endpoint:
raise ValueError(
"Need to specify a blockchain provider URI in order to get an agent from the ContractAgency"
)
@ -871,7 +871,7 @@ class ContractAgency:
types.Agent,
agent_class(
registry=registry,
provider_uri=provider_uri,
blockchain_endpoint=blockchain_endpoint,
),
)
cls.__agents[registry_id] = cls.__agents.get(registry_id, dict())
@ -900,7 +900,7 @@ class ContractAgency:
agent: EthereumContractAgent = cls.get_agent(
agent_class=agent_class,
registry=registry,
provider_uri=provider_uri,
blockchain_endpoint=provider_uri,
contract_version=contract_version
)
return agent

View File

@ -20,7 +20,7 @@ class OperatorBondedTracker(SimpleTask):
application_agent = ContractAgency.get_agent(
TACoApplicationAgent,
registry=self._ursula.registry,
provider_uri=self._ursula.eth_endpoint,
blockchain_endpoint=self._ursula.eth_endpoint,
)
# use TACo root since unbonding happens at root and not child (more immediate this way)
staking_provider_address = application_agent.get_staking_provider_from_operator(

View File

@ -478,7 +478,7 @@ class Bob(Character):
if polygon_endpoint:
coordinator_agent = ContractAgency.get_agent(
CoordinatorAgent,
provider_uri=polygon_endpoint,
blockchain_endpoint=polygon_endpoint,
registry=ContractRegistry.from_latest_publication(
domain=self.domain,
),
@ -1182,7 +1182,7 @@ class Ursula(Teacher, Character, Operator):
return cls.from_seed_and_stake_info(seed_uri=seed_uri, *args, **kwargs)
@classmethod
def seednode_for_network(cls, network: str, provider_uri: str) -> "Ursula":
def seednode_for_network(cls, network: str, eth_endpoint: str) -> "Ursula":
"""Returns a default seednode ursula for a given network."""
try:
url = TEACHER_NODES[network][0]
@ -1190,7 +1190,7 @@ class Ursula(Teacher, Character, Operator):
raise ValueError(f'"{network}" is not a known network.')
except IndexError:
raise ValueError(f'No default seednodes available for "{network}".')
ursula = cls.from_seed_and_stake_info(seed_uri=url, provider_uri=provider_uri)
ursula = cls.from_seed_and_stake_info(seed_uri=url, eth_endpoint=eth_endpoint)
return ursula
@classmethod
@ -1213,7 +1213,7 @@ class Ursula(Teacher, Character, Operator):
try:
teacher = cls.from_seed_and_stake_info(
seed_uri=teacher_uri,
provider_uri=provider_uri,
eth_endpoint=provider_uri,
minimum_stake=min_stake,
network_middleware=network_middleware,
registry=registry,
@ -1237,14 +1237,14 @@ class Ursula(Teacher, Character, Operator):
def from_seed_and_stake_info(
cls,
seed_uri: str,
provider_uri: str,
eth_endpoint: str,
registry: ContractRegistry = None,
minimum_stake: int = 0,
network_middleware: RestMiddleware = None,
) -> Union["Ursula", "NodeSprout"]:
if network_middleware is None:
network_middleware = RestMiddleware(
registry=registry, eth_endpoint=provider_uri
registry=registry, eth_endpoint=eth_endpoint
)
# Parse node URI
@ -1273,7 +1273,9 @@ class Ursula(Teacher, Character, Operator):
# Check the node's stake (optional)
if minimum_stake > 0 and staking_provider_address:
application_agent = ContractAgency.get_agent(
TACoApplicationAgent, provider_uri=provider_uri, registry=registry
TACoApplicationAgent,
blockchain_endpoint=eth_endpoint,
registry=registry,
)
seednode_stake = application_agent.get_authorized_stake(
staking_provider=staking_provider_address

View File

@ -134,7 +134,7 @@ def active_providers(general_config, registry_options):
general_config=general_config
)
application_agent = ContractAgency.get_agent(
TACoApplicationAgent, registry=registry, provider_uri=provider_uri
TACoApplicationAgent, registry=registry, blockchain_endpoint=provider_uri
)
(
total_staked,

View File

@ -6,7 +6,7 @@ from nucypher.blockchain.eth.agents import (
def paint_application_contract_status(emitter, registry, provider_uri):
application_agent = ContractAgency.get_agent(
TACoApplicationAgent, registry=registry, provider_uri=provider_uri
TACoApplicationAgent, registry=registry, blockchain_endpoint=provider_uri
)
blockchain = application_agent.blockchain

View File

@ -1049,7 +1049,7 @@ class Teacher:
the case that the "staking provider" isn't "staking" (e.g., all her tokens have been slashed).
"""
application_agent = ContractAgency.get_agent(
TACoApplicationAgent, provider_uri=provider_uri, registry=registry
TACoApplicationAgent, blockchain_endpoint=provider_uri, registry=registry
) # type: TACoApplicationAgent
staking_provider_address = application_agent.get_staking_provider_from_operator(operator_address=self.operator_address)
if staking_provider_address == NULL_ADDRESS:
@ -1064,7 +1064,7 @@ class Teacher:
As a follow-up, this checks that the staking provider is, indeed, staking.
"""
application_agent = ContractAgency.get_agent(
TACoApplicationAgent, registry=registry, provider_uri=eth_endpoint
TACoApplicationAgent, registry=registry, blockchain_endpoint=eth_endpoint
) # type: TACoApplicationAgent
is_staking = application_agent.is_authorized(staking_provider=self.checksum_address) # checksum address here is staking provider
return is_staking

View File

@ -85,7 +85,9 @@ class ContractPayment(PaymentMethod, ABC):
if self.__agent:
return self.__agent # get cache
agent = ContractAgency.get_agent(
agent_class=self._AGENT, provider_uri=self.provider, registry=self.registry
agent_class=self._AGENT,
blockchain_endpoint=self.provider,
registry=self.registry,
)
self.__agent = agent
return self.__agent # set cache

View File

@ -183,7 +183,7 @@ class StakingProviderMetricsCollector(BaseMetricsCollector):
application_agent = ContractAgency.get_agent(
TACoApplicationAgent,
registry=self.contract_registry,
provider_uri=self.eth_endpoint,
blockchain_endpoint=self.eth_endpoint,
)
authorized = application_agent.get_authorized_stake(
staking_provider=self.staking_provider_address

View File

@ -73,7 +73,7 @@ def nucypher_agents(
taco_application_agent = ContractAgency.get_agent(
agent_class=TACoApplicationAgent,
registry=staking_registry,
provider_uri=eth_endpoint,
blockchain_endpoint=eth_endpoint,
) # type: TACoApplicationAgent
registry = ContractRegistry.from_latest_publication(
@ -83,19 +83,19 @@ def nucypher_agents(
taco_child_application_agent = ContractAgency.get_agent(
agent_class=TACoChildApplicationAgent,
registry=registry,
provider_uri=polygon_endpoint,
blockchain_endpoint=polygon_endpoint,
) # type: TACoChildApplicationAgent
coordinator_agent = ContractAgency.get_agent(
agent_class=CoordinatorAgent,
registry=registry,
provider_uri=polygon_endpoint,
blockchain_endpoint=polygon_endpoint,
) # type: CoordinatorAgent
subscription_manager_agent = ContractAgency.get_agent(
agent_class=SubscriptionManagerAgent,
registry=registry,
provider_uri=polygon_endpoint,
blockchain_endpoint=polygon_endpoint,
) # type: SubscriptionManagerAgent
message = (

View File

@ -161,13 +161,13 @@ def nucypher_dkg(
coordinator_agent = ContractAgency.get_agent(
agent_class=CoordinatorAgent,
registry=registry,
provider_uri=polygon_endpoint,
blockchain_endpoint=polygon_endpoint,
) # type: CoordinatorAgent
application_agent = ContractAgency.get_agent(
agent_class=TACoApplicationAgent,
registry=registry,
provider_uri=eth_endpoint,
blockchain_endpoint=eth_endpoint,
) # type: TACoApplicationAgent
#

View File

@ -7,12 +7,12 @@ def test_get_agent_with_different_registries(test_registry):
application_agent_1 = ContractAgency.get_agent(
TACoApplicationAgent,
registry=test_registry,
provider_uri=TEST_ETH_PROVIDER_URI,
blockchain_endpoint=TEST_ETH_PROVIDER_URI,
)
application_agent_2 = ContractAgency.get_agent(
TACoApplicationAgent,
registry=test_registry,
provider_uri=TEST_ETH_PROVIDER_URI,
blockchain_endpoint=TEST_ETH_PROVIDER_URI,
)
assert application_agent_2.registry == application_agent_1.registry == test_registry
assert application_agent_2 is application_agent_1

View File

@ -13,7 +13,9 @@ from tests.constants import TEST_ETH_PROVIDER_URI
@pytest.fixture(scope='module')
def agent(testerchain, test_registry) -> NucypherTokenAgent:
token_agent = ContractAgency.get_agent(
NucypherTokenAgent, registry=test_registry, provider_uri=TEST_ETH_PROVIDER_URI
NucypherTokenAgent,
registry=test_registry,
blockchain_endpoint=TEST_ETH_PROVIDER_URI,
)
return token_agent

View File

@ -73,7 +73,7 @@ def mock_funded_account_password_keystore(
taco_application_agent = ContractAgency.get_agent(
TACoApplicationAgent,
registry=test_registry,
provider_uri=TEST_ETH_PROVIDER_URI,
blockchain_endpoint=TEST_ETH_PROVIDER_URI,
)
taco_application_agent.bond_operator(
staking_provider=provider_address,

View File

@ -52,7 +52,7 @@ def erc20_evm_condition_balanceof(testerchain, test_registry):
token = ContractAgency.get_agent(
NucypherTokenAgent,
registry=test_registry,
provider_uri=TEST_ETH_PROVIDER_URI,
blockchain_endpoint=TEST_ETH_PROVIDER_URI,
)
condition = ContractCondition(
contract_address=token.contract.address,
@ -115,7 +115,7 @@ def subscription_manager_get_policy_zeroized_policy_struct_condition(
subscription_manager = ContractAgency.get_agent(
SubscriptionManagerAgent,
registry=test_registry,
provider_uri=TEST_ETH_PROVIDER_URI,
blockchain_endpoint=TEST_ETH_PROVIDER_URI,
)
condition = ContractCondition(
contract_address=subscription_manager.contract.address,
@ -135,7 +135,7 @@ def subscription_manager_is_active_policy_condition(testerchain, test_registry):
subscription_manager = ContractAgency.get_agent(
SubscriptionManagerAgent,
registry=test_registry,
provider_uri=TEST_ETH_PROVIDER_URI,
blockchain_endpoint=TEST_ETH_PROVIDER_URI,
)
condition = ContractCondition(
contract_address=subscription_manager.contract.address,
@ -157,7 +157,7 @@ def custom_context_variable_erc20_condition(
token = ContractAgency.get_agent(
NucypherTokenAgent,
registry=test_registry,
provider_uri=TEST_ETH_PROVIDER_URI,
blockchain_endpoint=TEST_ETH_PROVIDER_URI,
)
condition = ContractCondition(
contract_address=token.contract.address,

View File

@ -346,7 +346,7 @@ def test_subscription_manager_get_policy_policy_struct_condition_key_tuple_evalu
subscription_manager = ContractAgency.get_agent(
SubscriptionManagerAgent,
registry=test_registry,
provider_uri=TEST_ETH_PROVIDER_URI,
blockchain_endpoint=TEST_ETH_PROVIDER_URI,
)
# test "sponsor" key (owner is the same as sponsor for this policy)
@ -464,7 +464,7 @@ def test_subscription_manager_get_policy_policy_struct_condition_index_and_value
subscription_manager = ContractAgency.get_agent(
SubscriptionManagerAgent,
registry=test_registry,
provider_uri=TEST_POLYGON_PROVIDER_URI,
blockchain_endpoint=TEST_POLYGON_PROVIDER_URI,
)
# test "sponsor" index not equal to correct value

View File

@ -375,7 +375,9 @@ def staking_providers(
def coordinator_agent(testerchain, test_registry):
"""Creates a coordinator agent"""
coordinator = ContractAgency.get_agent(
CoordinatorAgent, registry=test_registry, provider_uri=TEST_ETH_PROVIDER_URI
CoordinatorAgent,
registry=test_registry,
blockchain_endpoint=TEST_ETH_PROVIDER_URI,
)
return coordinator
@ -385,7 +387,7 @@ def taco_application_agent(test_registry):
_taco_application_agent = ContractAgency.get_agent(
TACoApplicationAgent,
registry=test_registry,
provider_uri=TEST_ETH_PROVIDER_URI,
blockchain_endpoint=TEST_ETH_PROVIDER_URI,
)
return _taco_application_agent
@ -396,7 +398,7 @@ def taco_child_application_agent(testerchain, test_registry):
_taco_child_application_agent = ContractAgency.get_agent(
TACoChildApplicationAgent,
registry=test_registry,
provider_uri=TEST_ETH_PROVIDER_URI,
blockchain_endpoint=TEST_ETH_PROVIDER_URI,
)
return _taco_child_application_agent

View File

@ -197,7 +197,7 @@ def aggregate_nodes(provider_uri: str) -> Tuple[Set[Ursula], Set[Ursula]]:
if DEFAULT_SEEDNODE_URIS:
for uri in DEFAULT_SEEDNODE_URIS:
ursula = Ursula.from_seed_and_stake_info(
seed_uri=uri, provider_uri=provider_uri
seed_uri=uri, eth_endpoint=provider_uri
)
seednodes.add(ursula)
@ -205,7 +205,7 @@ def aggregate_nodes(provider_uri: str) -> Tuple[Set[Ursula], Set[Ursula]]:
if HANDPICKED_URSULA_URIS:
for uri in HANDPICKED_URSULA_URIS:
ursula = Ursula.from_seed_and_stake_info(
seed_uri=uri, provider_uri=provider_uri
seed_uri=uri, eth_endpoint=provider_uri
)
ursulas.add(ursula)

View File

@ -10,7 +10,7 @@ from tests.mock.coordinator import MockCoordinatorAgent
@pytest.fixture(scope="module")
def agent(mock_contract_agency) -> MockCoordinatorAgent:
coordinator_agent: CoordinatorAgent = mock_contract_agency.get_agent(
CoordinatorAgent, registry=None, provider_uri=MOCK_ETH_PROVIDER_URI
CoordinatorAgent, registry=None, blockchain_endpoint=MOCK_ETH_PROVIDER_URI
)
return coordinator_agent