diff --git a/.gitignore b/.gitignore index b368262..f0ccdf1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ *venv *__pycache__ *.pyc + +# removing doc builds +docs/build/* \ No newline at end of file diff --git a/api/api.py b/api/api.py index 0f888a3..092d4d6 100644 --- a/api/api.py +++ b/api/api.py @@ -15,13 +15,19 @@ #TO GET ALL BLOCKS (LIMIT SET TO 10) @app.route('/v1.0/all_blocks/', methods=['GET']) def get_all_blocks(): + """ + Returns all the blocks data in the database. Limit set to 10 for test phase. + """ results = ApiBlocks.get_all_blocks() return json.dumps(results, indent=2, default=json_serial) -# #TO GET LATEST BLOCK'S BLOCKNUMBER +#TO GET LATEST BLOCK'S BLOCKNUMBER @app.route('/v1.0/current_blockNumber/', methods=['GET']) def eth_blockNumber(): + """ + Returns the block number of the latest block in the database. + """ results=ApiBlocks.get_current_block_number() return json.dumps(results, indent=2, default=json_serial) @@ -29,36 +35,66 @@ def eth_blockNumber(): #TO GET A BLOCK BY ITS BLOCK NUMBER @app.route('/v1.0/getBlockByNumber//', methods=['GET']) def eth_getBlockByNumber(blockno): + """ + Returns the data of the block of the given block number + + :param int blockno: Block Number that we want to retrieve data of + """ results=ApiBlocks.get_block_by_number(blockno) return json.dumps(results, indent=2, default=json_serial) #TO GET A BLOCK BY ITS BLOCK HASH @app.route('/v1.0/getBlockByHash//', methods=['GET']) def eth_getBlockByHash(block_hash): + """ + Returns the data of the block of the given block hash + + :param string block_hash: Block Hash that we want to retrieve data of + """ results=ApiBlocks.get_block_by_hash(block_hash) return json.dumps(results, indent=2, default=json_serial) #TO GET A BLOCK TRANSACTION COUNT BY ITS BLOCK HASH @app.route('/v1.0/getTransactionCountByHash//', methods=['GET']) def eth_getBlockTransactionCountByHash(block_hash): + """ + Returns the transaction count of the block of the given block hash + + :param string block_hash: Block Hash that we want to retrieve data of + """ results=ApiBlocks.get_block_transaction_count_by_hash(block_hash) return json.dumps(results, indent=2, default=json_serial) #TO GET A BLOCK TRANSACTION COUNT BY ITS BLOCK NUMBER @app.route('/v1.0/getTransactionCountByNumber//', methods=['GET']) def eth_getBlockTransactionCountByNumber(blockno): + """ + Returns the transaction count of the block of the given block number + + :param int blockno: Block Number that we want to retrieve data of + """ results=ApiBlocks.get_block_transaction_count_by_number(blockno) return json.dumps(results, indent=2, default=json_serial) #TO GET A BLOCK UNCLE COUNT BY ITS BLOCK HASH @app.route('/v1.0/getUncleCountByBlockHash//', methods=['GET']) def eth_getUncleCountByBlockHash(block_hash): + """ + Returns the uncle count of the block of the given block hash + + :param string block_hash: Block Hash that we want to retrieve data of + """ results=ApiBlocks.get_uncle_count_by_block_hash(block_hash) return json.dumps(results, indent=2, default=json_serial) #TO GET A BLOCK UNCLE COUNT BY ITS BLOCK NUMBER @app.route('/v1.0/getUncleCountByBlockNumber//', methods=['GET']) def eth_getUncleCountByBlockNumber(blockno): + """ + Returns the uncle count of the block of the given block number + + :param int blockno: Block Number that we want to retrieve data of + """ results=ApiBlocks.get_uncle_count_by_block_number(blockno) return json.dumps(results, indent=2, default=json_serial) @@ -69,18 +105,35 @@ def eth_getUncleCountByBlockNumber(blockno): #TO GET A TRANSACTION BY ITS HASH @app.route('/v1.0/getTransactionByHash//', methods=['GET']) def eth_getTransactionByHash(transaction_hash): + """ + Returns the data of the transaction of the given transaction hash + + :param string transaction_hash: Transaction Hash that we want to retrieve data of + """ results=ApiTransactions.get_transaction_by_hash(transaction_hash) return json.dumps(results, indent=2, default=json_serial) #TO GET A TRANSACTION BY BLOCK HASH AND INDEX @app.route('/v1.0/getTransactionByBlockHashAndIndex///', methods=['GET']) def eth_getTransactionByBlockHashAndIndex(block_hash, index): + """ + Returns the data of the transaction of the given transaction index and block hash + + :param int transaction_index: Transaction Index that we want to retrieve data of + :param string block_hash: Block Hash that we want to retrieve data of + """ results=ApiTransactions.get_transaction_by_block_hash_and_index(index, block_hash) return json.dumps(results, indent=2, default=json_serial) #TO GET A TRANSACTION BY BLOCK NUMBER AND INDEX @app.route('/v1.0/getTransactionByBlockNumberAndIndex///', methods=['GET']) def eth_getTransactionByBlockNumberAndIndex(blockno, index): + """ + Returns the data of the transaction of the given transaction index and block number + + :param int transaction_index: Transaction Index that we want to retrieve data of + :param int blockno: Block Number that we want to retrieve data of + """ results=ApiTransactions.get_transaction_by_block_number_and_index(index, blockno) return json.dumps(results, indent=2, default=json_serial) @@ -91,6 +144,11 @@ def eth_getTransactionByBlockNumberAndIndex(blockno, index): #TO GET A TRANSACTION RECEIPTS BY ITS HASH @app.route('/v1.0/getReceipt//', methods=['GET']) def eth_getTransactionReceipt(transaction_hash): + """ + Returns the data of the receipt of the given transaction hash + + :param string transaction_hash: Transaction Hash that we want to retrieve data of + """ results = ApiReceipts.get_receipt(transaction_hash) return json.dumps(results, indent=2, default=json_serial) @@ -101,6 +159,11 @@ def eth_getTransactionReceipt(transaction_hash): #TO GET AN UNCLE BY ITS HASH @app.route('/v1.0/getUncleByHash//', methods=['GET']) def eth_getUncleByUncleHash(uncle_hash): + """ + Returns the data of the uncle of the given uncle hash + + :param string uncle_hash: Uncle Hash that we want to retrieve data of + """ results = ApiUncles.get_uncle_by_uncle_hash(uncle_hash) return json.dumps(results, indent=2, default=json_serial) diff --git a/api/models/__init__.py b/api/models/__init__.py index 5d2b382..ccde802 100644 --- a/api/models/__init__.py +++ b/api/models/__init__.py @@ -1,3 +1,6 @@ +import sys + +sys.path.append("/api/models/") from .api_blocks import ApiBlocks from .api_transactions import ApiTransactions from .api_receipts import ApiReceipts diff --git a/api/models/api_blocks.py b/api/models/api_blocks.py index 4ff2083..8d374ea 100644 --- a/api/models/api_blocks.py +++ b/api/models/api_blocks.py @@ -1,16 +1,28 @@ from ether_sql.models import Blocks import sys from sqlalchemy.sql.expression import func -sys.path.append('../') +sys.path.append("../") from sessions import Session - ss=Session() session=ss.connect_to_psql() Block=ss.get_table_object('blocks') class ApiBlocks(Blocks): + """ + Extends the Blocks class from ether_sql.models. + The functions defined here access the psql Blocks table and retrieve the results based on requesting parameters. + Blocks Class maps a block table in the psql database to a block in ethereum node. + + :param int block_number: Quantity equal to number of blocks behind the current block + :param str block_hash: The Keccak 256-bit hash of this block + :param int uncle_count: Number of uncles in this block + :param int transaction_count: Number of transactions in this block + """ @staticmethod def get_all_blocks(): + """ + Returns all the blocks data in the database. Limit set to 10 for test phase. + """ results = [] blocks = session.query(Block).limit(10).all() columns = Block.columns.keys() @@ -20,6 +32,9 @@ def get_all_blocks(): @staticmethod def get_current_block_number(): + """ + Return the block number of the latest block in the database. + """ results = [] blocks = session.query(func.max(Block.columns.block_number).label('block_number')) column_names = [c["name"] for c in blocks.column_descriptions] @@ -28,6 +43,11 @@ def get_current_block_number(): @staticmethod def get_block_by_number(blockno): + """ + Returns the data of the block of the given block number + + :param int blockno: Block Number that we want to retrieve data of + """ results = [] blocks = session.query(Block).filter_by(block_number=blockno).all() columns = Block.columns.keys() @@ -37,6 +57,11 @@ def get_block_by_number(blockno): @staticmethod def get_block_by_hash(block_hash): + """ + Returns the data of the block of the given block hash + + :param string block_hash: Block Hash that we want to retrieve data of + """ results = [] blocks = session.query(Block).filter_by(block_hash=block_hash).all() columns = Block.columns.keys() @@ -46,6 +71,11 @@ def get_block_by_hash(block_hash): @staticmethod def get_block_transaction_count_by_hash(block_hash): + """ + Returns the transaction count of the block of the given block hash + + :param string block_hash: Block Hash that we want to retrieve data of + """ try: blocks = session.query(Block).filter_by(block_hash=block_hash).first() return [{'transaction_count':blocks.transaction_count}] @@ -54,6 +84,11 @@ def get_block_transaction_count_by_hash(block_hash): @staticmethod def get_block_transaction_count_by_number(blockno): + """ + Returns the transaction count of the block of the given block number + + :param int blockno: Block Number that we want to retrieve data of + """ try: blocks = session.query(Block).filter_by(block_number=blockno).first() return [{'transaction_count':blocks.transaction_count}] @@ -62,6 +97,11 @@ def get_block_transaction_count_by_number(blockno): @staticmethod def get_uncle_count_by_block_hash(block_hash): + """ + Returns the uncle count of the block of the given block hash + + :param string block_hash: Block Hash that we want to retrieve data of + """ try: blocks = session.query(Block).filter_by(block_hash=block_hash).first() return [{'uncle_count':blocks.uncle_count}] @@ -70,6 +110,11 @@ def get_uncle_count_by_block_hash(block_hash): @staticmethod def get_uncle_count_by_block_number(blockno): + """ + Returns the uncle count of the block of the given block number + + :param int blockno: Block Number that we want to retrieve data of + """ try: blocks = session.query(Block).filter_by(block_number=blockno).first() return [{'uncle_count':blocks.uncle_count}] diff --git a/api/models/api_receipts.py b/api/models/api_receipts.py index e270824..9835191 100644 --- a/api/models/api_receipts.py +++ b/api/models/api_receipts.py @@ -1,7 +1,7 @@ from ether_sql.models import Receipts import sys from sqlalchemy.sql.expression import func -sys.path.append('../') +sys.path.append("../") from sessions import Session ss=Session() @@ -9,9 +9,21 @@ Receipt=ss.get_table_object('receipts') class ApiReceipts(Receipts): + """ + Extends the Receipts class from ether_sql.models. + The functions defined here access the psql Receipts table and retrieve the results based on requesting parameters. + Receipts Class maps a block table in the psql database to a block in ethereum node. + :param str transaction_hash: The Keccak 256-bit hash of this transaction + + """ @staticmethod def get_receipt(transaction_hash): + """ + Returns the data of the receipt of the given transaction hash + + :param string transaction_hash: Transaction Hash that we want to retrieve data of + """ results = [] receipts = session.query(Receipt).filter_by(transaction_hash=transaction_hash).all() columns = Receipt.columns.keys() diff --git a/api/models/api_transactions.py b/api/models/api_transactions.py index 5370d84..92d849f 100644 --- a/api/models/api_transactions.py +++ b/api/models/api_transactions.py @@ -2,7 +2,7 @@ import sys from sqlalchemy.sql.expression import func from .api_blocks import ApiBlocks -sys.path.append('../') +sys.path.append("../") from sessions import Session ss=Session() @@ -10,9 +10,22 @@ Transaction=ss.get_table_object('transactions') class ApiTransactions(Transactions): + """ + Extends the Transactions class from ether_sql.models. + The functions defined here access the psql Transactions table and retrieve the results based on requesting parameters. + Transactions Class maps a block table in the psql database to a block in ethereum node. + + :param str transaction_hash: The Keccak 256-bit hash of this transaction + :param int block_number: Number of the block containing this transaction + :param datetime transaction_index: Position of this transaction in the transaction list of this block + + """ @staticmethod def get_all_transactions(): + """ + Returns all the transactions data in the database. Limit set to 10 for test phase. + """ results = [] blocks = session.query(Transaction).limit(10).all() columns = Transaction.columns.keys() @@ -22,6 +35,11 @@ def get_all_transactions(): @staticmethod def get_transaction_by_hash(transaction_hash): + """ + Returns the data of the transaction of the given transaction hash + + :param string transaction_hash: Transaction Hash that we want to retrieve data of + """ results = [] transactions = session.query(Transaction).filter_by(transaction_hash=transaction_hash).all() columns = Transaction.columns.keys() @@ -31,6 +49,12 @@ def get_transaction_by_hash(transaction_hash): @staticmethod def get_transaction_by_block_hash_and_index(transaction_index, block_hash): + """ + Returns the data of the transaction of the given transaction index and block hash + + :param int transaction_index: Transaction Index that we want to retrieve data of + :param string block_hash: Block Hash that we want to retrieve data of + """ results = [] blocks = ApiBlocks.get_block_by_hash(block_hash) if blocks==[]: @@ -43,6 +67,12 @@ def get_transaction_by_block_hash_and_index(transaction_index, block_hash): @staticmethod def get_transaction_by_block_number_and_index(transaction_index, blockno): + """ + Returns the data of the transaction of the given transaction index and block number + + :param int transaction_index: Transaction Index that we want to retrieve data of + :param int blockno: Block Number that we want to retrieve data of + """ results = [] transactions =session.query(Transaction).filter_by(transaction_index=transaction_index, block_number=blockno).all() columns = Transaction.columns.keys() diff --git a/api/models/api_uncles.py b/api/models/api_uncles.py index 2cd3ded..7ecf12d 100644 --- a/api/models/api_uncles.py +++ b/api/models/api_uncles.py @@ -1,7 +1,7 @@ from ether_sql.models import Uncles import sys from sqlalchemy.sql.expression import func -sys.path.append('../') +sys.path.append("../") from sessions import Session ss=Session() @@ -9,10 +9,21 @@ Uncle=ss.get_table_object('uncles') class ApiUncles(Uncles): + """ + Extends the Uncles class from ether_sql.models. + The functions defined here access the psql Uncles table and retrieve the results based on requesting parameters. + Uncles Class maps a block table in the psql database to a block in ethereum node. - @staticmethod + :param str uncle_hash: The Keccak 256-bit hash of this uncle + + """ def get_uncle_by_uncle_hash(uncle_hash): - results = [] + """ + Returns the data of the uncle of the given uncle hash + + :param string uncle_hash: Uncle Hash that we want to retrieve data of + """ + results=[] uncles = session.query(Uncle).filter_by(uncle_hash=uncle_hash).all() columns = Uncle.columns.keys() for row in uncles: diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..3a4569f --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SPHINXPROJ = ether-api +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..b5573fd --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,36 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=source +set BUILDDIR=build +set SPHINXPROJ=ether-api + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/docs/source/api/api.rst b/docs/source/api/api.rst new file mode 100644 index 0000000..147de8b --- /dev/null +++ b/docs/source/api/api.rst @@ -0,0 +1,13 @@ +Application Programming Interface(API) +====================================== + +ether-api provides a list of links at which GET requests can be targetted by the client. This section aims at detailing the various api links available in the library in detail. + +We use the `Click `_ library to generate CLI groups and their nested commands in a tree structure. + +API +--- +Following are the links for the API. + +.. automodule:: api.api + :members: \ No newline at end of file diff --git a/docs/source/api/index.rst b/docs/source/api/index.rst new file mode 100644 index 0000000..d645958 --- /dev/null +++ b/docs/source/api/index.rst @@ -0,0 +1,11 @@ +API's +===== + +This section aims to provide a detailed description of all the API's in the library. + +.. toctree:: + :maxdepth: 3 + :name: toc-api + + models + api diff --git a/docs/source/api/models.rst b/docs/source/api/models.rst new file mode 100644 index 0000000..602ffa7 --- /dev/null +++ b/docs/source/api/models.rst @@ -0,0 +1,28 @@ +API Classes & Methods +===================== + +This section aims at giving a detailed description of the psql tables in the database and their corresponding helper functions. + +ApiBlocks +--------- +A blockchain is literally a chain of blocks. A block contains a list of transactions, few features to prove the work done by a miner and a list of uncles. + +.. autoclass:: api.models.api_blocks.ApiBlocks + +ApiTransactions +--------------- +A transaction is the basic method for Ethereum accounts to interact with each other. The transaction is a single cryptographically signed instruction sent to the Ethereum network and has the capacity to change the world state. + +.. autoclass:: api.models.api_transactions.ApiTransactions + +ApiUncles +--------- +Due to ethereum block-chains fast block propagation time (~15 seconds), the probability of a block with sufficient proof-of-work becoming stale becomes quite high. This reduces the security and miner decentralization of block-chain. To rectify this issue ethereum proposes a modified-GHOST protocol by including and rewarding uncles (ommers) or stale blocks not included in the blockchain. + +.. autoclass:: api.models.api_uncles.ApiUncles + +ApiReceipts +----------- +Receipts information concerning the execution of a transaction in the block-chain. They can be useful to form a zero-knowledge proof, index and search, and debug transactions. The status column was included after the Byzantinium hardfork. + +.. autoclass:: api.models.api_receipts.ApiReceipts diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 0000000..7ff0749 --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,167 @@ +# -*- coding: utf-8 -*- +# +# Configuration file for the Sphinx documentation builder. +# +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/master/config + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys +sys.path.append('../') +sys.path.append("../api/") + + +# -- Project information ----------------------------------------------------- + +project = 'ether-api' +copyright = '2018, Saransh Vatsa' +author = 'Saransh Vatsa' + +# The short X.Y version +version = '' +# The full version, including alpha/beta/rc tags +release = '0.0.1' + + +# -- General configuration --------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', + 'sphinx.ext.ifconfig', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path . +exclude_patterns = [] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = 'ether-apidoc' + + +# -- Options for LaTeX output ------------------------------------------------ + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'ether-api.tex', 'ether-api Documentation', + 'Saransh Vatsa', 'manual'), +] + + +# -- Options for manual page output ------------------------------------------ + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'ether-api', 'ether-api Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ---------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'ether-api', 'ether-api Documentation', + author, 'ether-api', 'One line description of project.', + 'Miscellaneous'), +] + + +# -- Extension configuration ------------------------------------------------- + +# -- Options for intersphinx extension --------------------------------------- + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = {'https://docs.python.org/': None} \ No newline at end of file diff --git a/docs/source/index.rst b/docs/source/index.rst new file mode 100644 index 0000000..e5c7b54 --- /dev/null +++ b/docs/source/index.rst @@ -0,0 +1,29 @@ +.. ether-api documentation master file, created by + sphinx-quickstart on Fri Oct 12 12:44:43 2018. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Documentation +===================================== + +ether_api is a Flask API to get data from psql database created using ether_sql. + +It is maintained by `Analyse Ether `_, with the goal of making Ethereum data easily available to everyone. This API can be used to fetch Ethereum Blockchain data scraped using ether_sql for performing data analysis. + + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + introduction + installation + api/index + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/source/installation.rst b/docs/source/installation.rst new file mode 100644 index 0000000..63a1af5 --- /dev/null +++ b/docs/source/installation.rst @@ -0,0 +1,80 @@ +Installation Guide +================== + +Linux dependencies +------------------ + +Install postgresql as database:: + + $ sudo apt-get install postgresql + +Install python3 headers:: + + $ sudo apt-get install python3-pip + $ sudo apt-get install python3.6-dev + +Install redis server:: + + $ sudo apt-get install redis-server + +Install Rabbit-MQ server:: + + $ sudo apt-get install rabbitmq-server + + +Python dependencies +------------------- + +Clone the **ether-api** library:: + + $ git clone https://github.com/analyseether/ether-api.git + $ cd ether-api + +Create and activate a virtual environment:: + + $ virtualenv envname + $ source envname\bin\activate + +Install python libraries:: + + $ pip install -r requirements.txt + + +Database setup +-------------- + +Create a new psql user, this prompts for a user password, use the same password in the variable :code:`POSTGRES_PASSWORD` of the **settings.py** file:: + + $ sudo -u postgres createuser -s -P -e $USER + + +Create the ether_sql database in psql:: + + $ createdb ether_sql + +You can either load the database using the ether_sql library or load the database present in the test folder:: + psql ether_sql < tests/ether_sql_test.sql + + +Running the API +--------------- + +Run the flask server:: + + export FLASK_APP=api/api.py + flask run + +Finally, test the API's:: + + $ curl -i http://127.0.0.1:5000/v1.0/current_blockNumber/ + HTTP/1.0 200 OK + Content-Type: text/html; charset=utf-8 + Content-Length: 39 + Server: Werkzeug/0.14.1 Python/3.6.6 + Date: Tue, 18 Sep 2018 11:46:58 GMT + + [ + { + "block_number": 5000100 + } + ] \ No newline at end of file diff --git a/docs/source/introduction.rst b/docs/source/introduction.rst new file mode 100644 index 0000000..2824eee --- /dev/null +++ b/docs/source/introduction.rst @@ -0,0 +1,25 @@ +Introduction +============ + +ether-api +~~~~~~~~~~~~~~~~ + +ether_api is a Flask API to get data from psql database created using ether_sql. + +It is maintained by `Analyse Ether `_, with the goal of making Ethereum data easily available to everyone. This API can be used to fetch Ethereum Blockchain data scraped using ether_sql for performing data analysis. + +It is written in Python 3.6+, uses SqlAlchemy `_ to connect to a postgressql database and uses Flask and simplejson to serve the JSON to the requesting source. + +Goals +----- + +The main focus is to make Ethereum data easily available to everyone, while serving as a backbone for: + +* Open block explorers (coming soon...) +* `Data analysis platforms `_ + +Build Status +------------ +This is currently in very alpha stage, and not recommended for production use until it has received sufficient testing. + +Follow along the `Installation `_ to install the basic setup and checkout the `Guides <./guides/index.html>`_ to understand the process.