Giter VIP home page Giter VIP logo

feathers-giveth's Introduction

CI/CD

Feathers Giveth

Real-time json cache server for blockchain data

Note: Please use develop branch for contributing.

Welcome to the server code for Giveth's dapp. The dapp uses feathers as a cache for its blockchain transactions. By utilizing websockets on both the blockchain and client devices, we can receive and push updates simultaneously to all users in real time.

Table of content

Getting Started

Install

  • Linux

    If your operative system is any distrubution of linux you can use an All in One installation scripts special thanks to Dapp contributor Jurek Brisbane, available here along with a youtube video

  • Any OS

    1. Click Star on this repo near the top-right corner of this web page (if you want to).
    2. Join our slack if you haven't already.
    3. Fork this repo by clicking Fork button in top-right corner of this web page. Continue to follow instruction steps from your own feathers-giveth repo.
    4. The rest of these steps must be done from your machine's command line. Clone your own "feathers-giveth" repo. Copy the link from the "Clone or download" button near the top right of this repo's home page.
      git clone {paste your own repo link here}
      
    5. Change directories to feathers-giveth:
      cd feathers-giveth
      
    6. Make sure you have NodeJS (v10.24.0 or higher), yarn (v0.27.5 or higher), and npm (5.4.1 or higher) installed.
    7. Install dependencies from within feathers-giveth directory:
      npm install
      
      • note: due to a bug in yarn, yarn install currently does not work
    8. Install Mongo (we recommend installing via Brew)
    9. Run Mongo in a terminal window mongod or in the background mongod --fork --syslog
    10. Install Redis (we recommend install via Brew brew install redis)
    11. Run Redis in terminal window redis-server or in the background redis-server --daemonize yes
    12. (optionally) Install IPFS (we recommend installing via Brew)
    • If you don't install ipfs, image uploading will be affected. You can update the config ipfsGateway value to use a public ipfs gateway ex. https://ipfs.io/ipfs/, however your uploads will be removed at some point

Run server

