change usage of nodebalancer.

support-interfaces-endpoint
Andrey 2023-06-22 13:30:09 +03:00
rodzic 07de2c7382
commit 92888ba80d
3 zmienionych plików z 13 dodań i 64 usunięć

Wyświetl plik

@ -804,13 +804,13 @@ def get_moonworm_jobs(
def get_list_of_support_interfaces(
blockchain_type: AvailableBlockchainType,
address: str,
access_id: Optional[str] = None,
user_token: uuid.UUID,
multicall_method: str = "tryAggregate",
):
"""
Returns list of interfaces supported by given address
"""
web3_client = connect(blockchain_type, access_id=uuid.UUID(access_id))
web3_client = connect(blockchain_type, user_token=user_token)
contract = web3_client.eth.contract(
address=Web3.toChecksumAddress(address),
@ -845,15 +845,12 @@ def get_list_of_support_interfaces(
result = {}
for i, selector in enumerate(list_of_interfaces):
if multicall_result[i][0]:
supported = FunctionSignature(
contract.get_function_by_name("supportsInterface")
).decode_data(multicall_result[i][1])
if supported[0]:
result[selectors[selector]["name"]] = { # type: ignore
"selector": selector,
"abi": selectors[selector]["abi"], # type: ignore
@ -865,12 +862,12 @@ def get_list_of_support_interfaces(
def check_if_smartcontract(
blockchain_type: AvailableBlockchainType,
address: str,
access_id: Optional[str] = None,
user_token: uuid.UUID,
):
"""
Checks if address is a smart contract on blockchain
"""
web3_client = connect(blockchain_type, access_id=uuid.UUID(access_id))
web3_client = connect(blockchain_type, user_token=user_token)
is_contract = False

Wyświetl plik

@ -6,6 +6,7 @@ import hashlib
import json
import logging
from typing import Any, Dict, List, Optional
import traceback
from bugout.exceptions import BugoutResponseException
from fastapi import APIRouter, Depends, Request, Form, BackgroundTasks
@ -588,25 +589,6 @@ async def address_info(request: Request, address: str):
internal_error=e,
)
try:
resource = bc.list_resources(
token=user_token,
params={
"type": "nodebalancer-access",
},
)
except Exception as e:
logger.error(f"Error reading contract info from Brood API: {str(e)}")
raise MoonstreamHTTPException(status_code=500, internal_error=e)
access_id = resource.resources[0].resource_data["access_id"]
if not access_id:
raise MoonstreamHTTPException(
status_code=404,
detail="Not found access id",
)
contract_info = {}
for blockchain_type in AvailableBlockchainType:
@ -621,7 +603,7 @@ async def address_info(request: Request, address: str):
check_if_smartcontract,
address=address,
blockchain_type=blockchain_type,
access_id=access_id,
user_token=user_token,
)
)
@ -681,36 +663,11 @@ def get_contract_interfaces(
internal_error=e,
)
try:
resource = bc.list_resources(
token=user_token,
params={
"type": "nodebalancer-access",
},
)
except Exception as e:
logger.error(f"Error reading contract info from Brood API: {str(e)}")
raise MoonstreamHTTPException(status_code=500, internal_error=e)
if len(resource.resources) == 0:
raise MoonstreamHTTPException(
status_code=404,
detail="Not found access id",
)
access_id = resource.resources[0].resource_data["access_id"]
if not access_id:
raise MoonstreamHTTPException(
status_code=404,
detail="Not found access id",
)
try:
interfaces = get_list_of_support_interfaces(
blockchain_type=blockchain_type,
address=address,
access_id=access_id,
user_token=user_token,
)
except Exception as e:

Wyświetl plik

@ -1,6 +1,5 @@
import logging
from uuid import UUID
import traceback
from typing import Any, Optional, Union, Callable
from web3 import Web3
@ -9,7 +8,6 @@ from eth_abi import encode_single, decode_single
from eth_utils import function_signature_to_4byte_selector
from web3 import Web3
from web3.contract import ContractFunction
from web3.providers.ipc import IPCProvider
from web3.providers.rpc import HTTPProvider
from web3._utils.abi import normalize_event_input_types
@ -17,8 +15,6 @@ from web3._utils.abi import normalize_event_input_types
from .settings import (
MOONSTREAM_ETHEREUM_WEB3_PROVIDER_URI,
NB_ACCESS_ID_HEADER,
NB_DATA_SOURCE_HEADER,
NB_DATA_SOURCE_HEADER_VALUE,
MOONSTREAM_POLYGON_WEB3_PROVIDER_URI,
MOONSTREAM_MUMBAI_WEB3_PROVIDER_URI,
MOONSTREAM_XDAI_WEB3_PROVIDER_URI,
@ -46,22 +42,21 @@ def connect(
blockchain_type: AvailableBlockchainType,
web3_uri: Optional[str] = None,
access_id: Optional[UUID] = None,
async_: bool = False,
user_token: Optional[UUID] = None,
) -> Web3:
request_kwargs: Any = None
request_kwargs: D = {}
if access_id is not None:
if blockchain_type != AvailableBlockchainType.WYRM:
request_kwargs = {
"headers": {
"Content-Type": "application/json",
}
}
if blockchain_type != AvailableBlockchainType.WYRM:
if access_id is not None:
request_kwargs["headers"][NB_ACCESS_ID_HEADER] = str(access_id)
request_kwargs["headers"][
NB_DATA_SOURCE_HEADER
] = NB_DATA_SOURCE_HEADER_VALUE
elif user_token is not None:
request_kwargs["headers"]["Authorization"] = f"Bearer {user_token}"
if web3_uri is None:
if blockchain_type == AvailableBlockchainType.ETHEREUM: