Skip to content

hankedori/feathers-giveth

Repository files navigation

feathers-giveth

Real-time json cache for blockchain data.

About

feathers-giveth uses Feathersjs as a json cache for blockchain transaction history. The purpose is to ameliorate user wait times.

Feathersjs provides both a rest and websocket interface to database. Data itself is stored on the server file system use NeDB.

While this does nothing to speedup blockchain responses, it allows everyone connected to receive aggregate updates immediately via socketio push (aka pub/sub). This should hopefully simplify the code for the MVP, as it will not have worry about polling for all updates.

Getting Started

Getting up and running is as easy as 1, 2, 3.

  1. Make sure you have NodeJS and yarn installed.

  2. Install your dependencies

    cd path/to/feathers-giveth; npm install
    

    note: due to a bug in yarn, yarn install currently does not work

  3. feathers will need to connect to an ethereum node via websockets. Typically this will be a local TestRPC instance. The configuration param blockchain.nodeUrl is used to establish a connection. The default nodeUrl is ws://localhost:8546

  • we provide an easy way to start a TestRPC instance...

    1. mkdir data/testrpc -- this will contain the TestRPC database
    2. yarn testrpc -- this will start testrpc with some default parameters
  1. 1 time only - deploy liquidPledging contract

    node --harmony scripts/deploy.js

  2. Start your app

    yarn start
    
    • note: due to a bug somewhere (testrpc? web3? websocket?) the subscription events may not always be picked-up in feathers. especially the first time you run yarn start. It appears that testrpc is emitting the event correctly, but web3 Subscription is not recieving the message. If this happens, just restart feathers and all past events will be picked up.

Deploying

  1. start a production server

    yarn serve
    

Scripts

The scripts directory contains a few scripts to help development.

deploy.js - deploys a new vault & liquidPledging contract getState.js - prints the current state of the deployed vault & liquidPledging contracts. confirm.js - confirms any payments that are pending in the vault

Testing

Simply run yarn test and all your tests in the test/ directory will be run.

Usage

Each of these services are available via rest or websocket:

campaigns
dacs
donations
donationsHistory
milestones
uploads
users

To add another service use (after installing the feathers cli):

feathers generate service

Choose defaults for options as described here

Rest calls using curl

Example to store new json object:

curl 'http://secret.com:3030/skunkworks/' -H 'Content-Type: application/json' --data-binary '{ "name": "Curler", "text": "Hello from the command line!" }'

Example to remove all json objects:

curl 'http://secret.com:3030/skunkworks/' -X "DELETE"

WebSocket calls using javascript

You may call these services from client web app using the feathers api.

Example to connect to donations service:

const socket = io();
const client = feathers();
client.configure(feathers.socketio(socket));
const donations = client.service('donations');

Example to get donation data from server db and do something for each stored json object (notice pagination):

donations.find().then(page => page.data.forEach(doSomethingWithJsonObject));

Example to subscribe to donations service create event assign it to named function:

donations.on('created', doSomethingWithJsonObject);

Data schemas

Using a microservice approach, services are seperated into seperate json databases (which are really just json data files on the server).

Currenlty there are no enforced fields for json objects. Required fields and types may be introduced later with hooks.

Hooks

Currently there are no hooks but they can and will be added as a convenient way to execute operations that must occur on all requests (e.g. authorization, validation).

Help

Checkout Feathersjs api service methods and service events and database querying.

Changelog

0.1.0

  • Initial release

License

Copyright (c) 2016

Licensed under the MIT license.

About

Featherjs server for caching giveth data.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 91.5%
  • HTML 8.5%