forked from lyen1688/Scroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (35 loc) · 1.29 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
const express = require("express");
const bodyParser = require("body-parser");
const axios = require('axios');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.post("/getWalletInfo", async (req, res) => {
const requestId = req.headers["x-fc-request-id"];
console.log("FC Invoke Start RequestId: " + requestId);
const walletAddresses = req.body.wallet_addresses;
if (!Array.isArray(walletAddresses) || walletAddresses.some(address => !address.startsWith("0x"))) {
res.status(400).send({
msg: "Invalid wallet_addresses",
});
return;
}
const results = await Promise.all(walletAddresses.map(async (address) => {
const result = { wallet_address: address };
try {
const pointsResponse = await axios.get(`https://kx58j6x5me.execute-api.us-east-1.amazonaws.com/scroll/wallet-points?walletAddress=${address}`);
result.points = pointsResponse.data[0].points;
result.timestamp = pointsResponse.data[0].timestamp;
} catch (error) {
result.points = 0;
result.timestamp = 0;
}
return result;
}));
res.send(results);
console.log("FC Invoke End RequestId: " + requestId);
});
const port = 9000;
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});