Skip to content

Commit

Permalink
fix: tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
dvilelaf committed Mar 16, 2024
1 parent 3197f55 commit afba8de
Show file tree
Hide file tree
Showing 10 changed files with 4,922 additions and 98 deletions.
1,256 changes: 1,256 additions & 0 deletions packages/dvilela/contracts/agent_registry.json

Large diffs are not rendered by default.

1,217 changes: 1,217 additions & 0 deletions packages/dvilela/contracts/component_registry.json

Large diffs are not rendered by default.

2,031 changes: 2,031 additions & 0 deletions packages/dvilela/contracts/service_registry.json

Large diffs are not rendered by default.

56 changes: 46 additions & 10 deletions packages/dvilela/contracts/service_registry/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""This module contains the class to connect to the wveolas contract."""
import logging
from typing import Optional
from web3.types import BlockIdentifier

from aea.common import JSONLike
from aea.configurations.base import PublicId
Expand All @@ -41,19 +42,54 @@ class ServiceRegistryContract(Contract):
contract_id = PUBLIC_ID

@classmethod
def get_create_events(
cls, ledger_api: EthereumApi, contract_address: str, from_block: int
def get_events(
cls,
ledger_api: EthereumApi,
contract_address: str,
event_name: str,
from_block: BlockIdentifier = "earliest",
to_block: BlockIdentifier = "latest",
) -> Optional[JSONLike]:
"""Get CreateService events."""
"""Get events."""
contract_instance = cls.get_instance(ledger_api, contract_address)

create_service_events = ledger_api.contract_method_call(
# Avoid parsing too many blocks at a time. This might take too long and
# the connection could time out.
MAX_BLOCKS = 300000

to_block = (
ledger_api.api.eth.get_block_number() - 1 if to_block == "latest" else to_block
)
ranges = list(range(from_block, to_block, MAX_BLOCKS)) + [to_block]

# Event loop
event = getattr(contract_instance.events, event_name)
events = []
for i in range(len(ranges) - 1):
from_block = ranges[i]
to_block = ranges[i + 1]
events += event.create_filter(
fromBlock=from_block, # exclusive
toBlock=to_block, # inclusive
).get_all_entries() # limited to 10k entries for now: https://github.com/valory-xyz/contribution-service/issues/13

return dict(
events=events,
last_block=int(to_block),
)


@classmethod
def get_token_uri(
cls, ledger_api: EthereumApi, contract_address: str, unit_id: int
) -> Optional[JSONLike]:
"""Get events."""
contract_instance = cls.get_instance(ledger_api, contract_address)

result = ledger_api.contract_method_call(
contract_instance=contract_instance,
method_name="getVotes",
account=owner_address,
method_name="tokenURI",
unitId=unit_id,
)

return {
"last_parsed_block": last_parsed_block,
"create_service_events": create_service_events,
}
return {"result": result}
Loading

0 comments on commit afba8de

Please sign in to comment.