Skip to content
Snippets Groups Projects
Commit 639e2315 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

stop watching after getting result

parent 34febcf0
No related branches found
No related tags found
No related merge requests found
...@@ -108,8 +108,9 @@ function isHashZero(h) { ...@@ -108,8 +108,9 @@ function isHashZero(h) {
} }
function parseString(s) { function parseString(s) {
return new Buffer(s.substr(2, s.indexOf("000")-2), 'hex').toString(); return web3.toUtf8(s);
} }
function formatAddress(s) { function formatAddress(s) {
if (s) { if (s) {
try { try {
...@@ -158,7 +159,11 @@ function startServer() { ...@@ -158,7 +159,11 @@ function startServer() {
return; return;
} }
reg.name(addr, function(err, res) { reg.name(addr, function(err, res) {
var name = parseString(res);
if (name)
http_res.end(JSON.stringify({"name": parseString(res)})); 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) { app.post("/name/:name", function(req, http_res) {
...@@ -190,7 +195,8 @@ function startServer() { ...@@ -190,7 +195,8 @@ function startServer() {
http_res.end(JSON.stringify(terr)); http_res.end(JSON.stringify(terr));
} else { } else {
console.log("Transaction sent " + reg_c); 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) { if (error) {
console.log(error); console.log(error);
http_res.status(403).end(JSON.stringify({"success": false})); http_res.status(403).end(JSON.stringify({"success": false}));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment