Merge pull request #154 from bugout-dev/smartcontract-source-info

Smartcontract source info fix
pull/156/head^2
Neeraj Kashyap 2021-08-24 08:58:33 -07:00 zatwierdzone przez GitHub
commit 66b58b60b1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 13 dodań i 7 usunięć

Wyświetl plik

@ -16,6 +16,7 @@ from . import data
from .settings import DEFAULT_STREAM_TIMEINTERVAL, ETHERSCAN_SMARTCONTRACTS_BUCKET
logger = logging.getLogger(__name__)
ETHERSCAN_SMARTCONTRACT_LABEL_NAME = "etherscan_smartcontract"
async def get_transaction_in_blocks(
@ -258,7 +259,7 @@ def parse_search_query_to_sqlalchemy_filters(q: str, allowed_addresses: List[str
return constructed_filters
def get_source_code(
def get_contract_source_info(
db_session: Session, contract_address: str
) -> Optional[data.EthereumSmartContractSourceInfo]:
query = db_session.query(EthereumAddress.id).filter(
@ -272,7 +273,7 @@ def get_source_code(
)
for label in labels:
if label.label == "etherscan_smartcontract":
if label.label == ETHERSCAN_SMARTCONTRACT_LABEL_NAME:
object_uri = label.label_data["object_uri"]
key = object_uri.split("s3://etherscan-smart-contracts/")[1]
s3 = boto3.client("s3")
@ -288,7 +289,7 @@ def get_source_code(
)
return contract_source_info
except:
logger.error(f"Failed to load smart contract {contract_address}")
logger.error(f"Failed to load smart contract {object_uri}")
return None

Wyświetl plik

@ -84,11 +84,13 @@ async def txinfo_ethereum_blockchain_handler(
if smart_contract is not None:
response.is_smart_contract_deployment = True
else:
response.smart_contract_info = actions.get_source_code(
source_info = actions.get_contract_source_info(
db_session, txinfo_request.tx.to_address
)
response.smart_contract_address = txinfo_request.tx.to_address
response.is_smart_contract_call = True
if source_info is not None:
response.smart_contract_info = source_info
response.smart_contract_address = txinfo_request.tx.to_address
response.is_smart_contract_call = True
return response

Wyświetl plik

@ -43,4 +43,6 @@ for path in MOONSTREAM_OPENAPI_LIST:
DEFAULT_STREAM_TIMEINTERVAL = 5 * 60
# S3 Bucket
ETHERSCAN_SMARTCONTRACTS_BUCKET = "etherscan-smart-contracts"
ETHERSCAN_SMARTCONTRACTS_BUCKET = os.environ.get("AWS_S3_SMARTCONTRACT_BUCKET")
if ETHERSCAN_SMARTCONTRACTS_BUCKET is None:
raise ValueError("AWS_S3_SMARTCONTRACT_BUCKET is not set")

Wyświetl plik

@ -5,5 +5,6 @@ export MOONSTREAM_DATA_JOURNAL_ID="<bugout_journal_id_to_store_blockchain_data>"
export MOONSTREAM_DB_URI="postgresql://<username>:<password>@<db_host>:<db_port>/<db_name>"
export MOONSTREAM_POOL_SIZE=0
export MOONSTREAM_ADMIN_ACCESS_TOKEN="<Access token to application resources>"
export AWS_S3_SMARTCONTRACT_BUCKET=""
export BUGOUT_BROOD_URL="https://auth.bugout.dev"
export BUGOUT_SPIRE_URL="https://spire.bugout.dev"