Skip to content

helena-network/django-eth-events

 
 

Repository files navigation

Build Status Coverage Status Python 3.6 Django 2 PyPI version

django_eth_events

A standalone Django app for decoding Ethereum events compatible with Python 3.x. This app provides methods and Celery tasks to continuously decode events from ethereum blockchain and index then in a relational database. Too see an example of using this you can check Gnosis TradingDB repository and readthedocs documentation

Setup

If you want to install the latest stable release from PyPi:

$ pip install django-eth-events

If you want to install the latest development version from GitHub:

$ pip install -e git+https://github.com/gnosis/django-eth-events.git#egg=Package

Add django_eth_events to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'django_eth_events',
    ...
)

Settings

Provide an Ethereum node url. Provider will be detected depending on the protocol of the url. http/s, ipc and ws(websocket) providers are available. Recommended protocol is HTTPS. For example, using https://localhost:8545 communication with node will use RPC through HTTPS

ETHEREUM_NODE_URL = os.environ['ETHEREUM_NODE_URL']

You can also provide an IPC path to a node running locally, which will be faster, using ipc://PATH_TO_IPC_SOCKET

Number of concurrent threads connected to the ethereum node can be configured:

ETHEREUM_MAX_WORKERS = os.environ['ETHEREUM_MAX_WORKERS']

IPFS

Provide an IPFS host and port:

IPFS_HOST = os.environ['IPFS_HOST']
IPFS_PORT = os.environ['IPFS_PORT']
Events to listen to

Create a new array ETH_EVENTS in your settings file and as follows:

ETH_EVENTS = [
    {
        'ADDRESSES': ['0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B'],
        'EVENT_ABI': '... ABI ...',
        'EVENT_DATA_RECEIVER': 'yourmodule.event_receivers.YourReceiverClass',
        'NAME': 'Your Contract Name',
        'PUBLISH': True,
    },
    {
        'ADDRESSES_GETTER': 'yourmodule.address_getters.YouCustomAddressGetter',
        'EVENT_ABI': '... ABI ...',
        'EVENT_DATA_RECEIVER': 'chainevents.event_receivers.MarketInstanceReceiver',
        'NAME': 'Standard Markets Buy/Sell/Short Receiver'
    }
]

Take a look at Gnosis TradingDB repository and check out the full documentation.

Tests

You can launch tests using python run_tests.py. No additional services are required.

Django tests can also be used

DJANGO_SETTINGS_MODULE=settings.test python manage.py test

Coverage can be run using coverage tool:

pip install coverage
DJANGO_SETTINGS_MODULE=settings.test coverage run --source=django_eth_events manage.py test

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.8%
  • Shell 0.2%