aboutsummaryrefslogtreecommitdiff
path: root/api/routes/getSBlock
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2023-03-30 01:09:30 +0300
committerkaotisk <kaotisk@arching-kaos.org>2023-03-30 01:09:30 +0300
commite2da6d2db20093ebd2a65aad35c9991ab1a02176 (patch)
treee5c77a8f4a6fd106b13b659e248cab5768d07cdc /api/routes/getSBlock
parenta4901ad47d2945e9a6c6616661840c97ebbf03e7 (diff)
downloadarching-kaos-tools-e2da6d2db20093ebd2a65aad35c9991ab1a02176.tar.gz
arching-kaos-tools-e2da6d2db20093ebd2a65aad35c9991ab1a02176.tar.bz2
arching-kaos-tools-e2da6d2db20093ebd2a65aad35c9991ab1a02176.zip
Introducing an HTTP JSON API
Diffstat (limited to 'api/routes/getSBlock')
-rw-r--r--api/routes/getSBlock/index.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/api/routes/getSBlock/index.js b/api/routes/getSBlock/index.js
new file mode 100644
index 0000000..4ad9127
--- /dev/null
+++ b/api/routes/getSBlock/index.js
@@ -0,0 +1,43 @@
+const { spawn } = require('child_process');
+const config = require("../../config.js");
+
+
+/*
+ * Gets a SBLOCK from superchain
+ * LOL
+ *
+ */
+module.exports = (req, res) => {
+ regex= /[a-f0-9]{128}/
+ if (regex.test(req.query.sblock)){
+ genesisreg = /0{128}/
+ if (!genesisreg.test(req.query.sblock)){
+ const command = spawn("cat",[config.minedBlocksDir+req.query.sblock]);
+ response_string = "";
+ command.stdout.on("data", data => {
+ response_string = response_string+data;
+ });
+
+ command.stderr.on("data", data => {
+ console.log(`stderr: ${data}`);
+ });
+
+ command.on('error', (error) => {
+ console.log(`error: ${error.message}`);
+ response_string={err:"error.message"};
+ });
+
+ command.on("close", code => {
+ smt = JSON.stringify(response_string);
+ res.send({hrefPrevious:"http://127.0.0.1:8610/v0/sblock?sblock="+smt.previous,sblock:smt});
+ // res.send(JSON.parse(response_string));
+ console.log(`child process exited with code ${code}`);
+ });
+ } else {
+ res.send({sblock:"Genesis Block - Arching Kaos Net"});
+ }
+ } else {
+ res.send({"error":"No hash"})
+ }
+}
+