GithubHelp home page GithubHelp logo

nodefactoryio / hactar-backend Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 2.0 2.28 MB

Node.js backend application for Hactar (Filecoin tool for mining analysis)

License: MIT License

Dockerfile 0.33% JavaScript 15.00% TypeScript 84.67%
filecoin filecoinminer filecoin-lotus statistics api

hactar-backend's Introduction

Hactar backend

Node.js application for Hactar API.

This repository contains API implementation for Hactar, a Filecoin mining analyzer.

Development

Requirements

Following software is required to be installed to use this repo:

Usage

Make sure to run yarn install before first build or each time you change dependencies in package.json.

On first use of this repo, run npx task build which will build docker image.You will have to run npx task build each time you change dependencies in package.json (yarn.lock).

Run npx task --help to see all available commands and their description.

Notice

  • make sure you update yarn.lock before building
  • use sequelize-cli local to generate migrations (because of timestamp)

Documentation

The documentation can be accessed on app-url:${SWAGGER_DOCS_PORT}/${SWAGGER_DOCS_URL}

e.g. http://localhost:8080/api/swagger/

  • default docs url: /api/swagger
  • default docs port: 8080

License

This project is dual-licensed under Apache 2.0 and MIT terms:

Hactar Filecoin

hactar-backend's People

Contributors

dependabot[bot] avatar morrigan avatar mpetrunic avatar nmlinaric avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

hactar-backend's Issues

Fetch mining rewards history by filters

Expose nodes where user can fetch (using node ID) mining rewards history filtering them by:

  • week
  • day
  • month
  • year

Allow this filter to be query params i.e. ?filter=week

Fix auth response

Response from api/user/login should be json response and not plain string. I propose most simple structure as {token: "dummy-token-123"}

Store payment channels

Create a route that will store latest payment channels from a node.

API endpoint receives the node URL and address and list of payment channels with the following information:

  • payment channel status
  • voucher list with amount, signature and timelock

If payment channel for that node already exists in db, replace it with new information.

Seeders

Create seeders / dummy data for models we currently have

Edit account

Create endpoint PUT user/account to allow user to update account email or password.

Storing miner nodes

User can have N numbers of miner nodes (create new database model).
Expose endpoint that will allow user to store miner node with the following data:

  • URL
  • miner token (provided by user, not our JWT)
  • actor address

Expose delete endpoint too.

Support adding node name and description

Allow user to append node name and description to an existing node.

Create:

  • new columns migration for this (adding name and description in Node model)
  • route for updating this node info

Store mining rewards

Create an endpoint that will allow storing a log for miner rewards (receive array). This endpoint will be called when node detects that a miner has received a reward.

Reward amount is a fixed constant and saved in our backend app.

Should store owner address, miner actor, amount and time.

Endpoint API should also receive node URL and address.

Example of input:

[
   {
     Cid:   "bafy2bzaceawp7zcx74biecfl3axvoulh4lgdnnwzvgaza2cdhmxx75ymo6jnk",
     Address: "t0101",
     URL: "..."
   },
]

Amount is a fixed constant and should be in env/config file.

Fetch uptime history by filters

Expose nodes where user can fetch (using node ID) uptime records history filtering them by:

  • week
  • day
  • month
  • year

Allow this filter to be query params i.e. ?filter=week

Long lived token

Create JWT separately for daemon app that is long lived (no expiration).

Should be on separate route than current login.

Store disk space

Expose endpoint that will allow storing disk space which includes the following data:

  • total free space (in bytes, numeric)
  • taken space (in bytes, numeric)

Endpoint API should also receive node URL and actor address (we use both to distinguish unique nodes).

Create model schema accordingly, I propose naming DiskInformation. Note that this model depends (has relationship where 1 Node can have N disk information) on the Node model :)

Registration

Implement registration using email and password.

  1. Create user model with email, hash_password fields
  2. Create auth/register endpoint
  3. Return created user on successful registration.

Note, we will add later email confirmation. We will use JWT for authentication.

Authentication

User should be able to register using email and password. We use JWT for authentication and authorization.

Todo:

  • create /user/register endpoint
  • create /user/login endpoint

Email confirmation or forgotten password or update password is NOT required as a part of this ticket.

Fix CI for production build

Build production image steps fails in Circle CI

Step 1/9 : FROM nodefactory/nodejs-ts-starter:latest
pull access denied for nodefactory/nodejs-ts-starter, repository does not exist or may require 'docker login'

Email service

Create an email service that will be used for sending email.

EDIT: use sendinblue

Try to make it testable

Fix e2e tests in CI

Try to fix e2e tests in CircleCI by running migrations first, before test.

Store uptime

Expose simple endpoint (and create schema model) that will store reported uptime. This endpoint will be used to report if node is working or not so values can be true and false. Also, need time when entry was created.

Endpoint API should also receive node URL and actor address.

Authorization

Write middleware that will check if user's JWT is valid + user is allowed to access a specific records (is user record owner). Use it on existing routes:

  • creating and deleting user node
  • creating disk info
  • creating and fetching node uptime

or any other that I might have missed or been added meanwhile :)

Validation

Enable validation middleware (need to integrate with typescript)

Route for fetching disk info

Create a route that user will use to fetch disk info for a specific node (/node/diskinfo/:id).
Use JWT token for authorization, throw Forbidden if user not authorized.

Fetch balance

Create route for fetching balance using node ID.

We should display user's current balance (last entry) and 24 hour change (i.e. +149.FIL (0.5%)) -> TBD how

Store balance

Expose endpoint that will allow storing user's balance by time.

Create new model schema that stores balance number and time when entry is created.

Note that balance number is saved as bigint as we will be working with big numbers i.e. 139394994494949 (e^18)

Endpoint API should receive node URL, address and user's balance.

Fetch disk space history by filters

Expose nodes where user can fetch (using node ID) disk space records history filtering them by:

  • week
  • day
  • month
  • year

Allow this filter to be query params i.e. ?filter=week

Fix filters

We should not return ALL records but only the latest one appropriate for that filter.
For example, if filter week is used we should only return 7 records

Store general miner info

Store type of information that is regularly updated but doesn't need to have history for graphs or similar like we did with other information like disk information.

Create new table and endpoint that receives:

  • version (string i.e. 0.11.0)
  • sector size (bytes, bigint)
  • minerpower (bytes, bigint)
  • totalpower (bytes, bigint)

Node URL and address is received together with the info.

Note that we use only PUT type of requests here.
Also create a GET route so frontend can fetch this by node ID.

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.