-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
88 lines (79 loc) · 2.37 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require("dotenv").config();
const { Web3 } = require("web3");
const web3 = new Web3(process.env.RPC_URL);
const sendingBera = require("./src/sendBera.js");
const getBoosted = require("./src/isDelegator.js");
const getYeetard = require("./src/checkYeetard.js");
const express = require("express");
const app = express();
app.use(express.json());
const port = process.env.PORT;
const valiAddress = process.env.VALIDATOR_ADDRESS;
app.get("/checkaddr/:address", async (req, res) => {
const address = req.params.address;
if (!web3.utils.isAddress(address)) {
return res.status(400).send("Invalid address");
}
try {
const isDelegate = await getBoosted(address, valiAddress);
console.log(isDelegate);
if (isDelegate > 0) {
res.status(200).json({
status: "OK",
address: address,
amount: isDelegate,
});
} else {
res.status(404).send("Address not found or no boost amount");
}
} catch (err) {
res.status(500).json({ err: err.message });
}
});
app.get("/haveYeetard/:address", async (req, res) => {
const address = req.params.address;
if (!web3.utils.isAddress(address)) {
return res.status(400).send("Invalid address");
}
try {
const haveNFT = await getYeetard(address);
console.log(haveNFT);
if (haveNFT >= 0) {
res.status(200).json({
status: "OK",
address: address,
amount: haveNFT,
});
} else {
res.status(404).send("Address not found or no boost amount");
}
} catch (err) {
res.status(500).json({ err: err.message });
}
});
app.post("/winning", async (req, res) => {
const { address, amount } = req.body;
// account validation
if (!web3.utils.isAddress(address)) {
return res.status(400).send("Invalid address");
} else if (Number(amount) <= 0) {
return res.status(400).send("amount must be higher than 0 ");
} else if (!amount || !address) {
return res.status(400).send("address and amount are required");
}
try {
const isWinning = await sendingBera(address, amount);
if (isWinning === undefined) {
return res.status(400).send("insufficient balance");
}
res.status(200).json({
status: "OK",
address: address,
amount: amount,
Tx_Hash: `${isWinning}`,
});
} catch (err) {
res.status(500).send("Error fetching", err);
}
});
app.listen(port, () => console.log(`listening on port ${port}`));