Skip to content

Connecting the old world with the new. Used for things like indexing, identity attestations, and notifications

License

Notifications You must be signed in to change notification settings

franckc/bridge-server

 
 

Repository files navigation

origin_github_banner

bridge-server

The Origin Bridge Server connects the old world to the new.

Most traditional web APIs, such as those from Facebook and Twitter, can only interact with a centralized server located at a specific domain. A decentralized application, like our Origin Demo DApp, doesn't need to "live" on a particular server. (In fact, you can load it from any IPFS gateway!) Thus, in order for the DApp to use an "old world" API, it needs a Bridge Server.

Origin hosts a Bridge Server, but in the true spirit of decentralization, anyone is free to clone our open source code and host their own.

You can connect to and use our hosted Bridge Server at bridge.originprotocol.com. The develop branch of this repo is available at dev.bridge.originprotocol.com.

DApps can connect to the Bridge Server of their choosing in order to enable the following functionality which is either impossible or impractical to do directly onchain, including:

Indexing

Searching, browsing or filtering results is impractical to do either onchain or in the browser. DApps can connect to a bridge-server to solve this problem. The bridge server will index the blockchain and related JSON content that is stored on IPFS into a quickly queriable format to make searching and filtering results possible from DApps.

Identity

We need a centralized server that can handle tasks like issuing identity attestations and decryptying data that is returned from third-party services like Civic. We also need proxies for fetching public data from services like Facebook and Twitter which require authentication keys.

Notifications

There is currently no practical way to get email or text notifications when your bookings are made without a centralized monitoring service that can send you a text or an email to let you know about listings you care about.

API documentation

See the README for the API

One-time Setup

Prerequisites

  • Python 3.5 or higher required
  • Postgresql 9.3 or higher required
  • Redis 4.0+ recommended

Mac OS specifics

Install build tools packages:

brew install automake autoconf libtool

Set Up A Virtual Environment

git clone https://github.com/OriginProtocol/bridge-server.git
cd bridge-server

python3 -m venv ve

source ve/bin/activate

pip install -r requirements.txt

Clone the Starter Configuration Variables

cp dev.env .env

Adjust the values in .env now and in the future to suit your local environment. In particular, set up your DATABASE_URL to point to where you local database is or will be.

You'll need to set a few API keys:

  • Facebook
    • FACEBOOK_CLIENT_ID
    • FACEBOOK_CLIENT_SECRET
  • Sendgrid
    • SENDGRID_API_KEY
    • SENDGRID_FROM_EMAIL
  • Twilio
    • TWILIO_ACCOUNT_SID
    • TWILIO_AUTH_TOKEN
    • TWILIO_NUMBER (Can be added on this page)
  • Twitter
    • TWITTER_CONSUMER_KEY
    • TWITTER_CONSUMER_SECRET

For EnvKey support set ENVKEY to the key of the generated local developement key

When deploying, set appropriate environment variables for production, notably

DEBUG=0
HTTPS=1
HOST=<your-prod-host>
FLASK_SECRET_KEY=<unique-key>
PROJECTPATH=/app  # For Heroku

Use a unique Flask secret key per environment. Flask suggests that python -c "import os; print(os.urandom(24))" is a perfectly reasonable way to generate a secret key.

Enviroment keys for Indexing server:

  • RPC_SERVER: Set this to RPC server URL, you want the indexing server to listen to events on.

  • RPC_PROTOCOL: Different connection protocols for RPC server. Options are https or wss

    example configurations:

    • Rinkeby: RPC_SERVER: wss://rinkeby.infura.io/_ws RPC_PROTOCOL: wss

    • Connecting to local RPC server: RPC_SERVER: http://127.0.0.1:8545/ RPC_PROTOCOL: https

  • IPFS_DOMAIN: Set this to domain of an IPFS daemon. for example 127.0.0.1 or gateway.originprotocol.com

  • IPFS_PORT: port on which the IPFS daemon is listening.

  • REDIS_URL: Set this to point to your local Redis server. For example redis://127.0.0.1:6379/0

Set Up Your Database

createdb <db-name>  # Anything you want, perhaps bridge-server

Make sure the DB name you used is indicated in your DATABASE_URL in the .env file. Example: DATABASE_URL=postgresql://localhost:5432/bridge_server

# Applies all migrations to make the DB current. Works even on an empty database.
FLASK_APP=main.py flask db upgrade

Every Time You Develop

Set Up Your Shell

cd /path/to/environment/project
source ../bin/activate
export PYTHONPATH=.

It's handy to save bash alias for this. Consider adding in your ~/.bash_profile:

alias myenv='cd /path/to/environment/project && source ../bin/activate && export PYTHONPATH=.'

Run the Server

python main.py

This starts a development server on localhost:5000 by default.

Run the Celery worker

celery -A util.tasks worker -c=1
celery -A util.tasks beat

This starts a celery beat to issue periodic tasks and a celery worker to process the tasks.

Run the Tests

Throughout the development process and before committing or deploying, run:

pytest --flakes --codestyle

Run individual test files simply as:

pytest path/to/test.py

Run a single test case, or an individual test, using:

pytest path/to/test.py::test_case_name

Problems? Hit us up in the engineering channel on Discord if you need help.

Code Formatting

We are using pycodestyle to enforce code formatting. The tests will throw errors when code is not formatted properly, when using the --codestyle option.

To automatically format the code:

autopep8 --in-place --recursive --a --a .

Contributing

Please send your pull requests to the develop branch. Everything on master should be live at bridge.originprotocol.com

Database changes

We use Flask Migrate to handle database revisions. If you make changes to the database, use

FLASK_APP=main.py flask db migrate

to generate the required migration file. Rename it to add a description of the change after the underscore. Then run

FLASK_APP=main.py flask db upgrade

to apply your migration to your local database, then test your changes before committing.

Heroku Deploy

To deploy a development copy of the site on Heroku, just choose which branch you would like to use and follow the instructions:

Master branch
(stable)
Develop branch
(active development)
Deploy Deploy

Heroku will prompt you to set config variables. At a minium, you must set these three:

Config Value
FLASK_SECRET_KEY (make something up)
PROJECTPATH /app
HOST (domain name of your dev heroku app)

See dev.env for a full list of other optional config variables.

We use following buildpacks:

heroku buildpacks:set heroku/python

Contributing

Origin is an 100% open-source and community-driven project and we welcome contributions of all sorts. There are many ways to help, from reporting issues, contributing code, and helping us improve our community.

To get involved, please join our Discord channel and review our guide to contributing.

About

Connecting the old world with the new. Used for things like indexing, identity attestations, and notifications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.5%
  • HTML 2.0%
  • Mako 0.5%