kopia lustrzana https://github.com/bugout-dev/moonstream
Add abi_hash to subscription.
rodzic
319b973053
commit
f40a0fde1a
|
@ -379,15 +379,13 @@ def dashboards_abi_validation(
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def validate_abi_string(abi: str) -> None:
|
def validate_abi_string(abi: Any) -> None:
|
||||||
"""
|
"""
|
||||||
Transform string to json and run validation
|
Transform string to json and run validation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
validate_abi(json.loads(abi))
|
validate_abi(abi)
|
||||||
except json.JSONDecodeError:
|
|
||||||
raise MoonstreamHTTPException(status_code=400, detail="Malformed abi body.")
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise MoonstreamHTTPException(status_code=400, detail=e)
|
raise MoonstreamHTTPException(status_code=400, detail=e)
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -406,11 +406,12 @@ async def get_dashboard_data_links_handler(
|
||||||
|
|
||||||
for subscription in dashboard_subscriptions:
|
for subscription in dashboard_subscriptions:
|
||||||
|
|
||||||
|
hash = subscription.resource_data["abi_hash"]
|
||||||
available_timescales = [timescale.value for timescale in data.TimeScale]
|
available_timescales = [timescale.value for timescale in data.TimeScale]
|
||||||
stats[subscription.id] = {}
|
stats[subscription.id] = {}
|
||||||
for timescale in available_timescales:
|
for timescale in available_timescales:
|
||||||
try:
|
try:
|
||||||
result_key = f'contracts_data/{subscription.resource_data["address"]}/v1/{timescale}.json'
|
result_key = f'contracts_data/{subscription.resource_data["address"]}/{hash}/v1/{timescale}.json'
|
||||||
stats_presigned_url = s3_client.generate_presigned_url(
|
stats_presigned_url = s3_client.generate_presigned_url(
|
||||||
"get_object",
|
"get_object",
|
||||||
Params={"Bucket": SMARTCONTRACTS_ABI_BUCKET, "Key": result_key},
|
Params={"Bucket": SMARTCONTRACTS_ABI_BUCKET, "Key": result_key},
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
The Moonstream subscriptions HTTP API
|
The Moonstream subscriptions HTTP API
|
||||||
"""
|
"""
|
||||||
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
from typing import List, Optional, Dict, Any
|
from typing import List, Optional, Dict, Any
|
||||||
|
@ -13,7 +14,7 @@ from fastapi import APIRouter, Depends, Request, Form
|
||||||
from web3 import Web3
|
from web3 import Web3
|
||||||
|
|
||||||
from ..actions import (
|
from ..actions import (
|
||||||
validate_abi_string,
|
validate_abi_json,
|
||||||
upload_abi_to_s3,
|
upload_abi_to_s3,
|
||||||
)
|
)
|
||||||
from ..admin import subscription_types
|
from ..admin import subscription_types
|
||||||
|
@ -112,10 +113,21 @@ async def add_subscription_handler(
|
||||||
|
|
||||||
if abi:
|
if abi:
|
||||||
|
|
||||||
validate_abi_string(abi=abi)
|
try:
|
||||||
|
json_abi = json.loads(abi)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
raise MoonstreamHTTPException(status_code=400, detail="Malformed abi body.")
|
||||||
|
|
||||||
|
validate_abi_json(json_abi)
|
||||||
|
|
||||||
update_resource = upload_abi_to_s3(resource=resource, abi=abi, update={})
|
update_resource = upload_abi_to_s3(resource=resource, abi=abi, update={})
|
||||||
|
|
||||||
|
abi_string = json.dumps(json_abi, sort_keys=True, indent=2)
|
||||||
|
|
||||||
|
hash = hashlib.md5(abi_string.encode("utf-8")).hexdigest()
|
||||||
|
|
||||||
|
update_resource["abi_hash"] = hash
|
||||||
|
|
||||||
try:
|
try:
|
||||||
updated_resource: BugoutResource = bc.update_resource(
|
updated_resource: BugoutResource = bc.update_resource(
|
||||||
token=token,
|
token=token,
|
||||||
|
@ -241,7 +253,16 @@ async def update_subscriptions_handler(
|
||||||
|
|
||||||
if abi:
|
if abi:
|
||||||
|
|
||||||
validate_abi_string(abi=abi)
|
try:
|
||||||
|
json_abi = json.loads(abi)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
raise MoonstreamHTTPException(status_code=400, detail="Malformed abi body.")
|
||||||
|
|
||||||
|
validate_abi_json(json_abi)
|
||||||
|
|
||||||
|
abi_string = json.dumps(json_abi, sort_keys=True, indent=2)
|
||||||
|
|
||||||
|
hash = hashlib.md5(abi_string.encode("utf-8")).hexdigest()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subscription_resource: BugoutResource = bc.get_resource(
|
subscription_resource: BugoutResource = bc.get_resource(
|
||||||
|
@ -264,6 +285,8 @@ async def update_subscriptions_handler(
|
||||||
resource=subscription_resource, abi=abi, update=update
|
resource=subscription_resource, abi=abi, update=update
|
||||||
)
|
)
|
||||||
|
|
||||||
|
update["abi_hash"] = hash
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resource: BugoutResource = bc.update_resource(
|
resource: BugoutResource = bc.update_resource(
|
||||||
token=token,
|
token=token,
|
||||||
|
|
|
@ -304,7 +304,6 @@ def days_stats(type, abi):
|
||||||
|
|
||||||
|
|
||||||
def crawlers_start(db_session):
|
def crawlers_start(db_session):
|
||||||
token = os.getenv("MOONSTREAM_ADMIN_ACCESS_TOKEN")
|
|
||||||
|
|
||||||
# read all subscriptions
|
# read all subscriptions
|
||||||
required_subscriptions: BugoutResources = bc.list_resources(
|
required_subscriptions: BugoutResources = bc.list_resources(
|
||||||
|
|
Ładowanie…
Reference in New Issue