cleaned up txinfo endpoint

pull/139/head
yhtiyar 2021-08-23 16:47:33 +03:00
rodzic beb6cb90b4
commit 6abc6c67b9
3 zmienionych plików z 34 dodań i 31 usunięć

Wyświetl plik

@ -17,7 +17,7 @@ from sqlalchemy.orm import Session
from . import data from . import data
from .settings import DEFAULT_STREAM_TIMEINTERVAL from .settings import DEFAULT_STREAM_TIMEINTERVAL, ETHERSCAN_SMARTCONTRACTS_BUCKET
import boto3 import boto3
import json import json
@ -279,11 +279,11 @@ def get_source_code(
for label in labels: for label in labels:
if label.label == "etherscan_smartcontract": if label.label == "etherscan_smartcontract":
name = label.label_data["name"] object_uri = label.label_data["object_uri"]
uri = label.label_data["object_uri"] key = object_uri.split("s3://etherscan-smart-contracts/")[1]
key = uri.split("s3://etherscan-smart-contracts/")[1]
s3 = boto3.client("s3") s3 = boto3.client("s3")
bucket = "etherscan-smart-contracts" bucket = ETHERSCAN_SMARTCONTRACTS_BUCKET
try:
raw_obj = s3.get_object(Bucket=bucket, Key=key) raw_obj = s3.get_object(Bucket=bucket, Key=key)
obj_data = json.loads(raw_obj["Body"].read().decode("utf-8"))["data"] obj_data = json.loads(raw_obj["Body"].read().decode("utf-8"))["data"]
contract_source_info = data.EthereumSmartContractSourceInfo( contract_source_info = data.EthereumSmartContractSourceInfo(
@ -293,6 +293,8 @@ def get_source_code(
abi=obj_data["ABI"], abi=obj_data["ABI"],
) )
return contract_source_info return contract_source_info
except:
logger.error(f"Failed to load smart contract {contract_address}")
return None return None

Wyświetl plik

@ -8,6 +8,8 @@ end users.
import logging import logging
from typing import Dict, Optional from typing import Dict, Optional
from sqlalchemy.sql.expression import true
from fastapi import FastAPI, Depends, HTTPException, Query from fastapi import FastAPI, Depends, HTTPException, Query
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from moonstreamdb.db import yield_db_session from moonstreamdb.db import yield_db_session
@ -71,26 +73,22 @@ async def txinfo_ethereum_blockchain_handler(
logger.error(err) logger.error(err)
response.errors.append("Could not decode ABI from the given input") response.errors.append("Could not decode ABI from the given input")
# Checking if it is contract deployment: # transaction is contract deployment:
if txinfo_request.tx.to_address is None:
response.is_smart_contract_deployment = True
smart_contract = ( smart_contract = (
db_session.query(EthereumAddress) db_session.query(EthereumAddress)
.filter(EthereumAddress.transaction_hash == txinfo_request.tx.hash) .filter(EthereumAddress.transaction_hash == txinfo_request.tx.hash)
.one_or_none() .one_or_none()
) )
is_contract_deployment = smart_contract is not None if smart_contract is not None:
response.is_smart_contract_deployment = True
if txinfo_request.tx.to_address: else:
response.smart_contract_info = actions.get_source_code( response.smart_contract_info = actions.get_source_code(
db_session, txinfo_request.tx.to_address db_session, txinfo_request.tx.to_address
) )
response.smart_contract_address = txinfo_request.tx.to_address
if smart_contract is not None:
response.smart_contract_address = smart_contract.address
if txinfo_request.tx.to_address is None:
response.is_smart_contract_deployment = True
elif txinfo_request.tx.to_address == smart_contract.address:
response.is_smart_contract_call = True response.is_smart_contract_call = True
return response return response

Wyświetl plik

@ -41,3 +41,6 @@ for path in MOONSTREAM_OPENAPI_LIST:
DOCS_PATHS[f"/{path}/{DOCS_TARGET_PATH}/openapi.json"] = "GET" DOCS_PATHS[f"/{path}/{DOCS_TARGET_PATH}/openapi.json"] = "GET"
DEFAULT_STREAM_TIMEINTERVAL = 5 * 60 DEFAULT_STREAM_TIMEINTERVAL = 5 * 60
# S3 Bucket
ETHERSCAN_SMARTCONTRACTS_BUCKET = "etherscan-smart-contracts"