From 639e23153d62783ef5569a5febefc79aa2466f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Thu, 30 Jun 2016 14:23:21 -0400 Subject: [PATCH] stop watching after getting result --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 1d40f46..9d15237 100644 --- a/index.js +++ b/index.js @@ -108,8 +108,9 @@ function isHashZero(h) { } function parseString(s) { - return new Buffer(s.substr(2, s.indexOf("000")-2), 'hex').toString(); + return web3.toUtf8(s); } + function formatAddress(s) { if (s) { try { @@ -158,7 +159,11 @@ function startServer() { return; } reg.name(addr, function(err, res) { - http_res.end(JSON.stringify({"name": parseString(res)})); + var name = parseString(res); + if (name) + http_res.end(JSON.stringify({"name": parseString(res)})); + else + http_res.status(404).end(JSON.stringify({"error": "address not registred"})); }); }); app.post("/name/:name", function(req, http_res) { @@ -190,7 +195,8 @@ function startServer() { http_res.end(JSON.stringify(terr)); } else { console.log("Transaction sent " + reg_c); - reg.PrimaryChanged({"address": coinbase}, function(error, result) { + var watcher = reg.PrimaryChanged({"address": coinbase}, function(error, result) { + watcher.stopWatching(); if (error) { console.log(error); http_res.status(403).end(JSON.stringify({"success": false})); -- GitLab