Skip to content

Chore: update to web3 6.2.0 #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ install_requires =
ujson==5.1.0 # required by aiocache
urllib3==1.26.11
uvloop==0.17.0
web3==6.0.0b9
web3==6.2.0

dependency_links =
https://github.com/aleph-im/py-libp2p/tarball/0.1.4-1-use-set#egg=libp2p
Expand All @@ -99,7 +99,7 @@ exclude =
testing =
ipfshttpclient==0.8.0a2 # eth/web3 test dependency, for some reason
more-itertools==8.14.0
mypy==0.950
mypy==1.2.0
pytest
pytest-cov
pytest-aiohttp
Expand Down
4 changes: 2 additions & 2 deletions src/aleph/chains/chaindata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import json
from typing import Dict, Optional, List, Any, Mapping, Set, cast
from typing import Dict, Optional, List, Any, Mapping, Set, cast, Type, Union

from aleph_message.models import StoreContent, ItemType, Chain, MessageType
from pydantic import ValidationError
Expand Down Expand Up @@ -177,7 +177,7 @@ def _get_tx_messages_smart_contract_protocol(tx: ChainTxDb) -> List[Dict[str, An
Message validation should be left to the message processing pipeline.
"""

payload_model = (
payload_model: Union[Type[TezosMessageEventPayload], Type[MessageEvent]] = (
TezosMessageEventPayload if tx.chain == Chain.TEZOS else MessageEvent
)

Expand Down
2 changes: 1 addition & 1 deletion src/aleph/chains/ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def get_contract(config, web3: Web3):

def get_logs_query(web3: Web3, contract, start_height, end_height):
return web3.eth.get_logs(
{"address": contract.address, "fromBlock": start_height, "toBlock": end_height} # type: ignore[arg-type]
{"address": contract.address, "fromBlock": start_height, "toBlock": end_height}
)


Expand Down
4 changes: 2 additions & 2 deletions src/aleph/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def init_node_cache(config: Config) -> NodeCache:
return node_cache


async def main(args):
async def main(args: List[str]) -> None:
"""Main entry point allowing external calls

Args:
Expand All @@ -82,7 +82,7 @@ async def main(args):
key_pair = generate_keypair(args.print_key)
save_keys(key_pair, args.key_dir)
if args.print_key:
print(key_pair.private_key.impl.export_key().decode("utf-8"))
print(key_pair.private_key.impl.export_key().decode("utf-8")) # type: ignore[attr-defined]

return

Expand Down
8 changes: 4 additions & 4 deletions src/aleph/schemas/api/messages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime as dt
from typing import Optional, Generic, TypeVar, Literal, List, Any, Union, Dict
from typing import Optional, Generic, TypeVar, Literal, List, Any, Union, Dict, Mapping

from aleph_message.models import (
AggregateContent,
Expand All @@ -8,7 +8,7 @@
ForgetContent,
PostContent,
ProgramContent,
StoreContent,
StoreContent, AlephMessage,
)
from aleph_message.models import MessageType, ItemType
from pydantic import BaseModel
Expand Down Expand Up @@ -91,7 +91,7 @@ class StoreMessage(
}


def format_message(message: Any) -> BaseMessage:
def format_message(message: Any) -> AlephMessage:
message_cls = MESSAGE_CLS_DICT[message.type]
return message_cls.from_orm(message)

Expand Down Expand Up @@ -164,7 +164,7 @@ class ForgottenMessageStatus(BaseMessageStatus):

class RejectedMessageStatus(BaseMessageStatus):
status: MessageStatus = MessageStatus.REJECTED
message: Dict[str, Any]
message: Mapping[str, Any]
error_code: ErrorCode
details: Any

Expand Down
6 changes: 3 additions & 3 deletions src/aleph/schemas/base_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import datetime as dt
from hashlib import sha256
from typing import Optional, Generic, TypeVar
from typing import Optional, Generic, TypeVar, Any, Mapping, cast

from aleph_message.models import BaseContent, Chain
from aleph_message.models import MessageType, ItemType
Expand Down Expand Up @@ -62,7 +62,7 @@ def check_item_type(cls, values):
return values

@validator("item_hash")
def check_item_hash(cls, v, values):
def check_item_hash(cls, v: Any, values: Mapping[str, Any]):
"""
For inline item types, check that the item hash is equal to
the hash of the item content.
Expand All @@ -73,7 +73,7 @@ def check_item_hash(cls, v, values):
raise ValueError("Could not determine item type")

if item_type == ItemType.inline:
item_content: str = values.get("item_content")
item_content = cast(Optional[str], values.get("item_content"))
if item_content is None:
raise ValueError("Could not find inline item content")

Expand Down
6 changes: 3 additions & 3 deletions src/aleph/web/controllers/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from aiohttp import web
from aleph_message.models import MessageType
from pydantic import ValidationError
from pydantic import ValidationError, parse_obj_as

from aleph.db.accessors.balances import get_total_balance
from aleph.db.accessors.files import (
Expand All @@ -15,7 +15,7 @@
from aleph.schemas.api.accounts import (
GetAccountBalanceResponse,
GetAccountFilesResponse,
GetAccountFilesQueryParams,
GetAccountFilesQueryParams, GetAccountFilesResponseItem,
)
from aleph.types.db_session import DbSessionFactory
from aleph.web.controllers.app_state_getters import get_session_factory_from_request
Expand Down Expand Up @@ -105,7 +105,7 @@ async def get_account_files(request: web.Request) -> web.Response:
response = GetAccountFilesResponse(
address=address,
total_size=total_size,
files=file_pins,
files=parse_obj_as(List[GetAccountFilesResponseItem], file_pins),
pagination_page=query_params.page,
pagination_total=nb_files,
pagination_per_page=query_params.pagination,
Expand Down
2 changes: 1 addition & 1 deletion src/aleph/web/controllers/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def split_str(cls, v):
return v


async def address_aggregate(request):
async def address_aggregate(request: web.Request) -> web.Response:
"""Returns the aggregate of an address.
TODO: handle filter on a single key, or even subkey.
"""
Expand Down
7 changes: 4 additions & 3 deletions src/aleph/web/controllers/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from aleph.db.accessors.messages import get_distinct_channels
from aleph.types.channel import Channel
from aleph.types.db_session import DbSessionFactory, DbSession
from aleph.types.db_session import DbSession
from aleph.web.controllers.app_state_getters import get_session_factory_from_request


@cached(ttl=60 * 120, cache=SimpleMemoryCache, timeout=120)
Expand All @@ -14,13 +15,13 @@ async def get_channels(session: DbSession) -> List[Channel]:
return list(channels)


async def used_channels(request):
async def used_channels(request: web.Request) -> web.Response:
"""All used channels list

TODO: do we need pagination?
"""

session_factory: DbSessionFactory = request.app["session_factory"]
session_factory = get_session_factory_from_request(request)

with session_factory() as session:
channels = await get_channels(session)
Expand Down
10 changes: 5 additions & 5 deletions src/aleph/web/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


@aiohttp_jinja2.template("index.html")
async def index(request) -> Dict:
async def index(request: web.Request) -> Dict:
"""Index of aleph."""

session_factory: DbSessionFactory = get_session_factory_from_request(request)
Expand All @@ -23,7 +23,7 @@ async def index(request) -> Dict:
return asdict(await get_metrics(session=session, node_cache=node_cache))


async def status_ws(request):
async def status_ws(request: web.Request) -> web.WebSocketResponse:
ws = web.WebSocketResponse()
await ws.prepare(request)

Expand All @@ -47,13 +47,13 @@ async def status_ws(request):
await asyncio.sleep(2)


async def metrics(request):
async def metrics(request: web.Request) -> web.Response:
"""Prometheus compatible metrics.

Naming convention:
https://prometheus.io/docs/practices/naming/
"""
session_factory: DbSessionFactory = get_session_factory_from_request(request)
session_factory = get_session_factory_from_request(request)
node_cache = get_node_cache_from_request(request)

with session_factory() as session:
Expand All @@ -64,7 +64,7 @@ async def metrics(request):
)


async def metrics_json(request):
async def metrics_json(request: web.Request) -> web.Response:
"""JSON version of the Prometheus metrics."""
session_factory: DbSessionFactory = get_session_factory_from_request(request)
node_cache = get_node_cache_from_request(request)
Expand Down
5 changes: 3 additions & 2 deletions src/aleph/web/controllers/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from aleph.types.db_session import DbSessionFactory, DbSession
from aleph.types.message_status import MessageStatus
from aleph.types.sort_order import SortOrder, SortBy
from aleph.web.controllers.app_state_getters import get_session_factory_from_request
from aleph.web.controllers.utils import (
DEFAULT_MESSAGES_PER_PAGE,
DEFAULT_PAGE,
Expand Down Expand Up @@ -195,7 +196,7 @@ def format_response(
return web.json_response(text=aleph_json.dumps(response).decode("utf-8"))


async def view_messages_list(request):
async def view_messages_list(request: web.Request) -> web.Response:
"""Messages list view with filters"""

try:
Expand All @@ -213,7 +214,7 @@ async def view_messages_list(request):
pagination_page = query_params.page
pagination_per_page = query_params.pagination

session_factory: DbSessionFactory = request.app["session_factory"]
session_factory = get_session_factory_from_request(request)
with session_factory() as session:
messages = get_matching_messages(
session, include_confirmations=True, **find_filters
Expand Down
8 changes: 6 additions & 2 deletions src/aleph/web/controllers/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,13 @@ async def get_raw_hash(request):
return response


async def get_file_pins_count(request):
async def get_file_pins_count(request: web.Request) -> web.Response:
item_hash = request.match_info.get("hash", None)
session_factory: DbSessionFactory = request.app["session_factory"]

if item_hash is None:
raise web.HTTPBadRequest(text="No hash provided")

session_factory = get_session_factory_from_request(request)
with session_factory() as session:
count = count_file_pins(session=session, file_hash=item_hash)
return web.json_response(data=count)
2 changes: 1 addition & 1 deletion tests/chains/test_tezos.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_datetime_to_iso_8601():
def test_indexer_event_to_aleph_message(message_type: str, message_content: str):
indexer_event = IndexerMessageEvent(
source="KT1BfL57oZfptdtMFZ9LNakEPvuPPA2urdSW",
timestamp="2022-11-16T00:00:00Z",
timestamp=dt.datetime(2022, 11, 16, tzinfo=dt.timezone.utc),
type="MessageEvent",
operationHash="oorMNgusX6RxZ4NhzYriVDN8HDeMBNkjD3E8kx9a7j7dRRDGkzz",
blockLevel=584664,
Expand Down
2 changes: 1 addition & 1 deletion tests/web/controllers/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_format_dict_for_prometheus():
) == '{a=1,b=2.2,c="3"}'


def test_format_dataclass_for_prometheus():
def test_format_dataclass_for_prometheus() -> None:

@dataclass
class Simple:
Expand Down