-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
72 lines (66 loc) · 1.84 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
/* eslint global-require: "off", import/no-dynamic-require: "off" */
const Constants = require("./lib/constants")
const RequestFactory = require("./lib/requestFactory")
const Analytics = require("./lib/analytics")
const Scheduler = require("./lib/scheduling")
const TxRequest = require("./lib/txRequest")
const Util = require("./lib/util")
const RequestData = require("./lib/txRequest/requestData")
const version = require('./package.json').version;
const contracts = require("./package.json").dependencies["@ethereum-alarm-clock/contracts"];
/**
*
* @param {Web3} web3 The web3 object (required).
* @param {Object} assetJSON The asset JSON object which contains the contracts names
* mapped to the addresses.
*/
module.exports = (web3, assetJSON) => {
if (!web3) {
return {
Constants,
RequestFactory,
Scheduler,
TxRequest,
Util: Util(),
RequestData,
version,
contracts
}
}
const util = Util(web3)
const requestFactory = async () => {
let contracts;
if (!assetJSON) {
const chainName = await util.getChainName()
contracts = require(`./lib/assets/${chainName}.json`)
} else {
contracts = assetJSON;
}
return new RequestFactory(contracts.requestFactory, web3)
};
const scheduler = async () => {
let contracts;
if (!assetJSON) {
const chainName = await util.getChainName()
contracts = require(`./lib/assets/${chainName}.json`)
} else {
contracts = assetJSON;
}
return new Scheduler(
contracts.blockScheduler,
contracts.timestampScheduler,
web3
)
};
return {
Constants,
requestFactory,
scheduler,
transactionRequest: address => new TxRequest(address, web3),
Util: util,
RequestData,
Analytics: new Analytics(web3, scheduler, requestFactory),
version,
contracts
}
}