Giter Site home page Giter Site logo

collaboration's Introduction

OpenSquare Collaboration

OpenSquare Collaboration is an off-chain gas free collaboration platform. Currently, off chain voting has been implemented while bounties and paid questions are in the plan.

Off chain voting now support substrate based chains. Assets on Statemine/Statemint will be supported soon.

Code structure

The code is organized with yarn workspaces and make sure yarn is installed before running it. There are 2 packages node-api and next under the packages folder.

node-api

This package initializes multiple @polkadot/api instances for each chain in case of a single endpoint failure. It is in charge of interaction with chain nodes and provides restful apis for caller to fetch on-chain data. The apis include:

  • [chain]/balance/[address]/[blockHashOrHeight?]: get the address balance at a block(by block hash or height).
  • [chain]/proxy/[delegator]/[delegatee]/[blockHashOrHeight?]: get the proxy info between 2 addresses.
  • [chain]/chain/height: get current chain height.

next

Next package depends on next.js, renders the fronted pages and provides apis. It integrates koa.js as the backend server, and you can find the code under packages/next/backend folder. The server provides apis for spaces, balances and proposals, check them under packages/next/backend/features folder.

It depends on MongoDB and related proposal and votes data are stored. All votes data are signed with polkadot keys and uploaded to IPFS too. We use decoo as the IPFS service provider, so make sure to register an account and get the corresponding decoo api token and secret key.

This package also depends on the node-api package to fetch on-chain info. So don't forget to config the required NODE_API_ENDPOINT environment variable.

How to run it

Prerequisite

MongoDB

Make sure mongodb is installed, while corresponding url is required to config in the next package.

Decoo api key and secret

Register an decoo account and get the api key and secret. Or for your convenience, just use following test key.

DECOO_API_SECRET_KEY=MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAJxxBVD13g3ah0E5OYS13yJ5UbON9cn9Q5dnCEM/T7opfClOGYeG/dH+8uoNEweCcTBkueU+sLtFAYRMThihmT8VolFvbEtI0rrdXClAqzjxoQwN5DPOyGKs2ngDjG6I8Ar5y0BIYdoHNvoU0k0PzefGT51LwnNZoVDMODpkKdjnAgMBAAECgYBCbge44j6hmVr3yknvXZ9brzKPUUe+tundv6WVkKvVPEp5660RjLP5WQ5jbpvXA3/28b6yZtV7IAlN2W0MLoq4wS/0Il0h1Kha5G6T6WI/SgD2bfC0AsuCBU5lA9iMCgoidfBE+6BjlJDH7QSsNI3LQWwxUQ7osN58p1k9i4egmQJBAN1Q0sBx2SgZjifwlSVA13iESrs0xe/Pagf5S9cuRUnHZs+9v7ZJXuOmJ7Ple7vstuMTMWqWtUWV3st1psdMbbMCQQC09XJDCyZD6soIVgWkV30rSUGRUf65QHC2K4HLtVdpSes1L6GiCxgxyxV/I24o8p/5JN11MMR5QpRc5go1d1X9AkEAxMZ9/Dm9mNfP+1b/ZRYX/sGxKG4tp6FFZz2S3wn29ThkA0V01YC667HqDxt1PoujuJZyE5FYLzyn0UMUPJOJ3QJBAJC83UaYrWOXcT8Xpu2a+MfdkS8t2ULNMxnSVL/d7OuPLy1cSrj0jMaO/EOz0BG6do/tl6B7gDrJMSfY64N2TvUCQQCzJDnyA38Fz9fo2htWp6cKzA4pNrHBpRtYVaLXp4Sc56JcN3SMS6f3E4n7rFLIZmvjW1MryiGN8fVzTgqQAmN4
DECOO_API_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJrZXkiOnsiYXBpX2tleSI6IjExNThLQmZ3N1pmQ3pGdFd1NEFNaXRHRU9YYUxNMlZpN2Q1TzE2MzcxMzU2ODgyMDkiLCJ1c2VyX2lkIjoxMTU4fX0.tKeVjP4CxyVeZn8Y1OPzR177noAWzqgoWBXLnup1Y7Y

