diff --git a/routes/baseActionsRouter.js b/routes/baseActionsRouter.js index 1b58b83..1ff23d0 100755 --- a/routes/baseActionsRouter.js +++ b/routes/baseActionsRouter.js @@ -180,202 +180,202 @@ router.get("/blocks", function(req, res) { }); router.post("/search", function(req, res) { - if (!req.body.query) { - req.session.userMessage = "Enter a block height, block hash, or transaction id."; + if (!req.body.query) { + req.session.userMessage = "Enter a block height, block hash, or transaction id."; - res.redirect("/"); + res.redirect("/"); - return; - } + return; + } - var query = req.body.query.toLowerCase(); + var query = req.body.query.toLowerCase(); - if (query === null || query === "null" || query.length < 1) { - res.redirect("/"); - return; - } + if (query === null || query === "null" || query.length < 1) { + res.redirect("/"); + return; + } - query = query.replace(/,/g, ""); + query = query.replace(/,/g, ""); - if (query.stringLength < 9) { - if (typeof query == "number") { - res.redirect("/block-height/" + query); - console.log('This is a block'); - return; - } - } else { - console.log('Bigger than 9 char); - } + if (query.stringLength < 9) { + if (typeof query == "number") { + res.redirect("/block-height/" + query); + console.log('This is a block'); + return; + } + } else { + console.log('Bigger than 9 char'); + } - if (query.stringLength < 40) { - if (query.startsWith('V')) { - res.redirect("/address/" + query); - console.log('This is not number'); - return; - } else { - console.log('Does not start with V'); - } - } - console.log('Not less that 40 chars - going to check transaction and then block hash'); + if (query.stringLength < 40) { + if (query.startsWith('V')) { + res.redirect("/address/" + query); + console.log('This is not number'); + return; + } else { + console.log('Does not start with V'); + } + } + console.log('Not less that 40 chars - going to check transaction and then block hash'); - rpcApi.getRawTransaction(query).then(function(tx) { - if (tx) { - res.redirect("/tx/" + query); + rpcApi.getRawTransaction(query).then(function(tx) { + if (tx) { + res.redirect("/tx/" + query); - return; - } - }).catch(function(err) { - rpcApi.getBlockByHash(query).then(function(blockByHash) { - if (blockByHash) { - res.redirect("/block/" + query); + return; + } + }).catch(function(err) { + rpcApi.getBlockByHash(query).then(function(blockByHash) { + if (blockByHash) { + res.redirect("/block/" + query); - return; - } - }).catch(function(err) { - if (isNaN(query)) { - req.session.userMessage = "No results found for query: " + query; + return; + } + }).catch(function(err) { + if (isNaN(query)) { + req.session.userMessage = "No results found for query: " + query; - res.redirect("/"); + res.redirect("/"); - return; - } + return; + } - rpcApi.getBlockByHeight(parseInt(query)).then(function(blockByHeight) { - if (blockByHeight) { - res.redirect("/block-height/" + query); + rpcApi.getBlockByHeight(parseInt(query)).then(function(blockByHeight) { + if (blockByHeight) { + res.redirect("/block-height/" + query); - return; - } - }).catch(function(err) { - req.session.userMessage = "No results found for query: " + query; + return; + } + }).catch(function(err) { + req.session.userMessage = "No results found for query: " + query; - res.redirect("/"); - }); - }); - }); + res.redirect("/"); }); + }); + }); +}); - router.get("/block-height/:blockHeight", function(req, res) { - var client = global.client; +router.get("/block-height/:blockHeight", function(req, res) { + var client = global.client; - var blockHeight = parseInt(req.params.blockHeight); + var blockHeight = parseInt(req.params.blockHeight); - res.locals.blockHeight = blockHeight; + res.locals.blockHeight = blockHeight; - res.locals.result = {}; + res.locals.result = {}; - var limit = 20; - var offset = 0; + var limit = 20; + var offset = 0; - if (req.query.limit) { - limit = parseInt(req.query.limit); - } + if (req.query.limit) { + limit = parseInt(req.query.limit); + } - if (req.query.offset) { - offset = parseInt(req.query.offset); - } + if (req.query.offset) { + offset = parseInt(req.query.offset); + } - res.locals.limit = limit; - res.locals.offset = offset; - res.locals.paginationBaseUrl = "/block-height/" + blockHeight; + res.locals.limit = limit; + res.locals.offset = offset; + res.locals.paginationBaseUrl = "/block-height/" + blockHeight; - client.cmd('getblockhash', blockHeight, function(err, result, resHeaders) { - if (err) { - // TODO handle RPC error - return console.log(err); - } + client.cmd('getblockhash', blockHeight, function(err, result, resHeaders) { + if (err) { + // TODO handle RPC error + return console.log(err); + } - res.locals.result.getblockhash = result; + res.locals.result.getblockhash = result; - rpcApi.getBlockData(client, result, limit, offset).then(function(result) { - res.locals.result.getblock = result.getblock; - res.locals.result.transactions = result.transactions; - res.locals.result.txInputsByTransaction = result.txInputsByTransaction; + rpcApi.getBlockData(client, result, limit, offset).then(function(result) { + res.locals.result.getblock = result.getblock; + res.locals.result.transactions = result.transactions; + res.locals.result.txInputsByTransaction = result.txInputsByTransaction; - res.render("block-height"); - }); - }); + res.render("block-height"); }); + }); +}); - router.get("/block/:blockHash", function(req, res) { - var blockHash = req.params.blockHash; +router.get("/block/:blockHash", function(req, res) { + var blockHash = req.params.blockHash; - res.locals.blockHash = blockHash; + res.locals.blockHash = blockHash; - res.locals.result = {}; + res.locals.result = {}; - var limit = 20; - var offset = 0; + var limit = 20; + var offset = 0; - if (req.query.limit) { - limit = parseInt(req.query.limit); - } + if (req.query.limit) { + limit = parseInt(req.query.limit); + } - if (req.query.offset) { - offset = parseInt(req.query.offset); - } + if (req.query.offset) { + offset = parseInt(req.query.offset); + } - res.locals.limit = limit; - res.locals.offset = offset; - res.locals.paginationBaseUrl = "/block/" + blockHash; + res.locals.limit = limit; + res.locals.offset = offset; + res.locals.paginationBaseUrl = "/block/" + blockHash; - // TODO handle RPC error - rpcApi.getBlockData(client, blockHash, limit, offset).then(function(result) { - res.locals.result.getblock = result.getblock; - res.locals.result.transactions = result.transactions; - res.locals.result.txInputsByTransaction = result.txInputsByTransaction; + // TODO handle RPC error + rpcApi.getBlockData(client, blockHash, limit, offset).then(function(result) { + res.locals.result.getblock = result.getblock; + res.locals.result.transactions = result.transactions; + res.locals.result.txInputsByTransaction = result.txInputsByTransaction; - res.render("block"); - }); - }); + res.render("block"); + }); +}); - router.get("/address/:address", function(req, res) { +router.get("/address/:address", function(req, res) { - var address = req.params.address; + var address = req.params.address; - res.locals.address = address; + res.locals.address = address; - console.log("address is:" + address); + console.log("address is:" + address); - console.log("/usr/local/bin/vivo-cli -conf=/etc/masternodes/vivo_n1.conf getaddressbalance \'{\"addresses\": [\"" + address + "\"]}\'"); + console.log("/usr/local/bin/vivo-cli -conf=/etc/masternodes/vivo_n1.conf getaddressbalance \'{\"addresses\": [\"" + address + "\"]}\'"); - res.locals.result = {}; + res.locals.result = {}; - const { exec } = require('child_process'); + const { exec } = require('child_process'); - var balance = "Not Found"; - var received = "Not Found"; + var balance = "Not Found"; + var received = "Not Found"; - var yourscript = exec('/usr/local/bin/vivo-cli -conf=/etc/masternodes/vivo_n1.conf getaddressbalance \'{\"addresses\": [\"' + address + '"]}\'', - //var yourscript = exec('whoami', - (error, stdout, stderr) => { - console.log(stdout); + var yourscript = exec('/usr/local/bin/vivo-cli -conf=/etc/masternodes/vivo_n1.conf getaddressbalance \'{\"addresses\": [\"' + address + '"]}\'', + //var yourscript = exec('whoami', + (error, stdout, stderr) => { + console.log(stdout); - const json = stdout; - const obj = JSON.parse(json); + const json = stdout; + const obj = JSON.parse(json); - console.log(obj.balance); - console.log(obj.received); + console.log(obj.balance); + console.log(obj.received); - res.locals.balance = parseInt(obj.balance) / 100000000; - res.locals.received = parseInt(obj.received) / 100000000; + res.locals.balance = parseInt(obj.balance) / 100000000; + res.locals.received = parseInt(obj.received) / 100000000; - console.log(stderr); + console.log(stderr); - if (error !== null) { - console.log(`exec error: ${error}`); - } + if (error !== null) { + console.log(`exec error: ${error}`); + } - res.render("address"); + res.render("address"); - }); + }); - /* + /* const { spawn } = require("child_process"); //const ls = spawn("/usr/local/bin/vivo-cli", [" -conf=/etc/masternodes/vivo_n1.conf \'{\"addresses\": [\"" + address + "\"]}\'"]); @@ -404,69 +404,69 @@ router.post("/search", function(req, res) { - }); +}); - router.get("/tx/:transactionId", function(req, res) { - var txid = req.params.transactionId; +router.get("/tx/:transactionId", function(req, res) { + var txid = req.params.transactionId; - var output = -1; - if (req.query.output) { - output = parseInt(req.query.output); - } + var output = -1; + if (req.query.output) { + output = parseInt(req.query.output); + } - res.locals.txid = txid; - res.locals.output = output; + res.locals.txid = txid; + res.locals.output = output; - res.locals.result = {}; + res.locals.result = {}; - // TODO handle RPC error - rpcApi.getRawTransaction(txid).then(function(rawTxResult) { - res.locals.result.getrawtransaction = rawTxResult; + // TODO handle RPC error + rpcApi.getRawTransaction(txid).then(function(rawTxResult) { + res.locals.result.getrawtransaction = rawTxResult; - client.cmd('getblock', rawTxResult.blockhash, function(err3, result3, resHeaders3) { - res.locals.result.getblock = result3; + client.cmd('getblock', rawTxResult.blockhash, function(err3, result3, resHeaders3) { + res.locals.result.getblock = result3; - var txids = []; - for (var i = 0; i < rawTxResult.vin.length; i++) { - if (!rawTxResult.vin[i].coinbase) { - txids.push(rawTxResult.vin[i].txid); - } - } + var txids = []; + for (var i = 0; i < rawTxResult.vin.length; i++) { + if (!rawTxResult.vin[i].coinbase) { + txids.push(rawTxResult.vin[i].txid); + } + } - rpcApi.getRawTransactions(txids).then(function(txInputs) { - res.locals.result.txInputs = txInputs; + rpcApi.getRawTransactions(txids).then(function(txInputs) { + res.locals.result.txInputs = txInputs; - res.render("transaction"); - }); - }); + res.render("transaction"); }); }); + }); +}); - router.get("/terminal", function(req, res) { - if (!env.debug) { - res.send("Debug mode is off."); +router.get("/terminal", function(req, res) { + if (!env.debug) { + res.send("Debug mode is off."); - return; - } + return; + } - res.render("terminal"); - }); + res.render("terminal"); +}); - router.post("/terminal", function(req, res) { - if (!env.debug) { - res.send("Debug mode is off."); +router.post("/terminal", function(req, res) { + if (!env.debug) { + res.send("Debug mode is off."); - return; - } + return; + } - client.cmd(req.body.cmd, function(err, result, resHeaders) { - console.log(result); - console.log(err); - console.log(resHeaders); + client.cmd(req.body.cmd, function(err, result, resHeaders) { + console.log(result); + console.log(err); + console.log(resHeaders); - res.send(JSON.stringify(result, null, 4)); - }); - }); + res.send(JSON.stringify(result, null, 4)); + }); +}); - module.exports = router; \ No newline at end of file +module.exports = router; \ No newline at end of file