bitagora-booth
Advanced tools
Comparing version 1.0.127 to 1.0.128
53
booth.js
@@ -177,2 +177,23 @@ /** | ||
async function confirmSubmission(link) { | ||
try { | ||
console.log("Confirming submission at link "+link); | ||
let attempts = 0; | ||
var response; | ||
while (attempts < 10) { | ||
response = await requestWithLink(link); | ||
console.log("Response in confirmSubmission"); | ||
console.log(response); | ||
if (response.status == "COMMITTED") break; | ||
wait(5000 + attempts * 1000); | ||
attempts = attempts + 1; | ||
} | ||
console.log("Returning from confirmSubmission"); | ||
console.log(response); | ||
return(response); | ||
} catch(e) { | ||
return undefined; | ||
} | ||
} | ||
async function sendVoteToAPIs(bytes, apis) { | ||
@@ -182,15 +203,27 @@ try { | ||
let response = { status: 'ERROR' }; | ||
var link; | ||
for (var api of apis) { | ||
let result = await postVote(bytes, api).catch((e) => { return false }); | ||
let result = await postVote(bytes, api).catch(() => { return undefined; }); | ||
console.log("Result from calling API "+api); | ||
console.log(result); | ||
if (result) { | ||
console.log("Successful result"); | ||
response = result; | ||
break; | ||
} else { | ||
console.log("Sending vote resulted in error"); | ||
console.log("API: " +api); | ||
continue; | ||
} | ||
response = result; | ||
if (Boolean(response)) { | ||
console.log("Received response"); | ||
console.log(response); | ||
if ( response.status == 'COMMITTED' ) { | ||
console.log("Submission committed"); | ||
break; | ||
} else if ( response.status == 'PENDING' ) { | ||
console.log("Submission pending. Waiting for confirmation"); | ||
link = apis[i] + "/batch_statuses?id=" + response.id; | ||
console.log(link); | ||
response = await confirmSubmission(link); | ||
console.log("Confirmed submission response"); | ||
console.log(response); | ||
if (Boolean(response.status) && (response.status == 'COMMITTED')) break; | ||
} else if (response.status == 'INVALID' ) { | ||
console.log("Submission invalid. Breaking."); | ||
break; | ||
} | ||
} | ||
} | ||
@@ -197,0 +230,0 @@ console.log("Returning "); |
@@ -102,2 +102,4 @@ /** | ||
const request = require('request'); | ||
console.log("Requesting from "); | ||
console.log(url); | ||
try { | ||
@@ -104,0 +106,0 @@ request.get({ |
@@ -48,2 +48,3 @@ /** | ||
if (Object.keys(poll.values).length != Object.values(poll.values).length) throw 'wrong values'; | ||
console.log("Checking dates"); | ||
if (parseInt(poll.starts) < today.valueOf() || parseInt(poll.ends) < today.valueOf() || parseInt(poll.starts) > parseInt(poll.ends) ) throw 'wrong dates'; | ||
@@ -53,2 +54,3 @@ if (!Boolean(poll.certkey)) throw 'no certkey'; | ||
if (!Boolean(poll.adminkey)) throw 'no adminkey'; | ||
console.log("Checking approval"); | ||
var pubPoint = ec.keyFromPublic(poll.adminkey, 'hex').getPublic(); | ||
@@ -60,4 +62,7 @@ var x = pubPoint.getX().toString('hex'); | ||
var key = ec.keyFromPublic(pub, 'hex'); | ||
var certScript = _hash('sha256',_hash('sha256',getPollToken(poll))); | ||
resolve(key.verify(certScript, poll.approval)); | ||
var certScript = _hash('sha256',_hash('sha256', getPollToken(poll))); | ||
var verification = key.verify(certScript, poll.approval); | ||
console.log("Verification of approval"); | ||
console.log(verification); | ||
resolve(verification); | ||
} | ||
@@ -64,0 +69,0 @@ } catch(e) { |
{ | ||
"name": "bitagora-booth", | ||
"version": "1.0.127", | ||
"version": "1.0.128", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "author": "Ignasi Ribó, 2018", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74019
8
2811