Run

1. Dependency installation

yarn

2. Run node-api

cd packages/node-api
cat .env.example > .env

The default environment variables will work, but if you want to change some, just edit the '.env' file.

# You can change the chain endpoints, separated by ';'.
DOT_ENDPOINTS=wss://pub.elara.patract.io/polkadot;wss://rpc.polkadot.io;wss://polkadot.api.onfinality.io/public-ws;wss://polkadot.geometry.io/websockets
KSM_ENDPOINTS=wss://kusama-rpc.polkadot.io;wss://pub.elara.patract.io/kusama;wss://kusama.api.onfinality.io/public-ws;wss://kusama.geometry.io/websockets
KAR_ENDPOINTS=wss://karura.api.onfinality.io/public-ws;wss://karura-rpc-0.aca-api.network;wss://karura-rpc-1.aca-api.network;wss://karura-rpc-2.aca-api.network/ws;wss://karura-rpc-3.aca-api.network/ws;wss://karura.polkawallet.io;wss://pub.elara.patract.io/karura
KHA_ENDPOINTS=wss://khala.api.onfinality.io/public-ws

PORT=3223 # keep it

Then run

node src/index.js

Well, the node-api should be ready.

3. Run next package for the server and fronted

Come back to the project root dir and run

cd packages/node-api
cat .env.example > .env

Open the '.env' file and do necessary configuration

PORT=8001 # keep it

NEXT_PUBLIC_API_END_POINT=http://127.0.0.1:8001/ # keep it
NEXT_PUBLIC_SSR_API_END_POINT=http://127.0.0.1:8001/ # keep it

MONGO_URL=mongodb://localhost:27017 # set your mongodb url
MONGO_DB_NAME=voting # keep it or change it to any name you like

NEXT_PUBLIC_IDENTITY_SERVER_HOST=https://id.statescan.io # keep it

DECOO_API_OAUTH_ENDPOINT=https://api.decoo.io
DECOO_API_UPLOAD_ENDPOINT=https://api-hk.decoo.io
DECOO_IPFS_ENDPOINT=https://ipfs-hk.decoo.io/ipfs/
DECOO_API_TOKEN=xxx # fill the decoo jwt token
DECOO_API_SECRET_KEY=xxx # fill the decoo verification key

TEST_ACCOUNTS=xxx|yyy # ignore it, for test
TEST_ACCOUNT_BALANCE=100000000000 # ignore it, for test

# Following variables are for space proposal creation authority, you can just keep it
SPACE_PROPOSE_THRESHOLD_POLKADOT=10000000000
SPACE_PROPOSE_THRESHOLD_KUSAMA=10000000000
SPACE_PROPOSE_THRESHOLD_KARURA=1000000000000
SPACE_PROPOSE_THRESHOLD_KHALA=10000000000000

# Following variables are for space proposal vote authority, you can just keep it
SPACE_VOTE_THRESHOLD_POLKADOT=100000000
SPACE_VOTE_THRESHOLD_KUSAMA=10000000000
SPACE_VOTE_THRESHOLD_KARURA=10000000000
SPACE_VOTE_THRESHOLD_KHALA=10000000000

# Follwoing variables are space strategies configuration.
# You can choose both or either one startegy for each space, separated by ','.
SPACE_WEIGHT_STRATEGY_POLKADOT=balance-of,quadratic-balance-of
SPACE_WEIGHT_STRATEGY_KUSAMA=balance-of
SPACE_WEIGHT_STRATEGY_KARURA=balance-of
SPACE_WEIGHT_STRATEGY_KHALA=quadratic-balance-of

# The node api server url. Do not append '/' to the end.
NODE_API_ENDPOINT=http://localhost:3223

Then run

yarn run dev

or

node server.js

Do everything work well? Join OpenSquare matrix room if any problems.

Links

Documentation

collaboration's People

Contributors

hyifeng avatar qiyisi avatar yoshiyukisakura avatar wliyongfeng avatar dependabot[bot] avatar

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.