-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
84 lines (75 loc) · 2.21 KB
/
index.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
77
78
79
80
81
82
83
84
import Web3 from 'web3';
import IPFS from 'ipfs';
import CredentialGeneration from './lib/contracts/credentialGeneration';
import Commitment from './lib/contracts/commitment';
import Registration from './lib/contracts/registration';
import Python from './lib/python';
import Storage from './lib/storage';
// ABI imports, compiled with `truffle build`
const registrationJson = require('./build/contracts/Registration.json');
const credentialGenerationJson = require(
'./build/contracts/CredentialGeneration.json',
);
const commitmentJson = require('./build/contracts/Commitment.json');
// Library serves as initializer for all libs that interact with contracts
// wraps singleton http provider and web3 objects
export class ContractLibrary {
constructor(host, port, fromAddress, privateKey) {
this.httpProvider = new Web3.providers.HttpProvider(
`http://${host}:${port}`,
);
this.web3 = new Web3(this.httpProvider);
this.fromAddress = fromAddress;
this.privateKey = privateKey;
}
connectToRegistration() {
return new Registration(
this.httpProvider,
this.web3,
registrationJson,
this.fromAddress,
this.privateKey,
);
}
connectToCredentialGeneration() {
return new CredentialGeneration(
this.httpProvider,
this.web3,
credentialGenerationJson,
this.fromAddress,
this.privateKey,
);
}
connectToCommitment() {
return new Commitment(
this.httpProvider,
this.web3,
commitmentJson,
this.fromAddress,
this.privateKey,
);
}
}
// StorageLibrary serves as initializer for the IPFS Library
// wraps singleton IPFS node
export class StorageLibrary {
constructor() {
this.node = new IPFS();
}
connectToStorage() {
return new Storage(this.node);
}
}
// PythonLibrary serves as initializer for the Python Library
// wraps the Python path, e.g. a path to a virtual environment
export class PythonLibrary {
// pythonPath arg is provided as absolute
// script arg is provided as relative to Ecclesia directory
constructor(pythonPath, script) {
this.pythonPath = pythonPath;
this.script = script;
}
connectToPython() {
return new Python(this.pythonPath, this.script);
}
}