-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
153 lines (133 loc) · 4.2 KB
/
server.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const express = require("express");
// require('dotenv').config({ path: './config/.env' })
const cors = require("cors");
const mongoose = require("mongoose");
const path = require("path");
const { exec } = require("child_process");
const solanaWeb3 = require("@solana/web3.js");
const splToken = require("@solana/spl-token");
const axios = require("axios");
var aws = require("aws-sdk");
var s3 = new aws.S3({
accessKeyId: "AKIAWEOB2JURBXFYCHZ2",
secretAccessKey: "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",
region: "eu-west-2",
});
const LooserNft = require("./model/looserNft.model");
//initializing the port
const PORT = process.env.PORT || 5005;
//creating the server
const app = express();
app.use(cors());
app.use(express.json());
mongoose
.connect("mongodb://localhost:27017/rumbel-64", {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("DB connection successful!"))
.catch((err) => {
console.log(err);
console.log("Error connecting DB!");
});
app.post("/updateNFT", async (req, res) => {
try {
// const { nftToken, walletAddress } = req.body;
const { roundNumber } = req.body;
// const data = await LooserNft.find();
// console.log("🚀 ~ file: server.js ~ line 43 ~ app.post ~ data", data);
const getLooserNfts = await LooserNft.findOne({ roundNumber: roundNumber });
if (!getLooserNfts)
return res.status(200).send({
status: false,
code: 500,
message: "This round has yet to be played.",
data: {},
});
// console.log(getLooserNfts);
var nftDatas = getLooserNfts.nftData;
for (const singleNft of nftDatas) {
// console.log(singleNft.nftNumber.substring(8));
const upgradeScript = `metaboss update uri \
--keypair ~/.config/solana/owner.json \
--account ${singleNft.tokenAddress} \
--new-uri https://rumble-upgrade-lost.s3.eu-west-2.amazonaws.com/${singleNft.nftNumber.substring(
8
)}.json`;
// https://rumble-upgrade-lost.s3.eu-west-2.amazonaws.com/${singleNft.nftNumber}.json
// console.log(upgradeScript);
exec(upgradeScript, (error, stdout, stderr) => {
console.log(stdout);
console.log(error);
if (stdout !== "done" && error !== null) {
return res.status(200).send({
status: false,
code: 400,
message: "Unable to upgrade NFT.",
data: { error, stderr },
});
}
});
}
return res.status(200).send({
status: true,
code: 200,
message: "NFT upgrade.",
data: {},
});
} catch (e) {
console.log(e);
return res.status(200).send({
status: false,
code: 500,
message: "Something went wrong!",
data: {},
});
}
});
app.post("/storeTnxSignature", async (req, res) => {
try {
const { destination } = req.body;
var allTransaction = [];
// https://little-long-glade.solana-devnet.discover.quiknode.pro/c5d0746570dc7408f03da6989612e4b618dfa22c/
const endpoint =
"https://solemn-falling-morning.solana-mainnet.discover.quiknode.pro/e0507b4e27f4ac271fadd720fd20de1101c1461e/";
const solanaConnection = new solanaWeb3.Connection(endpoint);
const getTransactions = async (address) => {
const pubKey = new solanaWeb3.PublicKey(address);
let transactionList = await solanaConnection.getSignaturesForAddress(
pubKey
// {
// // limit: 2,
// },
);
for (const transaction of transactionList) {
console.log(transaction.signature);
const data = await solanaConnection.getConfirmedTransaction(
transaction.signature
);
allTransaction.push(data);
}
return res
.status(200)
.send({ data: { transactionList, allTransaction } });
};
getTransactions(destination);
} catch (e) {
console.log(e);
return res.status(200).send({
status: false,
code: 500,
message: "Something went wrong!",
data: {},
});
}
});
//default route
app.all("*", (req, res) => {
return res.status(200).send("URL not found");
});
//listening the server
app.listen(PORT, () => {
console.log("server is running on port " + PORT);
});