GithubHelp home page GithubHelp logo

neosmithx / backend-inscription Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aiweb3-dao/relay_frontend_sdw

0.0 0.0 0.0 22.78 MB

backend for fetching the inscription result.

TypeScript 100.00%

backend-inscription's Introduction

Backend for inscription project

This the backend for inscription real-application project in any substrate network. (For now, supporting astart/polkadot/...)

How to run this backend

run database

install mysql

sudo apt-get update
sudo apt-get install mysql-server
sudo mysql_secure_installation
sudo systemctl start mysql
sudo systemctl enable mysql
sudo systemctl status mysql

init mysql

mysql -u root -p
CREATE DATABASE inscription_aiweb3;
CREATE USER 'aiwbe3_test'@'localhost' IDENTIFIED BY '';
GRANT ALL PRIVILEGES ON inscription_aiweb3.* TO 'aiwbe3_test'@'localhost';
FLUSH PRIVILEGES;
USE inscription_aiweb3;
CREATE TABLE aiweb3_questions (
    network VARCHAR(255),
    space VARCHAR(255),
    question_ID INT,
    question TEXT,
    deploy_hash VARCHAR(255),
    correct_answer TEXT,
    winner_num INT,
    winner_list TEXT,
    PRIMARY KEY (network, space, question_ID)
);

run backend

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
source ~/.bashrc
nvm install node
npm install -g typescript
npm install --global yarn

How frontend interacts with this backend (Kabugu see here ๐ŸŽ‰)

The backend have multi main functions. url should be the ip address of the backend server.

  1. create the winner list for AMA Q&A

After the admin deploy the question, frontend needs to record question information into database via (call this backend)

    const url = "http://url:1986/create_quest_in_database" 
    const data = JSON.stringify({
        "network":network,
        "space":space,
        "question_ID":question_ID,
        "question":question,
        "deploy_hash":deploy_hash
    })
    const response = await fetch(
        url, 
        {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: data
        }
    )
    console.log(response.json())
  1. Fetch quest information via database.

Frontend can fetch question information from database via (call this backend)

    const url = "http://url:1986/read_quest_information_from_database" 
    const data = JSON.stringify({
        "network":network,
        "space":space,
        "question_ID":question_ID,
    })
    const response = await fetch(
        url, 
        {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: data
        }
    )
    console.log(response.json())

Here, response including all the information of the specifical question, including the deploy_hash, question, winner_num, winner_list, etc. Winner list exists only after the admin call the function (/create_quest_winner).

  1. Create the winner.

Frontend can create the quest winner (maybe click a button to trigger this call)

    const url = "http://url:1986/create_quest_winner" 
    const data = JSON.stringify({
        "network":network,
        "space":space,
        "question_ID":question_ID,
        "correct_answer":correct_answer,
        "winner_num":winner_num
    })
    const response = await fetch(
        url, 
        {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: data
        }
    )
    console.log(response.json())

Here, the result of winner list will be as such format

    {
        "status":true,
        "log":"succeed to find the winner",
        "data":{
            "winner_list":[
                "5Dxxxxxxx",
                "5Fxxxxxxx",
                ...
            ]
        }
    }

In addition, frontedn can fetch the winner list again by calling the function (/read_quest_information_from_database) at anytime.

backend-inscription's People

Contributors

neosmithx avatar idfree 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.