aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/routes/getSBlock/index.js24
-rw-r--r--api/routes/getSLatest/index.js20
-rw-r--r--api/routes/getZLatest/index.js25
3 files changed, 46 insertions, 23 deletions
diff --git a/api/routes/getSBlock/index.js b/api/routes/getSBlock/index.js
index e78c421..2fb8c80 100644
--- a/api/routes/getSBlock/index.js
+++ b/api/routes/getSBlock/index.js
@@ -8,15 +8,17 @@ const fs = require('fs');
const config = require("../../config.js");
module.exports = (req, res) => {
+ var args = req.url.split("/");
+ var sblock = args[3];
regex= /[a-f0-9]{128}/
- if (regex.test(req.params.sblock)){
+ if (regex.test(sblock)){
genesisreg = /0{128}/
- if (!genesisreg.test(req.params.sblock)){
- var path = config.minedBlocksDir+"/"+req.params.sblock;
- const command = spawn("cat",[config.minedBlocksDir+"/"+req.params.sblock]);
+ if (!genesisreg.test(sblock)){
+ var path = config.minedBlocksDir+"/"+sblock;
+ const command = spawn("cat",[config.minedBlocksDir+"/"+sblock]);
response_string = "";
command.stdout.on("data", data => {
- response_string = response_string+data;
+ response_string += data;
});
command.stderr.on("data", data => {
@@ -30,17 +32,21 @@ module.exports = (req, res) => {
command.on("close", code => {
if ( code === 0 ) {
- res.send(JSON.parse(fs.readFileSync(path)));
+ res.writeHead(200, {'Content-Type': 'application/json'});
+ res.end(JSON.stringify(JSON.parse(fs.readFileSync(path))));
} else {
- res.send({"error":"Sblock not found"})
+ res.writeHead(404, {'Content-Type': 'application/json'});
+ res.end(JSON.stringify({error:"Sblock not found"}));
}
console.log(`child process exited with code ${code}`);
});
} else {
- res.send({sblock:"Genesis Block - Arching Kaos Net"});
+ res.writeHead(200, {'Content-Type': 'application/json'});
+ res.end(JSON.stringify({sblock:"Genesis Block - Arching Kaos Net"}));
}
} else {
- res.send({"error":"No hash"})
+ res.writeHead(404, {'Content-Type': 'application/json'});
+ res.end(JSON.stringify({error:"No hash"}));
}
}
diff --git a/api/routes/getSLatest/index.js b/api/routes/getSLatest/index.js
index 5a31ae7..72005b6 100644
--- a/api/routes/getSLatest/index.js
+++ b/api/routes/getSLatest/index.js
@@ -1,13 +1,11 @@
const { spawn } = require('child_process');
-const os = require("os");
-const HomeDir = os.userInfo().homedir;
/*
* Gets the latest SBLOCK from superchain
* LOL
* sorry I was laughing at the term.. superchain
*/
-module.exports = (req, res) => {
+function getSLatest(req, res) {
const command = spawn("ak-schain-latest-cached");
response_string = "";
command.stdout.on("data", data => {
@@ -15,15 +13,23 @@ module.exports = (req, res) => {
});
command.stderr.on("data", data => {
- console.log(`stderr: ${data}`);
+ console.log(`stderr: ${data}`);
});
command.on('error', (error) => {
- console.log(`error: ${error.message}`);
+ console.log(`error: ${error.message}`);
});
command.on("close", code => {
- res.send(JSON.parse(response_string));
- console.log(`child process exited with code ${code}`);
+ console.log(`child process exited with code ${code}`);
+ if (code === 0){
+ res.writeHead(200, {'Content-Type': 'application/json'});
+ res.end(JSON.stringify(JSON.parse(response_string)));
+ } else {
+ res.writeHead(404, {'Content-Type': 'application/json'});
+ res.end({"error":"unreachable"});
+ }
});
}
+
+module.exports = getSLatest;
diff --git a/api/routes/getZLatest/index.js b/api/routes/getZLatest/index.js
index 4dc1899..9141a4e 100644
--- a/api/routes/getZLatest/index.js
+++ b/api/routes/getZLatest/index.js
@@ -1,28 +1,39 @@
const { spawn } = require('child_process');
/*
- * Gets the local latest zblock
+ * Gets the local latest zblock AKA zlatest
*
* Returns:
* - JSON object
* { zlatest: "Qm..." }
*
*/
-module.exports = (req, res) => {
+function getZLatest(req, res)
+{
const command = spawn("ak-get-zlatest");
+ var buffer = "";
command.stdout.on("data", data => {
- res.send({zlatest:`${data}`});
+ buffer += data;
});
command.stderr.on("data", data => {
- console.log(`stderr: ${data}`);
+ console.log(`stderr: ${data}`);
});
command.on('error', (error) => {
- console.log(`error: ${error.message}`);
+ console.log(`error: ${error.message}`);
});
command.on("close", code => {
- console.log(`child process exited with code ${code}`);
+ console.log(`child process exited with code ${code}`);
+ if (code === 0){
+ res.writeHead(200, {'Content-Type': 'application/json'});
+ res.end(JSON.stringify({zlatest:`${buffer}`}));
+ } else {
+ res.writeHead(404, {'Content-Type': 'application/json'});
+ res.end({"error":"unreachable"});
+ }
});
-}; \ No newline at end of file
+}
+
+module.exports = getZLatest;