/ README.md
README.md
  1  # Contract notifier
  2  
  3  Opt-in service to send email notifications when a contract event is emitted
  4  
  5  ## Requirements
  6  
  7  - NodeJS (tested on node v10.16.0)
  8  - MongoDB
  9  - Yarn (recommended)
 10  
 11  ## Installation
 12  ```
 13  git clone https://github.com/status-im/contract-notifier
 14  cd contract-notifier
 15  yarn
 16  ```
 17  
 18  ## Usage
 19  ### Configuration
 20  #### General
 21  `./config/index.js`
 22  - `PORT`: port where the API will be available (default: `4000`)
 23  - `RATE_LIMIT_MAX_REQ`: Max number of connections during `RATE_LIMIT_TIME` milliseconds before sending a 429 response. (default: `1`)
 24  - `RATE_LIMIT_TIME`: How long in milliseconds to keep records of requests in memory. (default: `15`)
 25  - `DB_CONNECTION`: MongoDB connection string
 26  - `BLOCKCHAIN_CONNECTION_POINT`: URL string of an ethereum node. (default: `http://localhost:8545`)
 27  - `SENDGRID_API_KEY`: To send emails.
 28  - `BLOCK_DELAY`: Adds a delay in the number of blocks to avoid reorgs. (default: `6`)
 29  - `POLL_SLEEP`: Interval of time wait for polling the chain for new events. (default: `30`)
 30  - `VALID_DAPPS`: Array with known dapps in `dapps/` folder
 31  
 32  The `ENV` variable can be used to set these variables,  as well as a `.secret.json` file.
 33  
 34  #### Dapp
 35  Each dapp should have their own configuration and templates to send emails. To add a dapp, create a folder inside `./dapps/` with the dapp name. Also, edit `./config/index.js` to add the new dapp in `VALID_DAPPS`. (**This will change with a proper dapp registry, to avoid this manual process**)
 36  
 37  Each dapp folder should have a `config.js` file and one or more .html and .txt templates. See `./dapps/teller-network/config.js` for a sample config. 
 38  
 39  (TODO: document the config file)
 40  
 41  
 42  ### Execution
 43  
 44  - To launch the API endpoint:
 45  
 46  ```
 47  yarn api
 48  ```
 49  
 50  API will be available in http://localhost:4000 or whatever port was configured
 51  
 52  - To launch the contract events mailer:
 53  
 54  ```
 55  yarn watch
 56  ```
 57  
 58  ### Rest API
 59  
 60  The following methods are available in the API:
 61  
 62  #### Subscribe
 63  - `POST`
 64  - http://localhost:4000/:dappId/subscribe
 65  ```
 66  {
 67    "email": "user@email.com",
 68    "address": "0x1234...ABCD",
 69    "signature": "0x1234...ABCD"
 70  }
 71  ```
 72  - Signature must be the user's `email` signed by the `address`
 73  - Replies with `OK` if the subscription was successful. Otherwise, an error message is shown
 74  - Sends a signup email with a token that expires in 2hr.
 75  - `:dappId` must be known by the service.
 76  
 77  #### Verify
 78  - `GET`
 79  - http://localhost:4000/confirm/:token
 80  - Replies with `OK` if the token is valid. Otherwise an error message is shown
 81  - Used to confirm that the user received the signup email.
 82  
 83  #### Unsubscribe
 84  - `POST`
 85  - http://localhost:4000/:dappId/unsubscribe
 86  ```
 87  {
 88    "address": "0x1234...ABCD",
 89    "signature": "0x1234...ABCD"
 90  }
 91  ```
 92  - Signature must be the `:dappId` signed by the `address`
 93  - Replies with `OK` if the user is unsubscribed successfully. Otherwise, an error message is shown
 94  - `:dappId` must be known by the service.
 95  
 96  #### User exists
 97  - `GET`
 98  - http://localhost:4000/:dappId/user/:address
 99  - Replies with `OK` if an user with `:address` is subscribed to the dapp events
100  - `:dappId` must be known by the service.
101  
102  
103  ## Contribution
104  Thank you for considering to help out with the source code! We welcome contributions from anyone on the internet, and are grateful for even the smallest of fixes!
105  
106  If you'd like to contribute to this project, please fork, fix, commit and send a pull request for the maintainers to review and merge into the main code base. If you wish to submit more complex changes though, please check up with the core devs first on #embark-status channel to ensure those changes are in line with the general philosophy of the project and/or get some early feedback which can make both your efforts much lighter as well as our review and merge procedures quick and simple.
107  
108  ## License
109  MIT