The feathers server 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:8545

  1. We need to deploy any contract to that we intend to call. NOTE: The following cmd will clear the data dir, thus starting off in a clean state.

    yarn deploy-local
    

    After deploying local, make sure to copy-paste the MiniMeToken address in default.json

  2. We provide an easy way to start the bridge & 2 ganache-cli instances. VERY IMPORTANT: this command enables Home Ganache and Foreign Ganache networks, if you are using MetaMask you will need to add a Custom RPC to your networks config,http://localhost:8546 will be Foreign Ganache, and Home Ganache is normally added by default which is http://localhost:8545 if needed.

    yarn start:networks
    
  3. Since the bridge & ganache-cli is now running, open a new terminal window and navigate to the same feathers-giveth directory.

  4. Optionally open a new terminal window and start the ipfs daemon

    ipfs daemon
    
  5. Run db migration files ( if this the first time you want to start application, it's not needed to run migrations)

     ./node_modules/.bin/migrate-mongo up
    
  6. Start your app

    yarn start
    

Kill Ganache

If you run into errors like wallet balance not loading, it is very likely that Ganache is stuck netstat -vanp tcp | grep 8545 Find the process that is listening on *.8545 and 127.0.0.1.8545 and kill it with kill -9 PID (which is in the last colomn)

IPFS Support

If the ipfsApi is a valid ipfs node that we can connect to, we will pin every ipfs hash that is stored in feathers. We currently do not remove any orphaned (hashes with no references in feathers) ipfs hashs. In the future we will provide a script that you can run as a cronjob to unpin any orphaned hashes.

Video Walkthrough

Video tutorial walkthrough here: https://tinyurl.com/y9lx6jrl

Scripts

The feathers-giveth/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

  • makeUserAdmin.js - make a user admin

Testing

Simply run yarn test and all your tests in the /src directory will be run. It's included some integration tests so for running tests, you need to run a mongodb in your local system (on port 27017)

Debugging

You can control the logging level with the LOG_LEVEL env variable. Available levels can be found at: https://github.com/winstonjs/winston/tree/2.x#logging-levels

To enable debug logging simply start the server with LOG_LEVEL=debug yarn start

Usage

Each of these services are available via rest or websockets:

campaigns
communities
donations
donationsHistory
traces
uploads
users
emails
homePaymentsTransactions
subscriptions

If the server is using default configurations, you can see data for any of these services through your web browser at http://localhost:3030/SERVICE_NAME

PS: For accessing all features like creating communities and campaigns it's suggested to make isAdmin field true, for your user in you local MongoDb

Production

We use docker-compose for orchestration of our docker containers in our production servers.

  • make Make sure you have a file named production.json in config folder
  • Install docker and docker-compose on your server
  • run this command: docker-compose -f docker-compose-production.yml up -d

PS: It's good to see Github Actions config to better understanding of deploy structure

RSK

  1. You will need to download the rsk node. After installing, you will run the node w/ the regtest network for local development.
java -jar rskj-core-0.5.2-ORCHID-all.jar co.rsk.Start --regtest

or

java -Drsk.conf.file=rsk.conf -jar rskj-core-0.5.2-ORCHID-all.jar co.rsk.Start
  1. We need to deploy any contracts that we intend to call. NOTE: You will also need to ensure that your rsk node is in a clean state (reset) for the configured addresses to be correct.

    npm run deploy-local:rsk
    
  2. Optionally open a new terminal window and start the ipfs daemon

    ipfs daemon
    
  3. Start your app

    yarn start:rsk
    

Audit Log

The Audit log system logs every Create, Update, Patch and Remove on Campaigns, Traces, Events, Users, PledgeAdmins, Communities, Donations For enabling audit log locally you should change enableAuditLog in config to true, then

  • cd elk
  • docker-compose up

And then after logging in localhost:5601 with user:elastic, password: changeme you can see the logs

Donations Diagram

This diagram demonstrates how donations are created and how status will be changed, if you want to edit diagram just change https://mermaid.ink/img/ to https://mermaid-js.github.io/mermaid-live-editor/edit/# in below link

A Solid arrow mean a new donation will be created after this action, and dotted arrows are used when existing donations are modified.

Help

For more info on how to work with feathers checkout out their docs on service methods, service events, and database querying.

Also feel free to reach out to us on slack for any help or to share ideas.

feathers-giveth's People

Contributors

aminlatifi avatar arbreton avatar caseyhelbling avatar cryptomental avatar dapplion avatar dependabot[bot] avatar ewingrj avatar gencymex avatar horus2021 avatar mahdine avatar mdehghani avatar mhmdksh avatar mohammadpch avatar mohammadranjbarz avatar ojones avatar ovx avatar santteegt avatar satyavh avatar twmilli avatar vojtechsimetka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

feathers-giveth's Issues

Listen to Ownership* events on plugins

the lpp-dac, lpp-milestone, and lpp-campaign plugins extend the Owned contract. The Owned contract emits the following events:

  • OwnershipRequested
  • OwnershipTransferred
  • OwnershipRemoved

We should listen to these events, and update the dac/campaign/milestone in feathers as appropriate

Tokens are not saved in donationTokens.db

Reproduce:

  1. make a donation

now check feathers console. It generates the event correctly:

handling GenerateTokens Event:  { logIndex: 3,
  transactionIndex: 0,
  transactionHash: '0xf9c7dea9a656140676706ab700bcbb308d34f6c6808808f7b55148336c4a4eb2',
  blockHash: '0xc25020a3d9e842a3557f3b300eff663faaa4e6856e6d9f1ac3cd9ba095022bc5',
  blockNumber: 27,
  address: '0xC89Ce4735882C9F0f0FE26686c53074E09B0D550',
  type: 'mined',
  id: 'log_7adb2dd4',
  returnValues:
   Result {
     '0': '0x5b1869D9A4C187F2EAa108f3062412ecf0526b24',
     '1': '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1',
     '2': '2000000000000000000',
     liquidPledging: '0x5b1869D9A4C187F2EAa108f3062412ecf0526b24',
     addr: '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1',
     amount: '2000000000000000000' },
  event: 'GenerateTokens',
  signature: '0xf8a6cdb77a67632a46c21be3e7ca9b2519ecd39d21e514f9222c5b2f19ce23ed',
  raw:
   { data: '0x00000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c10000000000000000000000000000000000000000000000001bc16d674ec80000',
     topics:
      [ '0xf8a6cdb77a67632a46c21be3e7ca9b2519ecd39d21e514f9222c5b2f19ce23ed',
        '0x0000000000000000000000005b1869d9a4c187f2eaa108f3062412ecf0526b24' ] } }

But it also throws errors and tokens are not saved in database

donation counters can be easily gamed

We should update the donation counters if a donation is refunded, otherwise it's possible for someone to keep donating and refunding to make their dac look better

Add the unique count of people who donated to an entity

Currently we track the amount of donations with donationCount. But we want to show the unique amount of people who support a project. So we need to add something like peopleCount to the donationsHistory.hook.js. This needs to count the unique givers for an entity.

Need a way to get wallet balance

We should fetch the wallet balance before the donation popup is shown, so we can make sure the donator does not donate more than is in the wallet.

Cannot create a new campaign, throws on eth_estimateGas

"Error: VM Exception while executing eth_estimateGas: invalid opcode
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:65907:17
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:85139:5
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:4783:9
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:1343:16
    at replenish (/Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:1863:25)
    at iterateeCallback (/Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:1853:17)
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:1828:16
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:4780:13
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:85135:9
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:81420:7"

Notification system

We need to provide notifications when something in the dapp happens. People are not going to check out the dapp all the time to see what happens, we need to bring the info to them.

Could be email, slack, etc.

Find replacement for Skylight

SkyLight is kind of hard to use because stateless doesn't have all the callbacks that controlled modals have. So either we find a replacement, or fork and extend.

Making a donation throws invalid opcode

Reproduce:

  1. make donation, it will fail.
  2. Now check console:
  Transaction: 0x322d6735b0b15d53092c9b7aa1ed5bb30344b4a14d763f7d00116a97fe54e0c8
  Gas usage: 196219
  Block Number: 32
  Block Time: Fri Nov 24 2017 13:44:59 GMT+0100 (CET)
  Runtime Error: invalid opcode

`mined` property on milestone object not set

There's a check in the Dapp (My Milestones) on the milestone property mined. That property is not returned form the /milestones service. Hence, the request withdrawal functionality does not appear in the UI

Add authentication

Currently there is no authentication to milestones or donations.

Configure milestones and donations services to use authentication to limit access to data particular to the owner who created it.

When creating a campaign I get an _addMilestone error

Reproduce:

  1. create a campaign

Now check the feathers console

_addMilestone error -> Error: Returned error: Error: VM Exception while executing eth_call: invalid opcode
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:65907:17
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:85139:5
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:4783:9
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:1343:16
    at replenish (/Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:1863:25)
    at iterateeCallback (/Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:1853:17)
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:1828:16
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:4780:13
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:85135:9
    at /Users/satya/Development/feathers-giveth/node_modules/ethereumjs-testrpc/build/cli.node.js:81420:7
    at Object.ErrorResponse (/Users/satya/Development/feathers-giveth/node_modules/web3/packages/web3-core-helpers/src/errors.js:29:16)
    at Object.<anonymous> (/Users/satya/Development/feathers-giveth/node_modules/web3/packages/web3-core-requestmanager/src/index.js:137:36)
    at /Users/satya/Development/feathers-giveth/node_modules/web3/packages/web3-providers-ws/src/index.js:76:44
    at Array.forEach (native)
    at W3CWebSocket.WebsocketProvider.connection.onmessage (/Users/satya/Development/feathers-giveth/node_modules/web3/packages/web3-providers-ws/src/index.js:53:36)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (/Users/satya/Development/feathers-giveth/node_modules/web3/packages/web3-providers-ws/node_modules/yaeti/lib/EventTarget.js:107:17)
    at W3CWebSocket.onMessage (/Users/satya/Development/feathers-giveth/node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/W3CWebSocket.js:234:14)
    at WebSocketConnection.<anonymous> (/Users/satya/Development/feathers-giveth/node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/W3CWebSocket.js:205:19)
    at emitOne (events.js:115:13)
    at WebSocketConnection.emit (events.js:210:7)
    at WebSocketConnection.processFrame (/Users/satya/Development/feathers-giveth/node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/WebSocketConnection.js:547:26)
    at /Users/satya/Development/feathers-giveth/node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/WebSocketConnection.js:321:40
    at _combinedTickCallback (internal/process/next_tick.js:95:7)
    at process._tickCallback (internal/process/next_tick.js:161:9)

npm install does not work

Hi, I have a problem by running npm install. I got the following error:

npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EAI_AGAIN: request to https://registry.npmjs.org/feathers-authentication failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/node-libs-browser/node_modules/path-browserify):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: request to https://registry.npmjs.org/path-browserify failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org:443

npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/os-browserify failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org:443

npm ERR! A complete log of this run can be found in: ...

I'm using:

Ubuntu 16.04
node v8.9.0
npm 5.5.1
yarn 1.3.2

Get `No record found for id` error when signing in with keystore wallet

Reproduce:

  1. rm -rf data
  2. Empty localstorage for the Giveth app
  3. node --harmony deploy.js
  4. load the Dapp
  5. Go to sign in, load testrpcDeterministicAccount0.json from Giveth-Dapp repro

Now you will get this error:

info: after: authentication/challenges - Method: create
info: error: authentication - Method: create: Challenge = k2KWCVXhwC3rgHQgyMGH
error:  NotAuthenticated: Challenge = k2KWCVXhwC3rgHQgyMGH
    at NotAuthenticated (/Users/satya/Development/feathers-giveth/node_modules/feathers-errors/lib/index.js:100:17)
    at /Users/satya/Development/feathers-giveth/node_modules/feathers-authentication/lib/hooks/authenticate.js:102:31
    at <anonymous>
info: after: authentication/challenges - Method: get
info: error: users - Method: get: No record found for id '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1'
error:  NotFound: No record found for id '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1'
    at NotFound (/Users/satya/Development/feathers-giveth/node_modules/feathers-errors/lib/index.js:121:17)
    at /Users/satya/Development/feathers-giveth/node_modules/feathers-nedb/lib/index.js:146:17
    at <anonymous>

handle chain reorgs

If a chain reorg happens, we need to update feathers to reflect the new state.

I saved a log file where a chain reorg happened on the feathers develop server.

mutliple giverIds added for a single user if they donate multiple times

we assign the user a giverId when their first donation is mined, or the first time they create a profile. If they donate a second time before the 1st tx is mined, we will send the donate tx w/ giverId 0 which will create another giverId. This can lead to a single user having multiple giverIds.

Figure out a way to deal with this

Keep track of total amount raised for DACs/Campaigns

When delegating money away from DACs/Causes, the donations will currently disappear from that DAC/Cause. That means we cannot show the total amount raised for that DAC/Campaign.

So in case all money has been delegated, the total amount raised will show 0

That is not a very good incentive for new donors. Plus it will show the DAC/Campaign has no community

Can't delegate donations that are not created by me

When you get incoming donations that are not made by you, they need to be delegated.
We delegate (for now) by patching the donation. But if donorAddress is not the currentUser, then Feathers throws a not authorized error, which means the client cannot patch the donation.

Implement Connect with LinkedIn on user profile

As discussed:

  1. as a method to validate someone's email address.
  2. as a way for donators to validate a campaign / DAC experience
  3. as a way for donators to have social proof of that experience (like you could literally ask connections of the DAC owner how reliable that person is).

Update Milestone model

Can we include the following fields in the milestone model, as per the mock:

  • image (base64)
  • video url (string)
  • description (string)
  • owner (string)
  • reviewers [string]
  • status [enum?]
  • causeID (string)

Update Causes model

Can we include the following fields in the causes model, as per the mock:

  • image (base64)
  • video url (string)
  • description (string)
  • owner (string)

Secure feathers models

We should secure the feathers models to avoid any unwanted fields entering the database.

Add Prettier and Prettier ESLint

User Story

User story 1: As a developer, I don't want to have to worry about formatting styles. I want code to autoformat whenever I save. I want to completely remove any thinking of formatting from my workflow.

User story 2: As a reviewer, I want to ensure that code is formatted correctly and I don't have to review formatting errors and comment on them.

Type: Developer Tool

Summary: Integrate Prettier and Prettier ESLint into the project.

There are multiple editor integrations such as VSCode, Sublime, Atom, Vim and more.
In addition with Prettier ESLint we can get the power of ESLint --fix to automatically fix Prettier errors automatically even when not using any plugins.

Links:
https://github.com/prettier/prettier/
https://prettier.io/
https://prettier.io/docs/en/eslint.html

Expected behavior

While coding I have a formatting style guide that I am forced to follow and if I don't I get linting errors which could potentially break builds.

Actual behavior

Currently developers have to think about maintaining the current style of formatting and coding and thinking hard about this wastes time to think of other more important problems.

Solution

Summary:

I will add Prettier and Prettier ESLint integration and write up a Formatting.md file to explain how to use this in a few editors of choice.

Additional Information

This is open to suggestions/feedback.

Delegation from campaign to milestone throws error

Reproduce:

  1. donate to campaign
  2. go to delegations
  3. delegate to milestone

This will fail both locally as well as on alpha. The error in the browser console is:

"Error: the tx doesn't have the correct nonce. acco…les/ethereumjs-testrpc/build/cli.node.js:81513:3)", code: -32000}
code: -32000
message: "Error: the tx doesn't have the correct nonce. account has nonce of: 15 tx has nonce of: 14↵

no errors in feathers / testrpc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.