This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
103 lines (82 loc) · 2.38 KB
/
app.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
//#region > Imports
//> Express
// Node.js Framework used to build web applications and APIs
const express = require("express");
//> Additional
/**
* Node.js body parsing middleware.
* Parse incoming request bodies in a middleware before your handlers.
*/
const bodyParser = require("body-parser");
// Providing a Connect/Express middleware to enable CORS
const cors = require("cors");
//> Configuration
// Basic Express config
const config = require("./config");
//> Routes
const routes = require("./routes");
//> Services
const IPFS = require("ipfs-core");
const web3 = require("./services/web3.js");
const storehash = require("./services/storehash.js");
// Miner Service
const ethminer = require("./services/ether.js");
const intelgen = require("./services/intelgen.js");
const fs = require("fs");
//#endregion
//#region > Initializers
// Init Express application
const app = express();
// Get .env values
require("dotenv").config();
//#endregion
//#region > Apply
//app.use(cors(config.corsOptions));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(config.centralErrorHandler);
app.use("/", routes);
app.listen(config.port, () => {
console.log(`Server is up and running at http://localhost:${config.port}`);
});
async function main() {
const node = await IPFS.create();
const version = await node.version();
console.log("Version:", version.version);
const accounts = await web3.eth.getAccounts();
ethminer.initMiner();
while (true) {
const res = await intelgen.fetchProfile().next();
console.info("Minded data", res);
const { personName, content } = res.value;
const fileName = `snek_person_${personName}.json`;
const fileAdded = await node.add({
path: fileName,
content,
});
console.info("Added file:", fileAdded.path, fileAdded.cid);
const transactionHash = fileAdded.cid.toString();
fs.appendFile(
"ipfs.cid.log",
`[${Date.now()}] ${transactionHash}\n`,
function (err) {
if (err) throw err;
console.log(`${fileName} added to IPFS!`);
}
);
storehash.methods.sendHash(transactionHash).send(
{
from: accounts[0],
},
(error, transactionHash) => {
console.log(transactionHash);
}
); //storehash
}
}
main();
//#endregion
/**
* SPDX-License-Identifier: (EUPL-1.2)
* Copyright © 2020 Werbeagentur Christian Aichner
*/