-
Notifications
You must be signed in to change notification settings - Fork 14
/
Jakefile.js
148 lines (135 loc) · 4.01 KB
/
Jakefile.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* Jakefile - tasks to manage deployment of contracts
*
* See https://jakejs.com/
*/
/* global setTimeout, clearTimeout, setInterval, clearInterval, module, require, process */
/* eslint-disable global-require */
// @ts-check
'use strict';
const io = {
sched: { setTimeout, clearTimeout, setInterval, clearInterval },
clock: () => Promise.resolve(Date.now()),
fs: require('fs'),
http: require('http'),
https: require('https'),
env: process.env,
exec: require('child_process').execSync,
};
const jake = require('jake');
// @ts-ignore
const { desc, directory, task } = jake;
// Our own libraries are written as ES6 modules.
// eslint-disable-next-line no-global-assign
require = require('esm')(module);
const { rhopm, makeAccount } = require('rchain-api');
/**
* BEGIN project-specific tasks and dependencies.
*/
const SRCS = [
'kudos.rho',
'inbox.rho',
'Issue.rho',
'directory.rho',
'memberIdGovRev.rho',
// 'Community.rho',
];
const TARGETS = Object.fromEntries(
SRCS.map((src) => [src, rhopm.rhoInfoPath(src)]),
);
/**
* See also https://github.com/rchain-community/rchain-docker-shard
* https://github.com/rchain-community/liquid-democracy/issues/17
* https://github.com/tgrospic/rnode-client-js
*
* @param {string} net
*/
const ofNet = (net) => {
const acct = (shard, pk) =>
makeAccount(
pk,
shard.observer,
{
setTimeout: io.sched.setTimeout,
clock: io.clock,
period: 7500,
},
{ phloPrice: 1, phloLimit: 250000 },
);
switch (net) {
case 'local': {
const shard = rhopm.shardIO(
io.fs.readFileSync('docker-shard/.env', 'utf8'),
io.http,
io.sched,
);
return { shard, account: acct(shard, shard.env.VALIDATOR_BOOT_PRIVATE) };
}
case 'testnet': {
const api = {
// TODO: rotate validators
boot: 'https://node2.testnet.rchain-dev.tk',
read: 'https://observer.testnet.rchain.coop',
};
// TODO: narrow http usage to request()
// so http and https are compatible
const https = io.https;
// @ts-ignore https is close enough to http
const shard = rhopm.shardAccess(io.env, api, https, {
setInterval,
clearInterval,
});
const pk = io.env.VALIDATOR_BOOT_PRIVATE;
if (!pk) throw new RangeError('missing VALIDATOR_BOOT_PRIVATE');
return { shard, account: acct(shard, pk) };
}
// TODO: factor out overlap with testnet
case 'mainnet': {
const api = {
// TODO: rotate validators
read: 'https://observer.services.mainnet.rchain.coop',
boot: 'https://node12.root-shard.mainnet.rchain.coop',
};
// TODO: narrow http usage to request()
// so http and https are compatible
const https = io.https;
// @ts-ignore https is close enough to http
const shard = rhopm.shardAccess(io.env, api, https, {
setInterval,
clearInterval,
});
const pk = io.env.VALIDATOR_BOOT_PRIVATE;
if (!pk) throw new RangeError('missing VALIDATOR_BOOT_PRIVATE');
return { shard, account: acct(shard, pk) };
}
default:
throw new TypeError(net);
// return { shard: 1, account: 2 };
}
};
const { shard, account } = ofNet(process.env.NETWORK || 'local');
desc(`deploy ${SRCS}`);
task('default', ['startShard', rhopm.rhoDir, ...Object.values(TARGETS)], () => {
console.log({ SRCS });
});
desc('start local shard with validator, observer');
task('startShard', [], () => {
if (io.env.NETWORK !== 'local') return;
io.exec('docker-compose up -d', { cwd: 'docker-shard' });
console.log(
'TODO: wait for "MultiParentCasper instance created." in the log',
);
});
directory(rhopm.rhoDir);
const contractTask = rhopm.makeContractTask(TARGETS, {
jake,
io: io.fs.promises,
shard,
account,
});
contractTask('kudos.rho');
contractTask('inbox.rho');
contractTask('directory.rho');
contractTask('memberIdGovRev.rho', ['inbox.rho', 'directory.rho']);
contractTask('Issue.rho');
// contractTask('Community.rho', ['directory.rho']);