generated from anupam-io/chainlink-node-operator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (37 loc) · 1.42 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const express = require("express");
const assert = require("assert");
const axios = require("axios");
var cors = require('cors');
const app = express();
app.use(express.static('public'))
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors({credentials: true, origin: true})); // Use this after the variable declaration
app.get("/status", (req, res) => {
res.send({ status: "OK" });
});
// Click this for testing: https://glacial-bayou-75167.herokuapp.com/check/nft/0xcfdf8fffaa4dd7d777d448cf93dd01a45e97d782/LINK
app.get("/check/nft/:user/:tokenSymbol", async (req, res) => {
const user = req.params.user.toLowerCase();
const tokenSymbol = req.params.tokenSymbol;
returnStatus = false;
url = `https://api.thegraph.com/subgraphs/name/sksuryan/baby-shark`;
query = {
query:
`{ symbols(orderBy: totalDeposit, orderDirection: desc, first: 5, where: {symbol: "` +
tokenSymbol +
`"}) { id totalDeposit symbol user eligibleForNFT } }`,
};
winnerArray = (await axios.post(url, query)).data.data.symbols;
assert(winnerArray.length <= 5 && winnerArray.length >= 0);
for (i = 0; i < winnerArray.length; i++) {
if (winnerArray[i].user == user) {
returnStatus = true;
break;
}
}
res.send({ result: returnStatus });
});
app.listen(process.env.PORT || 5000, () => {
console.log(`Server started at http://localhost:${process.env.PORT || 5000}`);
});