1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| var mysql = require('mysql'); var merkle=require("./merkle.js"); var connection = mysql.createConnection({ host : 'localhost', user : 'root', password : '123', database : 'stud' }); connection.connect(); connection.query('SELECT * from websites', function (error, results, fields) { if (error) throw error; for(var i=0;i<5;i++){ console.log('The solution is: ', results[i]); } var arr=[]; for(var i=0;i<results.length;i++){ var info=results[i].id.toString()+results[i].name+results[i].sex.toString()+results[i]['enterDay']+results[i]['leaveDay']+results[i]['schoolName']+results[i]['major']+results[i]['certID']; arr.push(info); } console.log(arr);
var tree=merkle('sha1').sync(arr); var abi=[ { "constant": false, "inputs": [ { "name": "school", "type": "address" } ], "name": "newAdd", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "Ministry_of_Education", "outputs": [ { "name": "", "type": "address", "value": "0xe7ea891e572345a05a7c1e8cfd64acba914db18c" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "name": "numb", "type": "uint256" }, { "name": "Snum", "type": "uint256" }, { "name": "name", "type": "string" }, { "name": "Mroot", "type": "uint256" }, { "name": "Sign", "type": "uint256" } ], "name": "setEdu", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "name": "", "type": "uint256" }, { "name": "", "type": "uint256" } ], "name": "educate", "outputs": [ { "name": "name", "type": "string", "value": "" }, { "name": "Mroot", "type": "uint256", "value": "0" }, { "name": "Sign", "type": "uint256", "value": "0" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "name": "num3", "type": "uint256" } ], "name": "DelAdd", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "name": "", "type": "uint256" } ], "name": "num_cert", "outputs": [ { "name": "", "type": "uint256", "value": "0" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [ { "name": "", "type": "uint256" } ], "name": "Add", "outputs": [ { "name": "", "type": "address", "value": "0xc06da6e18c352a26512aa42ca050aa85a31f024c" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "name": "Snum", "type": "uint256" }, { "name": "name", "type": "string" }, { "name": "Mroot", "type": "uint256" }, { "name": "Sign", "type": "uint256" } ], "name": "newEdu", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "payable": false, "stateMutability": "nonpayable", "type": "constructor" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "op", "type": "string" }, { "indexed": false, "name": "name", "type": "string" }, { "indexed": false, "name": "Mroot", "type": "uint256" }, { "indexed": false, "name": "Sign", "type": "uint256" } ], "name": "e", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "op", "type": "string" }, { "indexed": false, "name": "Addr", "type": "address" } ], "name": "d", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "op", "type": "string" }, { "indexed": false, "name": "number", "type": "uint256" } ], "name": "f", "type": "event" } ]; console.log('the address of contract is ') console.log(abi); console.log('the Mroot of Merkle hash tree is ') console.log(tree.root());
console.log('-----get Merkle hash tree root from Local Mysql-----') console.log(tree.root())
connection.end(); })
|