Revert "Revert "Zksync support for moonstreamapi""

pull/849/head
Sergei Sumarokov 2023-07-13 17:37:42 +03:00 zatwierdzone przez GitHub
rodzic f89ecd6fe0
commit 2d1a026bf0
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
12 zmienionych plików z 26123 dodań i 156 usunięć

Wyświetl plik

@ -59,11 +59,13 @@ blockchain_by_subscription_id = {
"mumbai_blockchain": "mumbai",
"xdai_blockchain": "xdai",
"wyrm_blockchain": "wyrm",
"zksync_era_testnet_blockchain": "zksync_era_testnet",
"ethereum_smartcontract": "ethereum",
"polygon_smartcontract": "polygon",
"mumbai_smartcontract": "mumbai",
"xdai_smartcontract": "xdai",
"wyrm_smartcontract": "wyrm",
"zksync_era_testnet_smartcontract": "zksync_era_testnet",
}

Wyświetl plik

@ -478,18 +478,12 @@ This CLI is configured to work with the following API URLs:
parser_moonworm_tasks_add.set_defaults(func=moonworm_tasks_add_subscription_handler)
queries_parser = subcommands.add_parser(
"queries", description="Manage Moonstream queries"
)
queries_parser.set_defaults(func=lambda _: queries_parser.print_help())
queries_subcommands = queries_parser.add_subparsers(
description="Query commands"
)
queries_subcommands = queries_parser.add_subparsers(description="Query commands")
create_query_parser = queries_subcommands.add_parser(
"create-template", description="Create query template"

Wyświetl plik

@ -24,12 +24,11 @@ from ..actions import get_all_entries_from_search, name_normalization
logger = logging.getLogger(__name__)
def create_query_template(args: argparse.Namespace) -> None:
"""
Create query template for all queries resources.
"""
query = ""
with args.query_file:
query = textwrap.indent(args.query_file.read(), " ")
@ -39,7 +38,6 @@ def create_query_template(args: argparse.Namespace) -> None:
name = f"template_{name_normalization(args.name)}"
try:
entry = bc.create_entry(
journal_id=MOONSTREAM_QUERIES_JOURNAL_ID,
title=args.name,
@ -51,18 +49,17 @@ def create_query_template(args: argparse.Namespace) -> None:
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
)
except BugoutResponseException as err:
logger.error(f"Failed to create query template: {err}")
return
except Exception as err:
logger.error(f"Failed to create query template: {err}")
return
logger.info(f"Query template created: {entry.id}")
logger.info(f"Query template created url name: {name}")
### Add query id
try:
@ -81,4 +78,4 @@ def create_query_template(args: argparse.Namespace) -> None:
logger.error(f"Failed to add query id: {err}")
return
logger.info(f"Query created: {json.dumps(entry.dict(), indent=4)}")
logger.info(f"Query created: {json.dumps(entry.dict(), indent=4)}")

Wyświetl plik

@ -72,6 +72,17 @@ CANONICAL_SUBSCRIPTION_TYPES = {
stripe_price_id=None,
active=True,
),
"zksync_era_testnet_smartcontract": SubscriptionTypeResourceData(
id="zksync_era_testnet_smartcontract",
name="zkSync Era testnet smartcontract",
blockchain="zksync_era_testnet",
choices=["input:address", "tag:erc721"],
description="Contracts events and tx_calls of contract of zkSync Era testnet blockchain.",
icon_url="https://s3.amazonaws.com/static.simiotics.com/moonstream/assets/zksync-era-testnet-token-logo.png",
stripe_product_id=None,
stripe_price_id=None,
active=True,
),
"ethereum_blockchain": SubscriptionTypeResourceData(
id="ethereum_blockchain",
name="Ethereum transactions",
@ -127,6 +138,17 @@ CANONICAL_SUBSCRIPTION_TYPES = {
stripe_price_id=None,
active=False,
),
"zksync_era_testnet_blockchain": SubscriptionTypeResourceData(
id="zksync_era_testnet_blockchain",
name="zkSync Era testnet transactions",
blockchain="zksync_era_testnet",
choices=["input:address", "tag:erc721"],
description="ZkSync Era testnet chain transactions subscription.",
icon_url="https://s3.amazonaws.com/static.simiotics.com/moonstream/assets/zksync-era-testnet-token-logo.png",
stripe_product_id=None,
stripe_price_id=None,
active=False,
),
"ethereum_whalewatch": SubscriptionTypeResourceData(
id="ethereum_whalewatch",
name="Ethereum whale watch",

Wyświetl plik

@ -51,10 +51,12 @@ event_providers: Dict[str, Any] = {
moonworm_provider.PolygonMoonwormProvider.event_type: moonworm_provider.PolygonMoonwormProvider,
moonworm_provider.MumbaiMoonwormProvider.event_type: moonworm_provider.MumbaiMoonwormProvider,
moonworm_provider.XDaiMoonwormProvider.event_type: moonworm_provider.XDaiMoonwormProvider,
moonworm_provider.ZkSyncEraTestnetMoonwormProvider.event_type: moonworm_provider.ZkSyncEraTestnetMoonwormProvider,
transactions.EthereumTransactions.event_type: transactions.EthereumTransactions,
transactions.PolygonTransactions.event_type: transactions.PolygonTransactions,
transactions.MumbaiTransactions.event_type: transactions.MumbaiTransactions,
transactions.XDaiTransactions.event_type: transactions.XDaiTransactions,
transactions.ZkSyncEraTestnetTransactions.event_type: transactions.ZkSyncEraTestnetTransactions,
bugout.polygon_whalewatch_provider.event_type: bugout.polygon_whalewatch_provider,
bugout.ethereum_txpool_provider.event_type: bugout.ethereum_txpool_provider,
bugout.ethereum_whalewatch_provider.event_type: bugout.ethereum_whalewatch_provider,

Wyświetl plik

@ -21,6 +21,7 @@ ethereum_event_type = "ethereum_blockchain"
polygon_event_type = "polygon_blockchain"
mumbai_event_type = "mumbai_blockchain"
xdai_event_type = "xdai_blockchain"
zksync_era_testnet_event_type = "zksync_era_testnet_blockchain"
allowed_tags = ["tag:erc721"]
description = f"""Event provider for transactions from the Ethereum blockchain.
@ -413,3 +414,10 @@ XDaiMoonwormProvider = MoonwormProvider(
description="Provider for reviving transactions from XDai tables.",
streamboaundary_range_limit=2 * 60 * 60,
)
ZkSyncEraTestnetMoonwormProvider = MoonwormProvider(
event_type="zksync_era_testnet_smartcontract",
blockchain=AvailableBlockchainType("zksync_era_testnet"),
description="Provider for reviving transactions from zkSync Era testnet tables.",
streamboaundary_range_limit=2 * 60 * 60,
)

Wyświetl plik

@ -475,3 +475,10 @@ XDaiTransactions = TransactionsProvider(
description="Provider for resiving transactions from XDai tables.",
streamboaundary_range_limit=2 * 60 * 60,
)
ZkSyncEraTestnetTransactions = TransactionsProvider(
event_type="zksync_era_testnet_blockchain",
blockchain=AvailableBlockchainType("zksync_era_testnet"),
description="Provider for resiving transactions from ZkSync Era testnet tables.",
streamboaundary_range_limit=2 * 60 * 60,
)

Wyświetl plik

@ -7,7 +7,6 @@ from typing import Any, Dict, List, Optional, Tuple, Union
from uuid import UUID
from bugout.data import BugoutResources, BugoutJournalEntryContent, BugoutJournalEntry
from bugout.exceptions import BugoutResponseException
from fastapi import APIRouter, Body, Request
@ -157,7 +156,6 @@ async def create_query_handler(
return entry
@router.get("/templates", tags=["queries"])
def get_suggested_queries(
supported_interfaces: Optional[List[str]] = None,
@ -223,7 +221,6 @@ async def get_query_handler(
) -> data.QueryInfoResponse:
token = request.state.token
# normalize query name
try:
@ -234,7 +231,6 @@ async def get_query_handler(
detail=f"Provided query name can't be normalize please select different.",
)
# check in templates
try:
@ -283,7 +279,6 @@ async def get_query_handler(
else:
query_id = entries.results[0].entry_url.split("/")[-1]
entry = entries.results[0]
try:
@ -312,7 +307,6 @@ async def get_query_handler(
else:
query_parameters[param] = None
print(type(entry.created_at))
return data.QueryInfoResponse(
@ -395,7 +389,6 @@ async def update_query_data_handler(
detail=f"Provided query name can't be normalize please select different.",
)
# check in templates
try:
@ -510,9 +503,7 @@ async def get_access_link_handler(
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
journal_id=MOONSTREAM_QUERIES_JOURNAL_ID,
query=f"tag:query_template tag:query_url:{query_name_normalized}",
filters=[
f"context_type:{MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE}"
],
filters=[f"context_type:{MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE}"],
limit=1,
)
except BugoutResponseException as e:
@ -522,7 +513,6 @@ async def get_access_link_handler(
raise MoonstreamHTTPException(status_code=500, internal_error=e)
if len(entries.results) == 0:
try:
query_id = get_query_by_name(query_name, token)
except NameNormalizationException:
@ -532,7 +522,6 @@ async def get_access_link_handler(
)
try:
entries = bc.search(
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
journal_id=MOONSTREAM_QUERIES_JOURNAL_ID,
@ -552,7 +541,6 @@ async def get_access_link_handler(
)
try:
s3_response = None
if entries.results[0].content:
@ -631,4 +619,4 @@ async def remove_query_handler(
except Exception as e:
raise MoonstreamHTTPException(status_code=500, internal_error=e)
return entry
return entry

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -137,6 +137,13 @@ MOONSTREAM_WYRM_WEB3_PROVIDER_URI = os.environ.get(
if MOONSTREAM_WYRM_WEB3_PROVIDER_URI == "":
raise Exception("MOONSTREAM_WYRM_WEB3_PROVIDER_URI env variable is not set")
MOONSTREAM_ZKSYNC_ERA_TESTNET_WEB3_PROVIDER_URI = os.environ.get(
"MOONSTREAM_ZKSYNC_ERA_TESTNET_WEB3_PROVIDER_URI", ""
)
if MOONSTREAM_ZKSYNC_ERA_TESTNET_WEB3_PROVIDER_URI == "":
raise Exception(
"MOONSTREAM_ZKSYNC_ERA_TESTNET_WEB3_PROVIDER_URI env variable is not set"
)
MOONSTREAM_S3_QUERIES_BUCKET = os.environ.get("MOONSTREAM_S3_QUERIES_BUCKET", "")
if MOONSTREAM_S3_QUERIES_BUCKET == "":

Wyświetl plik

@ -19,6 +19,7 @@ from .settings import (
MOONSTREAM_MUMBAI_WEB3_PROVIDER_URI,
MOONSTREAM_XDAI_WEB3_PROVIDER_URI,
MOONSTREAM_WYRM_WEB3_PROVIDER_URI,
MOONSTREAM_ZKSYNC_ERA_TESTNET_WEB3_PROVIDER_URI,
multicall_contracts,
multicall_contract_abi,
)
@ -69,6 +70,8 @@ def connect(
web3_uri = MOONSTREAM_XDAI_WEB3_PROVIDER_URI
elif blockchain_type == AvailableBlockchainType.WYRM:
web3_uri = MOONSTREAM_WYRM_WEB3_PROVIDER_URI
elif blockchain_type == AvailableBlockchainType.ZKSYNC_ERA_TESTNET:
web3_uri = MOONSTREAM_ZKSYNC_ERA_TESTNET_WEB3_PROVIDER_URI
else:
raise Exception("Wrong blockchain type provided for web3 URI")

Wyświetl plik

@ -16,7 +16,7 @@ setup(
"bugout>=0.2.9",
"moonstream-entity>=0.0.5",
"fastapi",
"moonstreamdb>=0.3.3",
"moonstreamdb>=0.3.4",
"humbug",
"pydantic",
"pyevmasm",