-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlib3.js
76 lines (59 loc) · 2.38 KB
/
lib3.js
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
const fs = require('fs');
const Web3 = require('web3');
exports.Consensus = {
init: (contractAddress, nodeAddress, pathABI, providerAddress) => {
this.consensusNodeAddress = nodeAddress;
// Read ABI from file
const json = JSON.parse(fs.readFileSync(pathABI, 'utf8'));
const abi = json.abi;
// Create provider
const provider = new Web3.providers.HttpProvider(providerAddress);
// Create web3 instance
this.web3 = new Web3(provider);
// Create contract
this.consensusContract = new this.web3.eth.Contract(abi, contractAddress, {from: nodeAddress});
},
createConsensus: (patientId, password) => {
const passwordHash = this.web3.utils.soliditySha3(password);
return this.consensusContract.methods.createconsensus(patientId, passwordHash)
.send({ from: this.consensusNodeAddress });
},
getConsensus: (patientId) => {
return this.consensusContract.methods.getconsensus(patientId)
.call();
},
revokeConsensus: (patientId, password) => {
return this.consensusContract.methods.revokeconsensus(patientId, password)
.send({ from: this.consensusNodeAddress });
}
}
exports.Transactions = {
init: (contractAddress, nodeAddress, pathABI, providerAddress) => {
this.transactionsNodeAddress = nodeAddress;
// Read ABI from file
const json = JSON.parse(fs.readFileSync(pathABI, 'utf8'));
const abi = json.abi;
// Create provider
const provider = new Web3.providers.HttpProvider(providerAddress);
// Create web3 instance
this.web3 = new Web3(provider);
// Create contract
this.transactionsContract = new this.web3.eth.Contract(abi, contractAddress, {from: nodeAddress});
},
addTransaction: (transactionId, hash) => {
return this.transactionsContract.methods.addTransaction(transactionId, hash)
.send({ from: this.transactionsNodeAddress, gas: 250000 });
},
getHash: (transactionId) => {
return this.transactionsContract.methods.getHash(transactionId)
.call();
},
getTransactionCount: () => {
return this.transactionsContract.methods.getTransactionCount()
.call();
},
getTransaction: (internal) => {
return this.transactionsContract.methods.getTransaction(internal)
.call();
}
}