aboutsummaryrefslogtreecommitdiff
path: root/api/routes/getZLatest
diff options
context:
space:
mode:
Diffstat (limited to 'api/routes/getZLatest')
-rw-r--r--api/routes/getZLatest/index.js25
1 files changed, 18 insertions, 7 deletions
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;