-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·67 lines (55 loc) · 1.71 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
#! /usr/bin/env node
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const argv = yargs(hideBin(process.argv)).argv
const express = require('express')
const core = require('./core.js')
const app = express();
const PORT = argv.port || 4002;
app.get('/decodes/nfts/search/:query?/:type?/:balance?', (request, response) => {
try {
let query = request.params.query || request.headers.query || null
let type = request.params.type || request.headers.type || null
let balance = request.params.balance || request.headers.balance || null
let result
if (query && type && balance) {
result = core.searchNft(balance, query, type)
} else {
result = core.getNfts(balance)
}
response.json({
data: result,
total: result.length
})
} catch (error) {
response.status(404).json({
error: error.message
});
}
});
app.get('/decodes/:action/:hex?', (request, response) => {
try {
let action = request.params.action || request.headers.action
let hex = request.params.hex || request.headers.hex
if (action == "balance") {
response.json(core.getTotalInWallet(hex))
}
if (action == "nfts") {
let result = core.getNfts(hex)
response.json({
data: result,
total: result.length
})
}
if (action == "address") {
response.json([
core.getAddressString(hex)
])
}
} catch (error) {
response.status(404).json({
error: error.message
});
}
});
app.listen(PORT);