Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
108 lines (95 loc) · 2.92 KB
/
Copy pathscript.js
File metadata and controls
108 lines (95 loc) · 2.92 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
web3.eth.defaultAccount = web3.eth.accounts[0];
var IDContract = web3.eth.contract(abi);
var ID = IDContract.at(contractAddress);
console.log(ID);
//var instructorEvent = ID.instructorInfo( {}, 'latest');
/**
var instructorEvent = ID.instructorInfo( {}, 'latest');
instructorEvent.watch(function (err, result) {
if (!err) {
if (result.blockHash != $("#instrans").html())
$(".loader").hide();
$("#insTrans").html('Block hash: ' +result.blockHash);
$("#instructor").html(web3.toAscii(result.args.fName) + ' ' + web3.toAscii(result.args.lName) + ' (' + result.args.age + ' years old)');
} else {
$(".loader").hide();
}
});
ID.countInstructors((err, res) => {
if(res)
$("#countIns").html(res.c + " Instructors");
})
$("#button").click(function() {
ID.setInstructor(web3.eth.defaultAccount, $("#age").val(), $("#fName").val(),$("#lName").val(), (err, res) => {
console.log(web3.eth.defaultAccount);
if(err){
$(".loader").hide();
}
});
$(".loader").show();
});
**/
var identityAddedEvent = ID.identityAdded( {}, 'latest');
identityAddedEvent.watch(function (err, result) {
$(".loader").hide();
if (!err) {
console.log(result.args.privateKey);
$("#show-block-data").html("This is your private key. DO NOT LOSE IT!\n" + result.args.privateKey);
$("#show-block-data").show();
} else {
console.log(err);
}
console.log("At least ran the code");
});
$("#register-button").click(function() {
ID.addIdentity(web3.eth.defaultAccount, $("#fName").val(), $("#lName").val(), $("#addr").val(), $("#dob").val(), $("#ssn").val(), (err, res) => {
if(err){
$(".loader").hide();
}
});
$(".loader").show();
});
$("#lookup-button").click(function() {
ID.getIdentity($("#private-key-in").val(), (err, res) => {
$(".loader").hide();
if(res){
console.log(res);
}
if(err){
console.log(err);
}
});
$(".loader").show();
});
//Code that creates a public Key
$("#getKeys").click(function() {
ID.getPublicKeys($("#privateKey").val() , (err, res) => {
if(res){
$("#key-list").empty();
$("#hide-until-keys").show();
jQuery.each(res, (i, val) => {
console.log(val);
$("#key-list").append("<p>"+res+"</p> <hr>");
})
console.log('it went through!');
}
if(err){
console.log(err);
}
});
});
$("#createKey").click(function() {
ID.createPublicKey($("#privateKey").val() , (err, res) => {
if(res){
console.log(res);
}
if(err){
console.log(err);
}
});
});