Improved /txinfo/ethereum_blockchain endpoint

The response now explicitly specifies whether the given transaction was
a smart contract deployment or a smart contract method call.

Testing script now uses an actual transaction from mainnet.
pull/27/head
Neeraj Kashyap 2021-07-28 23:57:40 -07:00
rodzic ad37dbd464
commit 7147377cf9
4 zmienionych plików z 27 dodań i 11 usunięć

Wyświetl plik

@ -106,6 +106,8 @@ class TxinfoEthereumBlockchainRequest(BaseModel):
class TxinfoEthereumBlockchainResponse(BaseModel):
tx: EthereumTransaction
is_smart_contract_deployment: bool = False
is_smart_contract_call: bool = False
smart_contract_address: Optional[str] = None
abi: Optional[ContractABI] = None
errors: List[str] = Field(default_factory=list)

Wyświetl plik

@ -11,18 +11,16 @@ from typing import Any, Dict
from fastapi import (
FastAPI,
Depends,
HTTPException,
Request,
)
from fastapi.middleware.cors import CORSMiddleware
from moonstreamdb.db import yield_db_session
from moonstreamdb.models import EthereumSmartContract
from sqlalchemy.orm import Session
from ..abi_decoder import decode_abi
from ..data import TxinfoEthereumBlockchainRequest, TxinfoEthereumBlockchainResponse
from ..middleware import BroodAuthMiddleware
from ..settings import (
MOONSTREAM_APPLICATION_ID,
DOCS_TARGET_PATH,
ORIGINS,
DOCS_PATHS,
@ -60,6 +58,8 @@ whitelist_paths.update(DOCS_PATHS)
app.add_middleware(BroodAuthMiddleware, whitelist=whitelist_paths)
# TODO(zomglings): Factor out the enrichment logic into a separate action, because it may be useful
# independently from serving API calls (e.g. data processing).
@app.post(
"/ethereum_blockchain",
tags=["txinfo"],
@ -77,4 +77,18 @@ async def txinfo_ethereum_blockchain_handler(
logger.error(r"Could not decode ABI:")
logger.error(err)
response.errors.append("Could not decode ABI from the given input")
smart_contract = (
db_session.query(EthereumSmartContract)
.filter(EthereumSmartContract.transaction_hash == txinfo_request.tx.hash)
.one_or_none()
)
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
return response

Wyświetl plik

@ -11,7 +11,7 @@ fastapi==0.66.0
h11==0.12.0
idna==3.2
jmespath==0.10.0
-e git+ssh://git@github.com/bugout-dev/moonstream.git@b9c828fc7f811af88a9f3a45dd7f5c4053433366#egg=moonstreamdb&subdirectory=db
-e git+ssh://git@github.com/bugout-dev/moonstream.git@ad37dbd464fb9bb81907ab0b16b0e810e9da738f#egg=moonstreamdb&subdirectory=db
mypy==0.910
mypy-extensions==0.4.3
pathspec==0.9.0

Wyświetl plik

@ -1,11 +1,11 @@
{
"tx": {
"from": "0x52f200565581ae950c765b67f574cfc99f662657",
"gas": 400000,
"gasPrice": 12500000000,
"hash": "0xee3d2c14cacc0e5b8085c0b1a0cbacb6ed79762220dcee0a9c19a5a25e59a331",
"input": "0x6102a8610026600b82828239805160001a60731461001957fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100355760003560e01c80636e8af2721461003a575b600080fd5b6100576004803603602081101561005057600080fd5b50356100b2565b6040518083815260200180602001828103825283818151815260200191508051906020019060200280838360005b8381101561009d578181015183820152602001610085565b50505050905001935050505060405180910390f35b60048101546000906060908067ffffffffffffffff811180156100d457600080fd5b506040519080825280602002602001820160405280156100fe578160200160208202803683370190505b50915060005b8181101561017757600061014f670de0b6b3a764000061014688600401858154811061012c57fe5b6000918252602090912001546001600160a01b031661017e565b600f0b906101ff565b905080850194508084838151811061016357fe5b602090810291909101015250600101610104565b5050915091565b6000816001600160a01b031663ac969a73306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156101cd57600080fd5b505afa1580156101e1573d6000803e3d6000fd5b505050506040513d60208110156101f757600080fd5b505192915050565b60008161020e5750600061026c565b600083600f0b121561021f57600080fd5b600f83900b6fffffffffffffffffffffffffffffffff8316810260401c90608084901c026001600160c01b0381111561025757600080fd5b60401b811981111561026857600080fd5b0190505b9291505056fea2646970667358221220bf54788224a5a22890835d5e41e3e9622b1a055984390a38ae02a95c53dccfd864736f6c63430007030033",
"to": null,
"from": "0x2E337E0Fb68F5e51ce9295E80BCd02273d7420c4",
"gas": 2265656,
"gasPrice": 1000000000,
"hash": "0x5f0b6e212e55c7120f36fe6f88d46eb001c848064fd099116b42805bb3564ae6",
"value": 0,
"input": "0x606061026b61014039602061026b60c03960c05160a01c1561002057600080fd5b61014051600055610160516001556001546101805181818301101561004457600080fd5b80820190509050600255600254421061005c57600080fd5b61025356600436101561000d576101ec565b600035601c52600051631998aeef8114156100855760015442101561003157600080fd5b600254421061003f57600080fd5b600454341161004d57600080fd5b600660035460e05260c052604060c020805460045481818301101561007157600080fd5b808201905090508155503360035534600455005b341561009057600080fd5b633ccfd60b8114156100db5760063360e05260c052604060c0205461014052600060063360e05260c052604060c02055600060006000600061014051336000f16100d957600080fd5b005b63fe67a54b811415610124576002544210156100f657600080fd5b6005541561010357600080fd5b600160055560006000600060006004546000546000f161012257600080fd5b005b6338af3eed81141561013c5760005460005260206000f35b634f245ef78114156101545760015460005260206000f35b632a24f46c81141561016c5760025460005260206000f35b6391f901578114156101845760035460005260206000f35b63d57bde7981141561019c5760045460005260206000f35b6312fa6feb8114156101b45760055460005260206000f35b6326b387bb8114156101ea5760043560a01c156101d057600080fd5b600660043560e05260c052604060c0205460005260206000f35b505b60006000fd5b61006161025303610061600039610061610253036000f30000000000000000000000002e337e0fb68f5e51ce9295e80bcd02273d7420c40000000000000000000000000000000000000000000000000000000060d2b04a00000000000000000000000000000000000000000000000000000000616b46ca"
"value": 0
}
}