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

whale-guru-dev/origin-bridge

 
 

Repository files navigation

origin_github_banner

Head to https://www.originprotocol.com/developers to learn more about what we're building and how to get involved.

Just getting started with Origin? We recommend using Origin Box for development and testing on your local machine.

Origin 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:

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

Mac OS specifics

Install build tools packages:

brew install automake autoconf libtool

Set Up A Virtual Environment

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

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.

For EnvKey support, set ENVKEY to the key of the generated local development key.

Flask secret

Set FLASK_SECRET_KEY to your unique Flask secret key. 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.

Database

Set up your DATABASE_URL to point to where you local database is or will be.

Identity attestation

This is optional - only define these environment keys if you want to use your bridge server deployment as an endpoint for the DApp identity attestation functionality.

  • Facebook
    • FACEBOOK_CLIENT_ID
    • FACEBOOK_CLIENT_SECRET
  • Sendgrid
    • SENDGRID_API_KEY
    • SENDGRID_FROM_EMAIL
  • Twilio
  • Twitter
    • TWITTER_CONSUMER_KEY
    • TWITTER_CONSUMER_SECRET

Mobile push notification

If you wish to setup push notification for your mobile apps

  • APNS_CERT_FILE: Apple notification service certificate(This needs to be .pem file. Refer to this doc for how to generate)
  • APNS_CERT_PASSWORD: Passphrase for the pem file if you do not strip it out when you exported to pem
  • APNS_APP_BUNDLE_ID: The bundle id of your app

FCM support forthcoming.

Production configuration

When deploying to a production system, make sure to set appropriate environment variables, in your .env file, notably

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

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.
#
# Run this in the virtual environment you set up above.
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

# Run this in the virtual environment you set up above.
python main.py

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

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

Packages

No packages published

Languages

  • Python 82.3%
  • CSS 12.7%
  • HTML 4.5%
  • Mako 0.5%