Fixes to work with spire entity

pull/875/head
kompotkot 2023-07-31 14:19:22 +00:00
rodzic bbe1530eef
commit 5dfcfd634f
8 zmienionych plików z 66 dodań i 51 usunięć

Wyświetl plik

@ -477,7 +477,7 @@ def get_all_entries_from_search(
results: List[BugoutSearchResult] = [] results: List[BugoutSearchResult] = []
existing_metods = bc.search( existing_methods = bc.search(
token=token, token=token,
journal_id=journal_id, journal_id=journal_id,
query=search_query, query=search_query,
@ -486,11 +486,11 @@ def get_all_entries_from_search(
limit=limit, limit=limit,
offset=offset, offset=offset,
) )
results.extend(existing_metods.results) results.extend(existing_methods.results) # type: ignore
if len(results) != existing_metods.total_results: if len(results) != existing_methods.total_results:
for offset in range(limit, existing_metods.total_results, limit): for offset in range(limit, existing_methods.total_results, limit):
existing_metods = bc.search( existing_methods = bc.search(
token=token, token=token,
journal_id=journal_id, journal_id=journal_id,
query=search_query, query=search_query,
@ -499,7 +499,7 @@ def get_all_entries_from_search(
limit=limit, limit=limit,
offset=offset, offset=offset,
) )
results.extend(existing_metods.results) results.extend(existing_methods.results) # type: ignore
return results return results
@ -641,7 +641,7 @@ def get_entity_subscription_journal_id(
token: Union[uuid.UUID, str], token: Union[uuid.UUID, str],
user_id: uuid.UUID, user_id: uuid.UUID,
create_if_not_exist: bool = False, create_if_not_exist: bool = False,
) -> Optional[str]: ) -> str:
""" """
Get collection_id (journal_id) from brood resources. If journal not exist and create_if_not_exist is True Get collection_id (journal_id) from brood resources. If journal not exist and create_if_not_exist is True
""" """
@ -684,7 +684,7 @@ def generate_journal_for_user(
journals: BugoutJournals = bc.list_journals(token=token) journals: BugoutJournals = bc.list_journals(token=token)
available_journals: Dict[str, str] = { available_journals: Dict[str, str] = {
journal.name: journal.id for journal in journals.journals journal.name: str(journal.id) for journal in journals.journals
} }
subscription_journal_name = f"subscriptions_{user_id}" subscription_journal_name = f"subscriptions_{user_id}"
@ -693,7 +693,7 @@ def generate_journal_for_user(
journal: BugoutJournal = bc.create_journal( journal: BugoutJournal = bc.create_journal(
token=token, name=subscription_journal_name token=token, name=subscription_journal_name
) )
journal_id = journal.id journal_id = str(journal.id)
else: else:
journal_id = available_journals[subscription_journal_name] journal_id = available_journals[subscription_journal_name]
except Exception as e: except Exception as e:
@ -705,7 +705,7 @@ def generate_journal_for_user(
resource_data = { resource_data = {
"type": resource_type, "type": resource_type,
"user_id": str(user_id), "user_id": str(user_id),
"collection_id": str(journal_id), "collection_id": journal_id,
} }
try: try:
@ -832,14 +832,14 @@ def get_list_of_support_interfaces(
list_of_interfaces.sort() list_of_interfaces.sort()
for interaface in list_of_interfaces: for interface in list_of_interfaces:
calls.append( calls.append(
( (
contract.address, contract.address,
FunctionSignature( FunctionSignature(
contract.get_function_by_name("supportsInterface") contract.get_function_by_name("supportsInterface")
) )
.encode_data([bytes.fromhex(interaface)]) .encode_data([bytes.fromhex(interface)])
.hex(), .hex(),
) )
) )

Wyświetl plik

@ -68,7 +68,8 @@ def add_entity_subscription(
f"Unknown subscription type ID: {subscription_type_id}. " f"Unknown subscription type ID: {subscription_type_id}. "
f"Known subscription type IDs: {CANONICAL_SUBSCRIPTION_TYPES.keys()}" f"Known subscription type IDs: {CANONICAL_SUBSCRIPTION_TYPES.keys()}"
) )
elif CANONICAL_SUBSCRIPTION_TYPES[subscription_type_id].blockchain is None: blockchain = CANONICAL_SUBSCRIPTION_TYPES[subscription_type_id].blockchain
if blockchain is None:
raise ValueError( raise ValueError(
f"Subscription type ID {subscription_type_id} is not a blockchain subscription type." f"Subscription type ID {subscription_type_id} is not a blockchain subscription type."
) )
@ -77,7 +78,7 @@ def add_entity_subscription(
token=MOONSTREAM_ADMIN_ACCESS_TOKEN, token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
journal_id=journal_id, journal_id=journal_id,
address=address, address=address,
blockchain=CANONICAL_SUBSCRIPTION_TYPES[subscription_type_id].blockchain, blockchain=blockchain,
title=label, title=label,
required_fields=[ required_fields=[
{"type": "subscription"}, {"type": "subscription"},

Wyświetl plik

@ -57,13 +57,6 @@ class SubscriptionResourceData(BaseModel):
updated_at: Optional[datetime] updated_at: Optional[datetime]
class CreateSubscriptionRequest(BaseModel):
address: str
color: str
label: str
subscription_type_id: str
class PingResponse(BaseModel): class PingResponse(BaseModel):
""" """
Schema for ping response Schema for ping response

Wyświetl plik

@ -4,10 +4,10 @@ Event providers powered by Bugout journals.
import json import json
import logging import logging
from datetime import datetime from datetime import datetime
from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional, Tuple, Union
from bugout.app import Bugout from bugout.app import Bugout
from bugout.data import BugoutResource, BugoutSearchResult from bugout.data import BugoutResource, BugoutSearchResult, BugoutSearchResultAsEntity
from bugout.journal import SearchOrder from bugout.journal import SearchOrder
from dateutil.parser import isoparse from dateutil.parser import isoparse
from dateutil.tz import UTC from dateutil.tz import UTC
@ -155,7 +155,7 @@ class BugoutEventProvider:
timeout=self.timeout, timeout=self.timeout,
order=SearchOrder.DESCENDING, order=SearchOrder.DESCENDING,
) )
events.extend([self.entry_event(entry) for entry in search_results.results]) events.extend([self.entry_event(entry) for entry in search_results.results]) # type: ignore
offset = search_results.next_offset offset = search_results.next_offset
return stream_boundary, events return stream_boundary, events
@ -192,7 +192,7 @@ class BugoutEventProvider:
timeout=self.timeout, timeout=self.timeout,
order=SearchOrder.DESCENDING, order=SearchOrder.DESCENDING,
) )
return [self.entry_event(entry) for entry in search_results.results] return [self.entry_event(entry) for entry in search_results.results] # type: ignore
def next_event( def next_event(
self, self,
@ -233,7 +233,7 @@ class BugoutEventProvider:
) )
if not search_results.results: if not search_results.results:
return None return None
return self.entry_event(search_results.results[0]) return self.entry_event(search_results.results[0]) # type: ignore
def previous_event( def previous_event(
self, self,
@ -274,7 +274,7 @@ class BugoutEventProvider:
) )
if not search_results.results: if not search_results.results:
return None return None
return self.entry_event(search_results.results[0]) return self.entry_event(search_results.results[0]) # type: ignore
class EthereumTXPoolProvider(BugoutEventProvider): class EthereumTXPoolProvider(BugoutEventProvider):

Wyświetl plik

@ -5,9 +5,8 @@ from uuid import UUID
import boto3 # type: ignore import boto3 # type: ignore
import requests # type: ignore import requests # type: ignore
from bugout.data import BugoutResource, BugoutResources from bugout.data import BugoutResource, BugoutResources, BugoutSearchResultAsEntity
from bugout.exceptions import BugoutResponseException from bugout.exceptions import BugoutResponseException
from entity.data import EntitiesResponse, EntityResponse # type: ignore
from fastapi import APIRouter, Body, Path, Query, Request from fastapi import APIRouter, Body, Path, Query, Request
from .. import actions, data from .. import actions, data
@ -59,7 +58,7 @@ async def add_dashboard_handler(
token=MOONSTREAM_ADMIN_ACCESS_TOKEN, token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
) )
subscriprions_list = bc.search( subscriptions_list = bc.search(
token=token, token=token,
journal_id=journal_id, journal_id=journal_id,
required_field=[f"type:subscription"], required_field=[f"type:subscription"],
@ -69,9 +68,9 @@ async def add_dashboard_handler(
# process existing subscriptions with supplied ids # process existing subscriptions with supplied ids
available_subscriptions_ids: Dict[Union[UUID, str], EntityResponse] = { available_subscriptions_ids: Dict[Union[UUID, str], BugoutSearchResultAsEntity] = {
subscription.entity_id: subscription subscription.entity_id: subscription
for subscription in subscriprions_list.entities for subscription in subscriptions_list.entities
} }
for dashboard_subscription in subscription_settings: for dashboard_subscription in subscription_settings:
@ -232,7 +231,7 @@ async def update_dashboard_handler(
token=MOONSTREAM_ADMIN_ACCESS_TOKEN, token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
) )
subscriprions_list = bc.search( subscriptions_list = bc.search(
token=token, token=token,
journal_id=journal_id, journal_id=journal_id,
required_field=[f"type:subscription"], required_field=[f"type:subscription"],
@ -240,9 +239,9 @@ async def update_dashboard_handler(
representation="entity", representation="entity",
) )
available_subscriptions_ids: Dict[Union[UUID, str], EntityResponse] = { available_subscriptions_ids: Dict[Union[UUID, str], BugoutSearchResultAsEntity] = {
subscription.entity_id: subscription subscription.entity_id: subscription
for subscription in subscriprions_list.entities for subscription in subscriptions_list.entities
} }
for dashboard_subscription in subscription_settings: for dashboard_subscription in subscription_settings:
@ -335,7 +334,7 @@ async def get_dashboard_data_links_handler(
token=MOONSTREAM_ADMIN_ACCESS_TOKEN, token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
) )
subscriprions_list = bc.search( subscriptions_list = bc.search(
token=token, token=token,
journal_id=journal_id, journal_id=journal_id,
required_field=[f"type:subscription"], required_field=[f"type:subscription"],
@ -352,9 +351,9 @@ async def get_dashboard_data_links_handler(
] ]
] ]
dashboard_subscriptions: Dict[Union[UUID, str], EntitiesResponse] = { dashboard_subscriptions: Dict[Union[UUID, str], BugoutSearchResultAsEntity] = {
subscription.entity_id: subscription subscription.entity_id: subscription
for subscription in subscriprions_list.entities for subscription in subscriptions_list.entities
if str(subscription.entity_id) in subscriptions_ids if str(subscription.entity_id) in subscriptions_ids
} }

Wyświetl plik

@ -5,7 +5,7 @@ import hashlib
import json import json
import logging import logging
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor, as_completed from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor, as_completed
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional, Union
from bugout.data import BugoutSearchResult from bugout.data import BugoutSearchResult
from bugout.exceptions import BugoutResponseException from bugout.exceptions import BugoutResponseException
@ -136,7 +136,7 @@ async def add_subscription_handler(
if description: if description:
content["description"] = description content["description"] = description
allowed_required_fields = [] allowed_required_fields: List[Any] = []
if tags: if tags:
allowed_required_fields = [ allowed_required_fields = [
item item
@ -144,7 +144,7 @@ async def add_subscription_handler(
if not any(key in item for key in MOONSTREAM_ENTITIES_RESERVED_TAGS) if not any(key in item for key in MOONSTREAM_ENTITIES_RESERVED_TAGS)
] ]
required_fields = [ required_fields: List[Dict[str, Union[str, bool, int, List[Any]]]] = [
{"type": "subscription"}, {"type": "subscription"},
{"subscription_type_id": f"{subscription_type_id}"}, {"subscription_type_id": f"{subscription_type_id}"},
{"color": f"{color}"}, {"color": f"{color}"},
@ -162,13 +162,14 @@ async def add_subscription_handler(
user_id=user.id, user_id=user.id,
create_if_not_exist=True, create_if_not_exist=True,
) )
blockchain = subscription_types.CANONICAL_SUBSCRIPTION_TYPES[
subscription_type_id
].blockchain
entity = bc.create_entity( entity = bc.create_entity(
token=token, token=token,
journal_id=journal_id, journal_id=journal_id,
address=address, address=address,
blockchain=subscription_types.CANONICAL_SUBSCRIPTION_TYPES[ blockchain=blockchain if blockchain is not None else "",
subscription_type_id
].blockchain,
title=label, title=label,
required_fields=required_fields, required_fields=required_fields,
secondary_fields=content, secondary_fields=content,
@ -186,10 +187,15 @@ async def add_subscription_handler(
internal_error=e, internal_error=e,
detail="Currently unable to get journal id", detail="Currently unable to get journal id",
) )
entity_required_fields = (
entity.required_fields if entity.required_fields is not None else []
)
entity_secondary_fields = (
entity.secondary_fields if entity.secondary_fields is not None else {}
)
normalized_entity_tags = [ normalized_entity_tags = [
f"{key}:{value}" f"{key}:{value}"
for tag in entity.required_fields for tag in entity_required_fields
for key, value in tag.items() for key, value in tag.items()
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS
] ]
@ -200,8 +206,8 @@ async def add_subscription_handler(
address=address, address=address,
color=color, color=color,
label=label, label=label,
abi=entity.secondary_fields.get("abi"), abi=entity_secondary_fields.get("abi"),
description=entity.secondary_fields.get("description"), description=entity_secondary_fields.get("description"),
tags=normalized_entity_tags, tags=normalized_entity_tags,
subscription_type_id=subscription_type_id, subscription_type_id=subscription_type_id,
updated_at=entity.updated_at, updated_at=entity.updated_at,
@ -252,6 +258,7 @@ async def delete_subscription_handler(
color = None color = None
label = None label = None
abi = None abi = None
description = None
if tags is not None: if tags is not None:
for tag in tags: for tag in tags:
@ -266,6 +273,13 @@ async def delete_subscription_handler(
if deleted_entity.secondary_fields is not None: if deleted_entity.secondary_fields is not None:
abi = deleted_entity.secondary_fields.get("abi") abi = deleted_entity.secondary_fields.get("abi")
description = deleted_entity.secondary_fields.get("description")
deleted_entity_required_fields = (
deleted_entity.required_fields
if deleted_entity.required_fields is not None
else []
)
return data.SubscriptionResourceData( return data.SubscriptionResourceData(
id=str(deleted_entity.id), id=str(deleted_entity.id),
@ -274,8 +288,8 @@ async def delete_subscription_handler(
color=color, color=color,
label=label, label=label,
abi=abi, abi=abi,
description=deleted_entity.secondary_fields.get("description"), description=description,
tags=deleted_entity.required_fields, tags=deleted_entity_required_fields,
subscription_type_id=subscription_type_id, subscription_type_id=subscription_type_id,
updated_at=deleted_entity.updated_at, updated_at=deleted_entity.updated_at,
created_at=deleted_entity.created_at, created_at=deleted_entity.created_at,

Wyświetl plik

@ -1,4 +1,6 @@
selectors = { from typing import Any, Dict
selectors: Dict[str, Any] = {
"274c7b3c": { "274c7b3c": {
"name": "ERC20PresetMinterPauser", "name": "ERC20PresetMinterPauser",
"selector": "274c7b3c", "selector": "274c7b3c",

Wyświetl plik

@ -8,3 +8,9 @@ ignore_missing_imports = True
[mypy-pyevmasm.*] [mypy-pyevmasm.*]
ignore_missing_imports = True ignore_missing_imports = True
[mypy-requests.*]
ignore_missing_imports = True
[mypy-dateutil.*]
ignore_missing_imports = True