Example #1
0
def query_blocks_v1(params: Optional[dict], parse: bool) -> "ESSearch":
    """Returns block matching block id, with query parameters accepted.
    Args:
        block_id: string Block id to search for.
        params: string Lucene syntax acceptable query string for Elastic searching.
        parse: whether or not we should parse contents
    """
    if params:
        query_params = params.get(
            "q"
        ) or "*"  # default to returning all results (limit 10 by default)
        sort_param = params.get("sort") or "block_id:desc"
        limit_param = params.get("limit") or None
        offset_param = params.get("offset") or None
        _log.info(f"[BLOCK] QUERY STRING PARAMS FOUND: {query_params}")
        return elasticsearch.search("BLOCK",
                                    q=query_params,
                                    sort=sort_param,
                                    limit=limit_param,
                                    offset=offset_param,
                                    should_parse=parse)
    else:
        return elasticsearch.search("BLOCK",
                                    q="*",
                                    sort="block_id:desc",
                                    should_parse=parse)
Example #2
0
def query_contracts_v1(params: Optional[dict]) -> "ESSearch":
    """Lambda function used by the smartcontract endpoint with method GET.
        Returns smart contracts matching SC txn_type, with query parameters accepted.
    Args:
        contract_id (str, exclusive): SC contract_id to search for.
        txn_type (str, exclusive): SC txn_type to search for.
        params (dict, exclusive): Dict of params for Elastic searching.
    Returns:
        The Elastic search results of the query specified.
    """
    if params:
        query_params = params.get("q") or "*"  # default to returning all results (limit 10 by default)
        sort_param = params.get("sort") or None
        limit_param = params.get("limit") or None
        offset_param = params.get("offset") or None

        _log.info(f"QUERY STRING PARAMS FOUND: {query_params}")
        return elasticsearch.search(folder=smart_contract_dao.FOLDER, q=query_params, sort=sort_param, limit=limit_param, offset=offset_param)
    else:
        return elasticsearch.search(folder=smart_contract_dao.FOLDER, q="*")
def get_serial_contracts() -> list:
    """Searches for serial contracts"""
    results = elasticsearch.search(
        folder=FOLDER,
        query={"query": {
            "match_phrase": {
                "execution_order": "serial"
            }
        }})["results"]

    if results:
        return results

    raise exceptions.NotFound("No serial smart contracts found.")
def get_contract_by_txn_type(
        txn_type: str) -> "smart_contract_model.SmartContractModel":
    """Searches for a contract by txn_type"""
    results = elasticsearch.search(
        folder=FOLDER,
        query={"query": {
            "match_phrase": {
                "txn_type": txn_type
            }
        }})["results"]

    if len(results) > 0:
        return smart_contract_model.new_contract_at_rest(results[0])

    raise exceptions.NotFound(f"Smart contract {txn_type} could not be found.")
Example #5
0
def get_block_by_id_v1(block_id: str, parse: bool) -> Dict[str, Any]:
    """Searches for a block by a specific block ID
    Args:
        block_id: The block id to get
        parse: whether or not to parse the result automatically
    """
    results = elasticsearch.search(
        folder=block_dao.FOLDER,
        query={"query": {
            "match_phrase": {
                "block_id": block_id
            }
        }},
        should_parse=parse)["results"]

    if len(results) > 0:
        return results[0]

    raise exceptions.NotFound(f"Block {block_id} could not be found.")
Example #6
0
def get_by_txn_type_v1(txn_type: str) -> Dict[str, Any]:
    results = elasticsearch.search(folder=smart_contract_dao.FOLDER, query={"query": {"match_phrase": {"txn_type": txn_type}}})["results"]
    if results:
        return results[0]
    raise exceptions.NotFound(f"Smart contract {txn_type} could not be found.")