added support of `nft` address metadata in `address_info/`

pull/236/head
yhtiyar 2021-09-06 15:56:21 +03:00
rodzic c12d4f9a36
commit 1e55e987b4
2 zmienionych plików z 30 dodań i 3 usunięć

Wyświetl plik

@ -57,6 +57,7 @@ def get_contract_source_info(
class LabelNames(Enum):
ETHERSCAN_SMARTCONTRACT = "etherscan_smartcontract"
COINMARKETCAP_TOKEN = "coinmarketcap_token"
ERC721 = "erc721"
def get_ethereum_address_info(
@ -71,6 +72,7 @@ def get_ethereum_address_info(
address_info = data.EthereumAddressInfo(address=address)
etherscan_address_url = f"https://etherscan.io/address/{address}"
etherscan_token_url = f"https://etherscan.io/token/{address}"
blockchain_com_url = f"https://www.blockchain.com/eth/address/{address}"
# Checking for token:
coinmarketcap_label: Optional[EthereumLabel] = (
@ -87,7 +89,7 @@ def get_ethereum_address_info(
symbol=coinmarketcap_label.label_data["symbol"],
external_url=[
coinmarketcap_label.label_data["coinmarketcap_url"],
etherscan_address_url,
etherscan_token_url,
blockchain_com_url,
],
)
@ -107,6 +109,24 @@ def get_ethereum_address_info(
external_url=[etherscan_address_url, blockchain_com_url],
)
# Checking for NFT
# Checking for smart contract
erc721_label: Optional[EthereumLabel] = (
db_session.query(EthereumLabel)
.filter(EthereumLabel.address_id == id[0])
.filter(EthereumLabel.label == LabelNames.ERC721.value)
.order_by(text("created_at desc"))
.limit(1)
.one_or_none()
)
if erc721_label is not None:
address_info.nft = data.EthereumSmartContractDetails(
name=erc721_label.label_data.get("name"),
symbol=erc721_label.label_data.get("symbol"),
total_supplly=erc721_label.label_data.get("totalSupply"),
external_url=[etherscan_token_url, blockchain_com_url],
)
return address_info

Wyświetl plik

@ -3,6 +3,8 @@ Pydantic schemas for the Moonstream HTTP API
"""
from typing import List, Optional, Dict, Any
from sqlalchemy.sql.selectable import alias
from pydantic import BaseModel, Field
@ -160,18 +162,23 @@ class EthereumSmartContractSourceInfo(BaseModel):
class EthereumTokenDetails(BaseModel):
name: Optional[str]
symbol: Optional[str]
external_url: List[str] = []
external_url: List[str] = Field(default_factory=list)
class EthereumSmartContractDetails(BaseModel):
name: Optional[str]
external_url: List[str] = []
external_url: List[str] = Field(default_factory=list)
class EthereumNFTDetails(EthereumTokenDetails):
total_supply: Optional[int] = Field(alias="totalSupply")
class EthereumAddressInfo(BaseModel):
address: str
token: Optional[EthereumTokenDetails]
smart_contract: Optional[EthereumSmartContractDetails]
nft: Optional[EthereumNFTDetails]
class TxinfoEthereumBlockchainResponse(BaseModel):