Skip to content

Shreyas-ITB/VerusStatisticsAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VerusStatisticsAPI

This is a Multipurpose VerusCoin API is created to provide the information of the verus-ethereum bridge, it also provides a variety of different transaction handling functions, that you can use to fetch various different price information, weights, currencystate and many more.

API URL

http://116.203.53.84:5000

Endpoints

  • / Returns the API is running.
    • Docstring

      """
      The main entry point of the VerusCoin Multipurpose API.
      Returns a success message indicating that the API is running, along with the port number.
      """

      Code explanation

      This code defines a FastAPI endpoint that responds to GET requests at the root URL ("/"). The endpoint returns a success message indicating that the VerusCoin Multipurpose API is running, along with a reminder to use it responsibly.      
      
  • /price/<ticker> Returns the price of VRSC in different currencies and values along with the 24 hour change.
    • Docstring

      """
      Returns the current price of Verus Coin in the specified currency.
      Parameters:
      ticker (str): The currency to get the price in.
      Returns:
      dict: A dictionary containing the current price of Verus Coin in the specified currency,
          along with the 24 hour change.
      Raises:
      HTTPException: If an error occurs while fetching the price data.
      """

      Code explanation

      This code defines a FastAPI endpoint `/price/{ticker}` that retrieves the current price of Verus Coin in the specified currency (`{ticker}`) from the CoinGecko API and returns the response as JSON. If an error occurs, it raises an HTTP exception with a 500 status code and the error details.
      
  • /difficulty Returns the current network difficulty and formats it into readable form.
    • Docstring

      """
      Returns the current network difficulty and formats it into readable form.
      Parameters:
      None
      Returns:
      str: The formatted network difficulty.
      Raises:
      HTTPException: If an error occurs while fetching the difficulty data.
      """

      Code explanation

      This code defines a FastAPI endpoint `/difficulty` that retrieves the current network difficulty from the Verus explorer API, formats it into a readable string using the `diff_format` function, and returns the result. If an error occurs, it raises an HTTP exception with a 500 status code and the error details.
      
  • /getcurrencystate/<currency>/<height> Returns the currency state of bridged coins.
    • Docstring

      """
      Retrieves the currency state for a given currency and height.
      Args:
          currency (str): The currency to retrieve the state for.
          height (str): The height at which to retrieve the currency state.
      Returns:
          The currency state data.
      Raises:
          HTTPException: If an error occurs while retrieving the currency state.
      """
      
      """
      Retrieves the current state of a currency at a specified height.
      Parameters:
          currency (str): The name of the currency.
          height (int): The height at which to retrieve the currency state.
      Returns:
          dict: The response from the RPC request containing the currency state.
      """

      Code explanation

      This code defines a GET API endpoint `/getcurrencystate/{currency}/{height}`. It takes two path parameters: `currency` and `height`, and attempts to call the `getcurrencystate` function with these parameters. If successful, it returns the result. If an exception occurs, it raises an HTTP error with a 500 status code and includes the error message in the response. (`endpoints/index.py:routegetcurrencystate`)
      
      This function sends a POST request to the URL specified by `RPCURL` with a JSON payload containing the `getcurrencystate` method and parameters `currency` and `height`. It then returns the response from the server.
      
  • /decoderawtransaction/<hex> Returns the decoded data of a raw transaction.
    • Docstring

      """
      Decodes a raw transaction given its hexadecimal representation.
      Args:
          hex (str): The hexadecimal representation of the raw transaction.
      Returns:
          dict: The decoded transaction data.
      Raises:
          HTTPException: If an error occurs during the decoding process.
      """
      
      """
      Decodes a raw transaction.
      Parameters:
      hex (str): The raw transaction to be decoded.
      Returns:
      dict: A dictionary containing the decoded transaction data, or an error message if decoding fails.
      """

      Code explanation

      This code defines a FastAPI endpoint `/decoderawtransaction/{hex}` that decodes a raw transaction given its hexadecimal representation (`hex`). If successful, it returns the decoded data. If an error occurs, it raises an HTTP exception with a 500 status code and the error message. The actual decoding is handled by the `decode_rawtransaction` function, which is not defined in this snippet. (Source: `endpoints/index.py:decode_rawtransaction_route`)
      
      This is a Python function named `decode_rawtransaction` that takes a hexadecimal string `hex` as input. It constructs a request to a remote API (at URL `RPCURL`) to decode the raw transaction data represented by the input `hex`. The function sends the request, handles any exceptions that may occur, and returns the decoded transaction data if successful, or an error message if not.
      
  • /getrawtransaction/<txid> Returns the raw transaction details.
    • Docstring

      """
      This function handles a GET request to retrieve the state of a specific currency at a given block height.
      Args:
          currency (str): The currency for which to retrieve the state.
          height (int): The block height at which to retrieve the currency state.
      Returns:
          The state of the currency at the specified block height.
      Raises:
          HTTPException: If an error occurs while retrieving the currency state.
      """
      
      """
      Retrieves the raw transaction data for a given transaction ID.
      Args:
          txid (str): The ID of the transaction.
      Returns:
          dict: A dictionary containing the raw transaction data, or an error message if the request fails.
      """

      Code explanation

      This code defines a FastAPI endpoint `/getrawtransaction/{txid}` that retrieves raw transaction data by transaction ID (`txid`). If successful, it returns the data. If an error occurs, it raises an HTTP exception with a 500 status code and the error message. 
      The actual retrieval of raw transaction data is handled by the `get_rawtransaction` function, which is not defined in this snippet.        
      
      This is a Python function named `get_rawtransaction` that takes a `txid` (transaction ID) as input and returns the raw transaction data associated with it. 
      Here's a step-by-step breakdown:
      1. It constructs a `requestData` dictionary that contains the details of an HTTP POST request to be sent to a URL specified by `RPCURL`.
      2. The request data includes the `txid` and an `id` field set to 2.
      3. It attempts to send the request using the `send_request` function and store the response.
      4. If the response is successful, it extracts the raw transaction data from the response and returns it.
      5. If any exception occurs during this process, it catches the error, converts it to a string, and returns it as a dictionary with a single key-value pair (`"error": error_message`).
      
  • /blockcount Returns the block height of verus.
    • Docstring

      """
      Returns the latest block count from the Verus blockchain.
      Parameters:
      None
      Returns:
      data (dict): The latest block count data.
      Raises:
      HTTPException: If an error occurs while fetching the block count data.
      """
      
      """
      Retrieves the latest block information from the blockchain.
      Returns:
          The latest block data if successful, otherwise an error message.
      Note:
          This function sends a POST request to the RPC URL with the 'getinfo' method.
      """

      Code explanation

      This code defines a FastAPI endpoint that responds to GET requests at the `/blockcount` path. When called, it attempts to retrieve the latest block data using the `latest_block()` function. If successful, it returns the data. If an exception occurs, it raises an HTTP error with a 500 status code and includes the error message as a string.
      
      This function sends a POST request to the `RPCURL` with a JSON payload containing the method "getinfo" and returns the latest block information from the response. If the request fails, it returns an error message.
      
  • /getticker/<currency_id> Returns the ticker of the given currencyID.
    • Docstring

      """
      Returns the ticker of the given currencyID.
      Parameters:
      currency_id (str): The ID of the currency.
      Returns:
      dict: A dictionary containing the ticker of the given currencyID.
      Raises:
      HTTPException: If an error occurs while fetching the ticker data.
      """
      
      """
      Retrieves the ticker symbol associated with a given currency ID.
      Parameters:
          currency_id (str): The ID of the currency to retrieve the ticker symbol for.
      Returns:
          str: The ticker symbol associated with the given currency ID, or "Currency not found" if no match is found.
      """

      Code explanation

      This code defines a FastAPI endpoint `/getticker/{currency_id}` that retrieves the ticker symbol for a given `currency_id`. It calls the `get_ticker_by_currency_id` function to fetch the ticker and returns it as a JSON response. If an error occurs, it raises a 500 Internal Server Error with the error details.    
      
      This function takes a `currency_id` as input and returns the corresponding `ticker` from the `arr_currencies` list if found, otherwise returns "Currency not found".
      
  • /getcurrid/<ticker> Returns currencyid of a currency when ticker is provided.
    • Docstring

      """
      Returns the currency ID associated with the provided ticker symbol.
      Parameters:
          ticker (str): The ticker symbol to retrieve the currency ID for.
      Returns:
          dict: A dictionary containing the currency ID, with the key "currencyid".
      Raises:
          HTTPException: If an error occurs while retrieving the currency ID.
      """
      
      """
      Retrieves the currency ID associated with a given ticker symbol.
      Parameters:
          ticker (str): The ticker symbol to search for.
      Returns:
          str: The currency ID if found, otherwise "Currency not found".
      """

      Code explanation

      This code defines a FastAPI endpoint `/getcurrid/{ticker}` that takes a `ticker` as input, attempts to retrieve the corresponding `currencyid` using the `get_currencyid_by_ticker` function, and returns it as a JSON response. If an error occurs during this process, it raises an HTTP exception with a 500 status code and the error message.
      
      This function takes a `ticker` as input and returns the corresponding `currencyid` from the `arr_currencies` list if found. If no match is found, it returns the string "Currency not found".
      
  • /fetchblockhash/<longest_chain> Returns the fetched blockhash.
    • Docstring

      """
      Fetches the block hash for a given longest chain.
      Parameters:
      longest_chain (str): The longest chain for which to fetch the block hash.
      Returns:
      dict: A dictionary containing the block hash data. If an error occurs, returns a dictionary with an "error" key.
      """

      Code explanation

      This code defines a GET API endpoint `/fetchblockhash/{longest_chain}` that fetches a block hash from a remote server. It sends a POST request to the server with the `longest_chain` parameter and returns the block hash data in the response. If an error occurs, it returns an error message.
      
  • /fetchtransactiondata/<transaction_id> Returns the transaction data of a transaction ID.
    • Docstring

      """
      Fetches transaction data by transaction ID.
      This function sends a GET request to the '/fetchtransactiondata/{transaction_id}' endpoint,
      retrieves the raw transaction data, decodes it, and returns the decoded transaction data.
      Args:
          transaction_id (str): The ID of the transaction to fetch data for.
      Returns:
          dict: A dictionary containing the decoded transaction data, or an error message if the request fails.
      """

      Code explanation

      This code defines a route `/fetchtransactiondata/{transaction_id}` that retrieves and decodes transaction data from a remote API. 
      Here's a step-by-step breakdown:
      1. It sends a POST request to the `RPCURL` with the `getrawtransaction` method and the provided `transaction_id`.
      2. It attempts to retrieve the raw transaction data from the response.
      3. If successful, it sends another POST request to the `RPCURL` with the `decoderawtransaction` method and the raw transaction data.
      4. It attempts to retrieve the decoded transaction data from the response.
      5. If both steps are successful, it returns the decoded transaction data. If any error occurs, it returns an error message.
      Note that the code is currently simulating the responses, and you should replace the simulated responses with the actual transaction data in a real implementation.
      
  • /getmoneysupply Returns the money supply of VRSC.
    • Docstring

      """
      Retrieves the current money supply from the Verus Explorer API.
      Returns:
      -------
      tuple
          A tuple containing the money supply data as a string and a success message.
      """

      Code explanation

      This code defines a FastAPI endpoint (`/getmoneysupply`) that makes a GET request to the Verus Explorer API to retrieve the money supply data and returns the response text along with a success message. `{endpoints/index.py:getmoneysupply}` 
      
  • /getrawmempool Returns all the unconfirmed transactions on the bridge.
    • Docstring

      """
      This function handles a GET request to retrieve the raw mempool data.
      It sends a POST request to the RPC URL with the 'getrawmempool' method and 
      returns the response result and the count of mempool entries.
      Args:
          None
      Returns:
          A dictionary containing the raw mempool data and its count, or an error 
          message if the request fails.
      """

      Code explanation

      This code defines a FastAPI endpoint `/getrawmempool` that sends a POST request to the URL specified by `RPCURL` to retrieve the raw mempool data. It then processes the response, extracts the mempool data and its count, and returns them as a JSON object. If an error occurs during this process, it catches the exception and returns an error message instead.    
      
  • /distribution Returns the distribution of VRSC in the network.
    • Docstring

      """
      Retrieves the distribution of VRSC in the network.
      Returns:
      -------
      dict
          A dictionary containing the distribution data.
      """

      Code explanation

      This code defines a FastAPI endpoint `/distribution` that retrieves and returns the distribution data from the Verus Explorer API. 
      Here's a step-by-step breakdown:
      1. The `@app.get('/distribution')` decorator indicates that this function handles GET requests to the `/distribution` endpoint.
      2. The function sends a GET request to the Verus Explorer API at the URL `https://explorer.verus.io/ext/getdistribution`.
      3. The response from the API is stored in the `resp` variable.
      4. The function returns the response data in JSON format using `resp.json()`.   
      
  • /getnethashpower Returns the network hashrate and formats it into readable form.
    • Docstring

      """
      Retrieves the network hash power from the Verus API.
      Returns:
          tuple: A tuple containing the formatted hash rate and a success message.
      """

      Code explanation

      This code defines an API endpoint `/getnethashpower` that retrieves the current network hash power from the Verus Insight API, formats the result as a human-readable hash rate, and returns it along with a success message.     
      
  • /getimports/<currency> Returns the import details of the currency provided on the current block height.
    • Docstring

      """
      Handles GET requests to retrieve imports for a specific currency.
      Parameters:
      currency (str): The currency for which to retrieve imports.
      Returns:
      The response containing the imports for the specified currency.
      Raises:
      HTTPException: If an error occurs during the request, with a status code of 500.
      """
      
      """
      Retrieves imports for a given currency.
      Args:
          currency (str): The currency for which to retrieve imports.
      Returns:
          dict: A JSON response containing the imports for the specified currency.
      """

      Code explanation

      This code defines a GET API endpoint `/getimports/{currency}` that takes a `currency` parameter as a string. It calls the `get_imports` function with the provided `currency` and returns the response. If any exception occurs, it raises an HTTP exception with a 500 status code and the error message. 
      
      This function sends a POST request to the URL specified by `RPCURL` with a JSON payload containing the `currency` parameter, and returns the JSON response. The request is made using the `send_request` function, which is not shown in this snippet.
      
  • /getimports_blk/<currency>/<fromblock>/<toblock> Returns the import details of the currency from block to block.
    • Docstring

      """
      Handles GET requests to retrieve imports with block information.
      Parameters:
          currency (str): The currency for which to retrieve imports.
          fromblk (int): The starting block number.
          toblk (int): The ending block number.
      Returns:
          The response from the get_imports_with_blocks function.
      """
      
      """
      Retrieves imports with blocks for a given currency and block range.
      Args:
          currency (str): The currency to retrieve imports for.
          fromblk (int): The starting block number.
          toblk (int): The ending block number.
      Returns:
          dict: A JSON response containing the imports with blocks.
      """

      Code explanation

      This code defines a FastAPI endpoint `/getimports_blk/{currency}/{fromblk}/{toblk}/` that accepts three path parameters: `currency`, `fromblk`, and `toblk`. It calls the `get_imports_with_blocks` function with these parameters and returns the response.  
      
      This function sends a POST request to the URL specified by `RPCURL` with a JSON payload containing the `currency`, `fromblk`, and `toblk` parameters. It then returns the JSON response from the server.
      
  • /getvolume/<currencyid>/<currency>/<fromblk>/<toblk> Returns the total reservein and reserveout volumes of a specific currency on the bridge.
    • Docstring

      """
      Retrieves the volume of a specific currency within a given block range.
      Args:
          currencyid (str): The ID of the currency.
          currency (str): The name of the currency.
          fromblk (int): The starting block number.
          toblk (int): The ending block number.
      Returns:
          tuple: A tuple containing the calculated reserve balance and a success message.
      """
      
      """
      Calculates the reserve balance for a given currency.
      Args:
          currencyid (str): The ID of the currency.
          currency (str): The name of the currency.
      Returns:
          dict: A dictionary containing the currency ID, currency name, reserve in, and reserve out.
              If an error occurs, returns a dictionary with an error message.
      """

      Code explanation

      This code defines a GET API endpoint `/getvolume/{currencyid}/{currency}/{fromblk}/{toblk}` that calculates and returns the reserve balance for a given currency within a specified block range.
      The endpoint takes four path parameters:
      * `currencyid`: a string representing the currency ID
      * `currency`: a string representing the currency
      * `fromblk`: an integer representing the starting block number
      * `toblk`: an integer representing the ending block number
      The function calls `calculate_reserve_balance` with these parameters and returns the response along with a success message.
      
      This function calculates the reserve balance for a specific currency. It takes a `currencyid` and `currency` as input, retrieves JSON data using the `get_imports` function, and then parses the data to find the reserve balance for the specified currency. The function returns a dictionary containing the currency ID, currency name, and reserve balance (in and out). If any errors occur during parsing, it returns an error message.
      
  • /gettotalvolume/<currency>/<fromblk>/<toblk> Returns the total reservein, reserveout, primarycurrencyin, primarycurrencyout and conversionfees of all the currencies present in the basket.
    • Docstring

      """
      Retrieves the total volume of a given currency within a specified block range.
      Parameters:
      currency (str): The currency for which to retrieve the total volume.
      fromblk (int): The starting block number of the range.
      toblk (int): The ending block number of the range.
      Returns:
      tuple: A tuple containing the total volume and a success message.
      """
      
      """
      Calculates the total balances for a given currency.
      Args:
          currency (str): The currency for which to calculate the total balances.
      Returns:
          dict: A dictionary containing the total reserve in, total reserve out, total conversion fees,
              total primary currency in, and total primary currency out, all in DAI.
              If an error occurs, returns a dictionary with an "error" key containing the error message.
      """

      Code explanation

      This code defines a GET API endpoint `/gettotalvolume/{currency}/{fromblk}/{toblk}` that calculates the total volume of a given currency between two block numbers (`fromblk` and `toblk`). The `calculate_total_balances` function is called with the provided parameters, and the response is returned along with a success message.
      
      This function calculates total balances for a given currency. It retrieves data from an external source using `get_imports(currency)`, then iterates through the data to calculate total reserve in, reserve out, conversion fees, primary currency in, and primary currency out. The results are returned in a dictionary, with values converted to DAI using the DAI reserve price. If any errors occur during the process, an error message is returned instead. 
      
      This function appears to be part of a larger system that interacts with a cryptocurrency or blockchain, given the references to DAI reserves and currency states.
      
  • /gettransactions/<currency>/<fromblk>/<toblk> Returns all the transactions of a specific basket in the given block interval.
    • Docstring

      """
      Retrieves a list of transactions for a given currency within a specified block range.
      Args:
          currency (str): The currency for which to retrieve transactions.
          fromblk (int): The starting block number for the transaction range.
          toblk (int): The ending block number for the transaction range.
      Returns:
          A list of transactions for the specified currency and block range.
      """
      
      """
      Extracts transfer data for a given currency.
      Parameters:
      currency (str): The currency for which to extract transfer data.
      Returns:
      list: A list of transfer data, where each item is a tuple containing the transfers, export txid, and import txid.
      dict: An error dictionary with a string error message if an exception occurs.
      """

      Code explanation

      This code defines a GET API endpoint `/gettransactions/{currency}/{fromblk}/{toblk}` that accepts three path parameters: `currency`, `fromblk`, and `toblk`. It calls the `extract_transfers` function with these parameters and returns the response.
      
      This function `extract_transfers` takes a `currency` string as input, retrieves import data for that currency using `get_imports`, and then extracts transfer information from the data. It returns a list of transfer data, or an error message if an exception occurs. 
      Note that the function is defined in `functions/extracttransfers.py`, and it uses the `get_imports` function from `functions/getimports.py` (as seen in the provided context).
      
  • /getaddressbalance/<address> Returns the balance of the given address.
    • Docstring

      """
      This function handles a GET request to retrieve the balance of a given address.
      Parameters:
      address (str): The address for which to retrieve the balance.
      Returns:
      response: The balance of the given address.
      """
      
      """
      Retrieves the balance of a given address by sending a POST request to the RPC URL.
      Args:
          address (str): The address for which to retrieve the balance.
      Returns:
          dict: A dictionary containing the balance data if the request is successful, otherwise an error message.
      """

      Code explanation

      This code defines a GET API endpoint `/getaddressbalance/{address}` that takes an `address` as a path parameter, converts it to a string (although it's already a string), and then calls the `get_address_balance` function with this address. The response from this function is then returned by the API endpoint.
      Note: The conversion to string `newaddress = str(address)` is unnecessary since `address` is already defined as a string `address: str`.
      
      This function sends a POST request to the URL specified by `RPCURL` to retrieve the balance of a given cryptocurrency address. It returns the response data in JSON format if the request is successful (200 status code), otherwise it returns an error message.
      
  • /getbasketinfo/ Returns all the basket currency information.
    • Docstring

      """
      Returns a list of basket information.
      This endpoint retrieves all baskets using the `getallbaskets` function and 
      then fetches the currency converter data for each basket using the 
      `get_currencyconverters` function. The resulting data is returned as a list.
      Returns:
          list: A list of dictionaries containing basket information.
      Raises:
          HTTPException: If an error occurs during execution, a 500 error is raised 
              with the exception details.
      """
      
      """
      Retrieves all DeFiChain baskets by sending a POST request to the RPC URL with a JSON payload containing the method 'getcurrencyconverters' and parameter 'VRSC'.
      Returns:
          tuple: A tuple containing two lists. The first list contains the fully qualified names of the baskets, and the second list contains the corresponding i-strings.
      Raises:
          None
      Notes:
          If the response format is unexpected, it prints an error message and returns two empty lists.
      """
      
      """
      Retrieves currency converter data for a given basket name.
      Parameters:
          basket_name (str): The name of the basket to retrieve data for.
      Returns:
          dict or None: A dictionary containing the processed data, including initial supply, supply, start block, block number, and volume, as well as reserve and price information for each reserve currency. Returns None if no data is available.
      Notes:
          This function sends a POST request to a specific URL based on the basket name, processes the response data, and extracts various information.
      """

      Code explanation

      This is a FastAPI endpoint that retrieves and returns information about all baskets. 
      Here's a succinct breakdown:
      1. It calls `getallbaskets()` to retrieve a list of baskets and their corresponding i-addresses.
      2. It loops through each basket, calling `get_currencyconverters(basket)` to retrieve additional information about the basket.
      3. If the additional information is available, it appends it to the `data` list.
      4. Finally, it returns the list of basket information.
      If any exception occurs during this process, it catches the exception, raises an HTTPException with a 500 status code, and includes the exception details in the response.     
      
      This function, `getallbaskets()`, sends a POST request to the URL specified by `RPCURL` with a JSON payload containing the method `getcurrencyconverters` and parameter `VRSC`. It then parses the response, expecting a dictionary with a `result` key containing a list of items. For each item, it extracts the `fullyqualifiedname` and a key starting with `i` and of length 34, and returns these values as two separate lists. If the response format is unexpected, it prints an error message and returns two empty lists.
      
      This is a Python function named `get_currencyconverters` that retrieves and processes data about currency converters for a given `basket_name`. Here's a succinct explanation:
      1. The function retrieves various data points, including:
        * Latest block information (`networkblocks`)
        * DAI reserves (`reserves`)
        * DAI price (`resp`)
        * Basket supply (`supply`)
      2. Based on the `basket_name`, the function sends a POST request to a specific URL (either `VARRRRPCURL`, `VDEXRPCURL`, or `RPCURL`) to retrieve currency converter data.
      3. The function processes the response data, extracting information about each currency converter, including:
        * Initial supply
        * Start block
        * Reserve in and out values
        * Reserve currencies and their prices
      4. The function calculates the total volume and creates an output dictionary containing the processed data.
      5. The output dictionary includes the bridge name, initial supply, supply, start block, block number, and volume, as well as reserve and price information for each reserve currency.
      The function appears to be designed to provide data about liquidity pools and their associated tokens, including reserve values, prices, and fees. However, without more context about the specific use case or the system it's part of, it's difficult to provide a more detailed explanation.
      **Source:** This explanation is based on the provided code snippet from `functions/getcurrencyconverters.py:get_currencyconverters`. 
      
  • /getcurrencyvolumes Returns the currencyvolumes as per 24 hours.
    • Docstring

      """
      This function handles GET requests to the '/getcurrencyvolumes' endpoint. 
      It calls the calculatevolumeinfo function to retrieve currency volume information.
      Returns:
          jsond: A JSON object containing currency volume data.
      """
      
      """
      This function calculates and returns volume information for all baskets.
      It first retrieves the latest block number and calculates the volume block number.
      Then, it iterates over each basket to get the currency volume information.
      Parameters:
      None
      Returns:
      dict: A dictionary containing volume information for each basket.
      """

      Code explanation

      This code defines a GET API endpoint `/getcurrencyvolumes` that returns JSON data calculated by the `calculatevolumeinfo()` function.
      
      This function calculates the volume information for a list of baskets. Here's a breakdown:
      1. It gets the current block number (`currblock`) and calculates a block interval (`blockint`) 1440 blocks ago.
      2. It retrieves a list of baskets and their addresses using `getallbaskets()`.
      3. It then loops through each basket, calling `getcurrencyvolumeinfo()` to retrieve volume information for that basket within the calculated block interval.
      4. The volume information is stored in a dictionary (`data`) with the basket as the key.
      5. Finally, the function returns the dictionary containing volume information for all baskets.
      In essence, this function aggregates volume data for a set of baskets over a specific block interval.
      

Market Endpoints

  • /market/allTickers Returns all the basket currencies as pairs with high/low/close volume information as well as the total volume information of each basket in a 24 hour period. Note that this endpoint returns the currency prices in the currency VRSC. Since VRSC is in every basket, it makes more sense to standardize volumes in VRSC and all volumes are aggregated. Any basket with no transactions in 24 hour period will not show up in this API endpoint, if any listing partners want to use USD prices then they can easily convert the prices from VRSC to USD by themselves, as all the currency volume information are given out in Verus!

    • Docstring

      """
      This function handles the '/market/allTickers' endpoint, 
      gathering and processing market data for various ticker symbols.
      It retrieves the latest block number, calculates the volume block number, 
      and fetches market tickers for different baskets. The function then 
      processes the tickers, adjusting their symbols and names as needed, 
      and combines them into a single list.
      The function returns a dictionary containing the timestamp and the 
      processed ticker information.
      Parameters:
      None
      Returns:
      dict: A dictionary with a 'code' key and a 'data' key. The 'data' key 
          contains a dictionary with 'time' and 'ticker' keys, where 'time' 
          is the timestamp and 'ticker' is the list of processed tickers.
      """
      
      """
      Retrieves all baskets by sending a POST request to the RPC URL with the method 'getcurrencyconverters' and parameter 'VRSC'.
      Returns:
          tuple: A tuple containing two lists. The first list contains fully qualified names and the second list contains i-strings.
      """
      
      """
      Retrieves the latest block information from the blockchain.
      Returns:
          dict: The latest block information, or an error message if the request fails.
      """
      
      """
      This function is used to retrieve market ticker information for a given set of baskets.
      Parameters:
      baskets (list): A list of baskets to retrieve market ticker information for.
      volblock (int): The volume block to use for retrieving market ticker information.
      latestblock (int): The latest block to use for retrieving market ticker information.
      ticker_infovrsc (list): A list to store the retrieved market ticker information for VRSC.
      ticker_infodai (list): A list to store the retrieved market ticker information for DAI.
      ticker_infoeth (list): A list to store the retrieved market ticker information for ETH.
      ticker_infomkr (list): A list to store the retrieved market ticker information for MKR.
      ticker_infotbtc (list): A list to store the retrieved market ticker information for TBTC.
      excluded_pairs (list): A list of pairs to exclude from the retrieved market ticker information.
      Returns:
      tuple: A tuple containing the retrieved market ticker information for VRSC, DAI, ETH, MKR, and TBTC.
      """

      Code explanation

      This is a Python function that appears to be part of a web application, specifically a route handler for the `/market/allTickers` endpoint. The function retrieves and processes market ticker data for various cryptocurrencies and returns the data in a JSON response.
      Here's a high-level overview of what the function does:
      1. It retrieves the latest block number and calculates a timestamp.
      2. It calls the `getallbaskets()` function to retrieve a list of baskets (not shown in the code snippet).
      3. It calls the `getmarkettickers()` function to retrieve market ticker data for various cryptocurrencies, passing in the baskets, block numbers, and other parameters.
      4. It processes the retrieved ticker data by iterating over each ticker and modifying its symbol and symbol name if necessary.
      5. It combines the processed ticker data into a single list.
      6. It returns a JSON response with a code, timestamp, and the combined ticker data.
      The function appears to be designed to handle a large amount of data and perform various data transformations and filtering operations. However, without more context or information about the surrounding codebase, it's difficult to provide a more detailed explanation.
      
      This code snippet defines a function called `getmarkettickers` that takes several parameters: `baskets`, `volblock`, `latestblock`, `ticker_infovrsc`, `ticker_infodai`, `ticker_infoeth`, `ticker_infomkr`, `ticker_infotbtc`, and `excluded_pairs`. 
      
      The function iterates over each `basket` in `baskets` and performs the following steps:
      1. Calls the `getcurrencyvolumeinfo` function with the `basket`, `volblock`, `latestblock`, `1440`, and `"VRSC"` as arguments. If the returned `volume_info` is not `None`, it iterates over each `pair` in `volume_info`.
      2. Checks if the currency or convertto in the pair is "VRSC" or "DAI" or "ETH" or "MKR" or "TBTC". If so, it removes the ".vETH" suffix and 'v' prefix from the currency names.
      3. If the currency or convertto is one of the specified currencies, it calculates weights based on the volume of the pair.
      4. It then calculates the last, high, low, and open values based on the weights and the corresponding values in the pair.
      5. It appends a dictionary containing the symbol, symbolName, volume, last, high, low, and open values to the `ticker_infovrsc`, `ticker_infodai`, `ticker_infoeth`, `ticker_infomkr`, or `ticker_infotbtc` list, depending on the currency.
      6. After processing all the pairs for each basket, it combines the reverse pairs by summing the volumes and calculating the combined values based on the weights.
      7. Finally, it returns the combined values as lists for each ticker type (vrsc, dai, eth, mkr, tbtc).
      The purpose of this code snippet seems to be to retrieve market ticker information for various currencies based on their volume and calculate combined values for reverse pairs.
      
      This function sends a POST request to the URL specified by `RPCURL` with a JSON payload to retrieve currency volume information. It then attempts to parse the response to extract volume pairs and volume for a specific interval, returning these values if they exist, or `None` otherwise.
      
  • /gettvl Returns the Total Value Locked on the network (not being used ATM by any platforms).

    • Docstring

      """
      This function handles a GET request to retrieve the total value locked (TVL) in the network.
      It fetches the baskets and their corresponding i_addresses, then processes each basket to 
      retrieve its currency converter information. The function then calculates the prices and 
      balances of DAI, ETH, and Verus Coin, as well as the token balances and their USD values.
      Finally, it returns a JSON response containing the token balances, including the DAI and 
      ETH prices, balances, and the network TVL.
      Returns:
          A JSON response with a status code and a data object containing the token balances.
      """
      
      """
      Retrieves all baskets from the RPC server.
      This function sends a POST request to the RPC server with the method 'getcurrencyconverters' and parameter 'VRSC'.
      It then parses the response and extracts the fully qualified names and i-strings of the baskets.
      Returns:
          tuple: A tuple containing two lists. The first list contains the fully qualified names of the baskets,
              and the second list contains the corresponding i-strings.
      """
      
      """
      Retrieves and processes currency converter data for a given basket name.
      Parameters:
          basket_name (str): The name of the basket for which to retrieve data.
      Returns:
          dict or None: A dictionary containing the processed data, or None if no data is available.
      """
      
      """
      Retrieves the current price of DAI cryptocurrency.
      Returns:
          Decimal: The current price of DAI in USD.
      """
      
      """
      Retrieves the DAI value by making an Ethereum call to the specified contract.
      This function uses the Web3 library to create a function signature and encode the query address.
      It then constructs an API request to Etherscan to perform the Ethereum call and retrieve the result.
      The result is then converted from Wei to Ether and returned.
      Parameters:
          None
      Returns:
          float: The DAI value in Ether.
      """
      
      """
      Retrieves the current price of Ethereum (ETH) in USD.
      Returns:
          Decimal: The current price of ETH in USD.
      """
      
      """
      Retrieves the Ethereum balance for a given address.
      Args:
          address (str): The Ethereum address to retrieve the balance for.
      Returns:
          Decimal: The Ethereum balance for the given address.
      """
      
      """
      Retrieves the current price of Verus Coin from Yahoo Finance.
      Returns:
          Decimal: The current price of Verus Coin.
      """
      
      """
      Retrieves the token balance for a given token contract and address.
      
      Parameters:
      token_contract (str): The contract address of the token.
      decimals (int): The number of decimal places for the token balance.
      
      Returns:
      Decimal: The token balance.
      """
      
      """
      Retrieves the current price of a token in USD from the CoinGecko API.
      Args:
          token_contract (str): The contract address of the token.
          retries (int, optional): The number of times to retry the request if it fails. Defaults to 5.
          delay (int, optional): The initial delay between retries in seconds. Defaults to 1.
      Returns:
          Decimal: The current price of the token in USD.
      Raises:
          KeyError: If the token contract is not found in the API response.
          requests.exceptions.RequestException: If the request to the API fails.
      """

      Code explanation

      This is a Python function named `gettvl` that is decorated with `@app.get('/gettvl')`, indicating it's an API endpoint that responds to GET requests at the `/gettvl` path.
      The function calculates and returns various financial metrics, including:
      1. Token balances and their USD values
      2. Network Total Value Locked (TVL)
      3. Reserves_0 values and their USD values
      4. ETH and DAI prices and balances
      It does this by calling other functions to retrieve prices, balances, and other data, and then performing calculations to derive the desired metrics.
      The function returns a JSON response with a "code" and a "data" section. The "data" section contains a dictionary with the calculated metrics.
      If an error occurs during execution, the function catches the exception and returns a JSON response with a "code" of 500000 and an error message.
      This function, `getallbaskets()`, sends a POST request to the URL specified by `RPCURL` with a JSON payload containing the method `getcurrencyconverters` and parameter `VRSC`. It then parses the response, extracting fully qualified names and i-strings from the result, and returns them as two separate lists. If the response format is unexpected, it prints an error message and returns two empty lists.
      
      This is a Python function named `get_currencyconverters` that retrieves and processes currency converter data for a given basket name. Here's a succinct explanation:
      **Functionality:**
      1. The function takes a `basket_name` as input and retrieves various data points, including:
        * Latest block information (`networkblocks`)
        * DAI reserves (`reserves`)
        * DAI price (`resp`)
        * Basket supply (`supply`)
      2. Based on the `basket_name`, the function sends a POST request to a specific URL (either `VARRRRPCURL`, `VDEXRPCURL`, or `RPCURL`) to retrieve currency converter data.
      3. The function processes the response data, extracting various information, including:
        * Initial supply
        * Start block
        * Reserve in and out values
        * Reserve currencies and their prices
      4. The function calculates the total volume and creates an output dictionary containing the processed data.
      5. The output dictionary includes the bridge name, initial supply, supply, start block, block number, and volume, as well as reserve and price information for each reserve currency.
      **Context:**
      This function appears to be part of a larger system that interacts with a blockchain or cryptocurrency platform. The `basket_name` input suggests that the function is designed to work with specific baskets or assets on the platform. The use of URLs like `VARRRRPCURL` and `VDEXRPCURL` implies that the function is interacting with external APIs or services.
      
      This function retrieves the current price of DAI cryptocurrency in USD from Yahoo Finance. It uses the `yfinance` library to fetch the historical data for the last day and returns the closing price as a Decimal value.
      
      This function retrieves the DAI value by making an Ethereum call to a specified contract. It uses the Web3 library to create a function signature and encode a query address, then sends a request to Etherscan to perform the Ethereum call and retrieve the result. The result is converted from Wei to Ether and returned.
      **Specifically:**
      * It uses the `Web3` library to interact with the Ethereum blockchain.
      * It creates a function signature using the `keccak` hash function.
      * It encodes a query address using `web3.to_hex` and `web3.to_bytes`.
      * It sends a request to Etherscan to perform an Ethereum call using `requests.get`.
      * It extracts the result from the response and converts it from Wei to Ether using `web3.from_wei`.
      **Context:** This function is likely used in a cryptocurrency or blockchain-related application, specifically to retrieve the value of DAI (a stablecoin) from a smart contract.
      
      This function retrieves the current price of Ethereum (ETH) in USD from Yahoo Finance. It returns the closing price of ETH for the most recent trading day as a Decimal value.
      
      This function retrieves the current Ethereum balance for a given address from the Etherscan API and returns it as a Decimal value in Ether (not Wei).
      
      This function retrieves the current price of Verus Coin from Yahoo Finance. It uses the `yfinance` library to fetch the historical data for the last day, and then returns the closing price of the most recent trading day as a decimal value.
      
      This function retrieves the balance of a specific token for a given Ethereum address using the Etherscan API.
      It takes two parameters:
      * `token_contract`: the contract address of the token
      * `decimals`: the number of decimal places the token uses
      The function returns the balance of the token as a Decimal object.
      
      This function retrieves the current price of a token in USD from the CoinGecko API. It attempts to make the request up to `retries` times, waiting `delay` seconds between attempts, and doubling the delay after each failure (exponential backoff). If all attempts fail, it raises an exception or prints an error message.
      
  • /getdefichaininfo Returns all the baskets in the network along with their currencyids, currencies inside the basket and their currencyids with their reserve and priceinreserves.

    • Docstring

      """
      Retrieves DeFiChain information.
      This function fetches the latest DeFiChain data, processes it, and returns the results.
      It handles potential exceptions and returns error messages accordingly.
      Returns:
          dict: A dictionary containing the result code, timestamp, and DeFiChain data.
      """
      
      """
      Retrieves all baskets from the RPC server.
      This function sends a POST request to the RPC server with the method 'getcurrencyconverters' and parameter 'VRSC'.
      It then processes the response, extracting fully qualified names and i-strings from the result.
      Returns:
          tuple: A tuple containing two lists: fully qualified names and i-strings.
      """
      
      """
      Retrieves all baskets from the RPC server.
      This function sends a POST request to the RPC server with the method 'getcurrencyconverters' and parameter 'VRSC'.
      It then processes the response, extracting fully qualified names and i-strings from the result.
      Returns:
          tuple: A tuple containing two lists: fully qualified names and i-strings.
      """

      Code explanation

      This code defines a FastAPI endpoint `/getdefichaininfo` that:
      1. Retrieves all DeFiChain baskets using `getallbaskets()`.
      2. For each basket, it calls `getdefichain(basket)` and appends the results to a list `output`.
      3. Returns a JSON response with a timestamp, and the aggregated results.
      It also handles exceptions:
      * If an `HTTPException` occurs, it returns a 500 error with the exception details.
      * If any other exception occurs, it returns a 500 error with a generic error message.
      
      This function, `getallbaskets()`, sends a POST request to the URL specified by `RPCURL` with a JSON payload containing the method `getcurrencyconverters` and parameter `VRSC`. It then parses the response, expecting a dictionary with a `result` key containing a list of items. For each item, it extracts the `fullyqualifiedname` and a key starting with `i` and of length 34, and returns these values as two separate lists. If the response format is unexpected, it prints an error message and returns two empty lists.
      
      This is a Python function named `getdefichain` that takes a `basket` parameter. The function appears to be part of a larger system that interacts with a cryptocurrency exchange or a blockchain.
      Here's a succinct summary of what the function does:
      1. It retrieves various data from external sources, including:
        * Reserve values from the `dai_reserves` function.
        * The latest block number from the `latest_block` function.
        * Volume information for the specified `basket` from the `getdefivolume` function.
      2. It sends a request to an API (using the `send_request` function) to retrieve data about currency converters for the specified `basket`.
      3. It processes the response data, extracting information about each currency converter, including:
        * Fully qualified names.
        * I-addresses.
        * Reserve values.
        * Price in reserve values.
        * Currency IDs.
        * Tickers.
        * Fees (although this is currently commented out).
      4. It formats the extracted data into a list of dictionaries, where each dictionary represents a liquidity pool (LP) with its associated tokens.
      5. It returns the list of formatted LP dictionaries.
      The function appears to be designed to provide data about liquidity pools and their associated tokens, including reserve values, prices, and fees. However, without more context about the specific use case or the system it's part of, it's difficult to provide a more detailed explanation.
      

More API Endpoints will be added in the future..