bitagora-booth
Advanced tools
Comparing version 1.0.53 to 1.0.54
70
booth.js
@@ -10,6 +10,12 @@ const { | ||
const Bs58 = require('base-x')(BASE58); | ||
const protobuf = require('protobufjs') | ||
//const { protobuf } = require('sawtooth-sdk/protobuf'); | ||
const { createContext, CryptoFactory } = require('sawtooth-sdk/signing'); | ||
const { Secp256k1PrivateKey } = require('sawtooth-sdk/signing/secp256k1'); | ||
/* Protobufs */ | ||
const protobuf = require('protobufjs'); | ||
const root = protobuf.Root.fromJSON(require('./node_modules/sawtooth-sdk/protobuf/protobuf_bundle.json')); | ||
const TransactionHeader = root.lookup('TransactionHeader'); | ||
const Transaction = root.lookup('Transaction'); | ||
const Batch = root.lookup('Batch'); | ||
const BatchHeader = root.lookup('BatchHeader'); | ||
const BatchList = root.lookup('BatchList'); | ||
@@ -76,3 +82,3 @@ const today = new Date(); | ||
var payloadBytes = Buffer.from(JSON.stringify(vote)); | ||
const transactionHeaderBytes = protobuf.TransactionHeader.encode({ | ||
const transactionHeaderBytes = TransactionHeader.encode({ | ||
familyName: BITAGORA_FAMILY, | ||
@@ -88,3 +94,3 @@ familyVersion: BITAGORA_VERSION, | ||
const signature = signer.sign(transactionHeaderBytes); | ||
const transaction = protobuf.Transaction.create({ | ||
const transaction = Transaction.create({ | ||
header: transactionHeaderBytes, | ||
@@ -95,3 +101,3 @@ headerSignature: signature, | ||
const transactions = [transaction]; | ||
const batchHeaderBytes = protobuf.BatchHeader.encode({ | ||
const batchHeaderBytes = BatchHeader.encode({ | ||
signerPublicKey: vote.id, | ||
@@ -101,3 +107,3 @@ transactionIds: transactions.map((txn) => txn.headerSignature) | ||
const batchSignature = signer.sign(batchHeaderBytes); | ||
const batch = protobuf.Batch.create({ | ||
const batch = Batch.create({ | ||
header: batchHeaderBytes, | ||
@@ -107,3 +113,3 @@ headerSignature: batchSignature, | ||
}); | ||
const batchListBytes = protobuf.BatchList.encode({ | ||
const batchListBytes = BatchList.encode({ | ||
batches: [batch] | ||
@@ -170,32 +176,34 @@ }).finish(); | ||
getNodeList( function(APIs) { | ||
if (context.nodeSeed !== undefined) { | ||
let array = []; | ||
for (item in context.nodeSeed) { | ||
if (APIs.indexOf(item) === -1) array.push('http://'+item+':8008'); | ||
} | ||
APIs = array; | ||
try { | ||
if (context.nodeSeed !== undefined) { | ||
let array = []; | ||
for (item in context.nodeSeed) { | ||
if (APIs.indexOf(item) === -1) array.push('http://'+item+':8008'); | ||
} | ||
APIs = array; | ||
} | ||
let bytes = getVoteBytes(newVote, signer, context.poll); | ||
console.log("Getting bytes"); | ||
console.log(newVote); | ||
console.log(signer); | ||
console.log(context.poll); | ||
console.log(bytes); | ||
if (bytes) { | ||
sendVoteToAPIs(bytes, APIs).then((result) => { | ||
cb(result); | ||
}); | ||
} else { | ||
throw 'No bytes to send'; | ||
} | ||
} catch(e) { | ||
console.log(e); | ||
cb({ status: 'ERROR' }); | ||
} | ||
let bytes = getVoteBytes(newVote, signer, context.poll); | ||
console.log("Getting bytes"); | ||
console.log(newVote); | ||
console.log(signer); | ||
console.log(context.poll); | ||
console.log(bytes); | ||
if (bytes) { | ||
sendVoteToAPIs(bytes, APIs).then((result) => { | ||
cb(result); | ||
}); | ||
} else { | ||
throw 'No bytes to send'; | ||
} | ||
}).catch((e) => { | ||
throw e; | ||
}); | ||
}); | ||
} else { | ||
throw 'Vote is not valid'; | ||
} | ||
} catch(e) { | ||
console.log(e); | ||
cb({ status: 'ERROR' }); | ||
cb({ status: 'ERROR' }); | ||
} | ||
@@ -202,0 +210,0 @@ }; |
{ | ||
"name": "bitagora-booth", | ||
"version": "1.0.53", | ||
"version": "1.0.54", | ||
"author": "Ignasi Ribó, 2018", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
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
26241
8
781