rocketh 0.4.40 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +3 -0
- package/.prettierrc +7 -0
- package/CHANGELOG.md +7 -0
- package/README.md +1 -21
- package/dist/chunk-KWY4QLNL.js +648 -0
- package/dist/chunk-KWY4QLNL.js.map +1 -0
- package/dist/cli.cjs +697 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +66 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +684 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +186 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -20
- package/src/cli.ts +37 -0
- package/src/environment/deployments.ts +79 -0
- package/src/environment/index.ts +392 -0
- package/src/environment/types.ts +158 -0
- package/src/executor/index.ts +302 -0
- package/src/executor/types.ts +42 -0
- package/src/index.ts +5 -0
- package/src/internal/types.ts +6 -0
- package/src/utils/fs.ts +70 -0
- package/src/utils/json.ts +26 -0
- package/tsconfig.json +15 -0
- package/tsup.config.ts +5 -0
- package/.gitattributes +0 -1
- package/bitski_subprovider.js +0 -148
- package/geth_test_server.js +0 -194
- package/index.js +0 -424
- package/provider.js +0 -58
- package/providerengine.js +0 -128
- package/run.js +0 -1575
- package/run_ganache.js +0 -27
- package/utils.js +0 -188
- package/walletprovider.js +0 -232
package/.prettierignore
ADDED
package/.prettierrc
ADDED
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
to use it with mocha for example:
|
|
4
|
-
|
|
5
|
-
```rocketh launch mocha ...```
|
|
6
|
-
|
|
7
|
-
then in your mocha test :
|
|
8
|
-
|
|
9
|
-
```js
|
|
10
|
-
...
|
|
11
|
-
const rocketh = require('rocketh');
|
|
12
|
-
const web3 = new Web3(rocketh.ethereum)
|
|
13
|
-
const accounts = rocketh.accounts; // shortcuts
|
|
14
|
-
const chainId = rocketh.chainId; // shortcuts
|
|
15
|
-
const deployments = rocketh.deployments(); // get current deployments
|
|
16
|
-
await rocketh.runStages(); // re run the deployments to a new set of contract
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
By the way rocketh lookup the dependencies (solc and ganache) in the folder you operate. so you'll need solc, ganache-cli as dependencies
|
|
20
|
-
|
|
21
|
-
support solc >= 0.4.11
|
|
1
|
+
# rocketh
|
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/utils/fs.ts
|
|
10
|
+
import fs from "fs";
|
|
11
|
+
import path from "path";
|
|
12
|
+
function traverseMultipleDirectory(dirs) {
|
|
13
|
+
const filepaths = [];
|
|
14
|
+
for (const dir of dirs) {
|
|
15
|
+
let filesStats = traverse(dir);
|
|
16
|
+
filesStats = filesStats.filter((v) => !v.directory);
|
|
17
|
+
for (const filestat of filesStats) {
|
|
18
|
+
filepaths.push(path.join(dir, filestat.relativePath));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return filepaths;
|
|
22
|
+
}
|
|
23
|
+
var traverse = function(dir, result = [], topDir, filter) {
|
|
24
|
+
fs.readdirSync(dir).forEach((name) => {
|
|
25
|
+
const fPath = path.resolve(dir, name);
|
|
26
|
+
const stats = fs.statSync(fPath);
|
|
27
|
+
if (!filter && !name.startsWith(".") || filter && filter(name, stats)) {
|
|
28
|
+
const fileStats = {
|
|
29
|
+
name,
|
|
30
|
+
path: fPath,
|
|
31
|
+
relativePath: path.relative(topDir || dir, fPath),
|
|
32
|
+
mtimeMs: stats.mtimeMs,
|
|
33
|
+
directory: stats.isDirectory()
|
|
34
|
+
};
|
|
35
|
+
if (fileStats.directory) {
|
|
36
|
+
result.push(fileStats);
|
|
37
|
+
return traverse(fPath, result, topDir || dir, filter);
|
|
38
|
+
}
|
|
39
|
+
result.push(fileStats);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/executor/index.ts
|
|
46
|
+
import path4 from "path";
|
|
47
|
+
import fs4 from "fs";
|
|
48
|
+
|
|
49
|
+
// src/environment/index.ts
|
|
50
|
+
import fs3 from "fs";
|
|
51
|
+
import { createPublicClient, custom } from "viem";
|
|
52
|
+
import { JSONRPCHTTPProvider } from "eip-1193-json-provider";
|
|
53
|
+
import path3 from "path";
|
|
54
|
+
|
|
55
|
+
// src/utils/json.ts
|
|
56
|
+
function bnReplacer(k, v) {
|
|
57
|
+
if (typeof v === "bigint") {
|
|
58
|
+
return v.toString() + "n";
|
|
59
|
+
}
|
|
60
|
+
return v;
|
|
61
|
+
}
|
|
62
|
+
function bnReviver(k, v) {
|
|
63
|
+
if (typeof v === "string" && (v.startsWith("-") ? !isNaN(parseInt(v.charAt(1))) : !isNaN(parseInt(v.charAt(0)))) && v.charAt(v.length - 1) === "n") {
|
|
64
|
+
return BigInt(v.slice(0, -1));
|
|
65
|
+
}
|
|
66
|
+
return v;
|
|
67
|
+
}
|
|
68
|
+
function JSONToString(json, space) {
|
|
69
|
+
return JSON.stringify(json, bnReplacer, space);
|
|
70
|
+
}
|
|
71
|
+
function stringToJSON(str) {
|
|
72
|
+
return JSON.parse(str, bnReviver);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/environment/deployments.ts
|
|
76
|
+
import path2 from "path";
|
|
77
|
+
import fs2 from "fs";
|
|
78
|
+
function loadDeployments(deploymentsPath, subPath, onlyABIAndAddress, expectedChainId) {
|
|
79
|
+
const deploymentsFound = {};
|
|
80
|
+
const deployPath = path2.join(deploymentsPath, subPath);
|
|
81
|
+
let filesStats;
|
|
82
|
+
try {
|
|
83
|
+
filesStats = traverse(deployPath, void 0, void 0, (name) => !name.startsWith(".") && name !== "solcInputs");
|
|
84
|
+
} catch (e) {
|
|
85
|
+
return { deployments: {} };
|
|
86
|
+
}
|
|
87
|
+
let chainId;
|
|
88
|
+
if (filesStats.length > 0) {
|
|
89
|
+
const chainIdFilepath = path2.join(deployPath, ".chainId");
|
|
90
|
+
if (fs2.existsSync(chainIdFilepath)) {
|
|
91
|
+
chainId = fs2.readFileSync(chainIdFilepath).toString().trim();
|
|
92
|
+
} else {
|
|
93
|
+
throw new Error(`A .chainId' file is expected to be present in the deployment folder for network ${subPath}`);
|
|
94
|
+
}
|
|
95
|
+
if (expectedChainId) {
|
|
96
|
+
if (expectedChainId !== chainId) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Loading deployment in folder '${deployPath}' (with chainId: ${chainId}) for a different chainId (${expectedChainId})`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
return { deployments: {} };
|
|
104
|
+
}
|
|
105
|
+
let fileNames = filesStats.map((a) => a.relativePath);
|
|
106
|
+
fileNames = fileNames.sort((a, b) => {
|
|
107
|
+
if (a < b) {
|
|
108
|
+
return -1;
|
|
109
|
+
}
|
|
110
|
+
if (a > b) {
|
|
111
|
+
return 1;
|
|
112
|
+
}
|
|
113
|
+
return 0;
|
|
114
|
+
});
|
|
115
|
+
for (const fileName of fileNames) {
|
|
116
|
+
if (fileName.substring(fileName.length - 5) === ".json") {
|
|
117
|
+
const deploymentFileName = path2.join(deployPath, fileName);
|
|
118
|
+
let deployment = JSON.parse(fs2.readFileSync(deploymentFileName).toString());
|
|
119
|
+
if (onlyABIAndAddress) {
|
|
120
|
+
deployment = {
|
|
121
|
+
address: deployment.address,
|
|
122
|
+
abi: deployment.abi,
|
|
123
|
+
linkedData: deployment.linkedData
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const name = fileName.slice(0, fileName.length - 5);
|
|
127
|
+
deploymentsFound[name] = deployment;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return { deployments: deploymentsFound, chainId };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/environment/index.ts
|
|
134
|
+
globalThis.extensions = [];
|
|
135
|
+
function extendEnvironment(extension) {
|
|
136
|
+
globalThis.extensions.push(extension);
|
|
137
|
+
}
|
|
138
|
+
globalThis.signerProtocols = {};
|
|
139
|
+
function handleSignerProtocol(protocol, getSigner) {
|
|
140
|
+
globalThis.signerProtocols[protocol] = {
|
|
141
|
+
getSigner
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
async function createEnvironment(config, providedContext) {
|
|
145
|
+
const provider = "provider" in config ? config.provider : new JSONRPCHTTPProvider(config.nodeUrl);
|
|
146
|
+
const transport = custom(provider);
|
|
147
|
+
const viemClient = createPublicClient({ transport });
|
|
148
|
+
const chainId = (await viemClient.getChainId()).toString();
|
|
149
|
+
let networkName;
|
|
150
|
+
let saveDeployments;
|
|
151
|
+
let tags = {};
|
|
152
|
+
if ("nodeUrl" in config) {
|
|
153
|
+
networkName = config.networkName;
|
|
154
|
+
saveDeployments = true;
|
|
155
|
+
} else {
|
|
156
|
+
if (config.networkName) {
|
|
157
|
+
networkName = config.networkName;
|
|
158
|
+
} else {
|
|
159
|
+
networkName = "memory";
|
|
160
|
+
}
|
|
161
|
+
if (networkName === "memory" || networkName === "hardhat") {
|
|
162
|
+
tags["memory"] = true;
|
|
163
|
+
saveDeployments = false;
|
|
164
|
+
} else {
|
|
165
|
+
saveDeployments = true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const resolvedAccounts = {};
|
|
169
|
+
const accountCache = {};
|
|
170
|
+
async function getAccount(name, accounts, accountDef) {
|
|
171
|
+
if (accountCache[name]) {
|
|
172
|
+
return accountCache[name];
|
|
173
|
+
}
|
|
174
|
+
let account;
|
|
175
|
+
if (typeof accountDef === "number") {
|
|
176
|
+
const accounts2 = await provider.request({ method: "eth_accounts" });
|
|
177
|
+
const accountPerIndex = accounts2[accountDef];
|
|
178
|
+
if (accountPerIndex) {
|
|
179
|
+
accountCache[name] = account = {
|
|
180
|
+
type: "remote",
|
|
181
|
+
address: accountPerIndex,
|
|
182
|
+
signer: provider
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
} else if (typeof accountDef === "string") {
|
|
186
|
+
if (accountDef.startsWith("0x")) {
|
|
187
|
+
if (accountDef.length === 66) {
|
|
188
|
+
const privateKeyProtocol = globalThis.signerProtocols["privateKey"];
|
|
189
|
+
if (privateKeyProtocol) {
|
|
190
|
+
const namedSigner = await privateKeyProtocol.getSigner(`privateKey:${accountDef}`);
|
|
191
|
+
const [address] = await namedSigner.signer.request({ method: "eth_accounts" });
|
|
192
|
+
accountCache[name] = account = {
|
|
193
|
+
...namedSigner,
|
|
194
|
+
address
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
accountCache[name] = account = {
|
|
199
|
+
type: "remote",
|
|
200
|
+
address: accountDef,
|
|
201
|
+
signer: provider
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
} else {
|
|
205
|
+
if (accountDef.indexOf(":") > 0) {
|
|
206
|
+
const [protocolID, extra] = accountDef.split(":");
|
|
207
|
+
const protocol = globalThis.signerProtocols[protocolID];
|
|
208
|
+
if (!protocol) {
|
|
209
|
+
throw new Error(`protocol: ${protocol} is not supported`);
|
|
210
|
+
}
|
|
211
|
+
const namedSigner = await protocol.getSigner(accountDef);
|
|
212
|
+
const [address] = await namedSigner.signer.request({ method: "eth_accounts" });
|
|
213
|
+
accountCache[name] = account = {
|
|
214
|
+
...namedSigner,
|
|
215
|
+
address
|
|
216
|
+
};
|
|
217
|
+
} else {
|
|
218
|
+
const accountFetched = await getAccount(name, accounts, accounts[accountDef]);
|
|
219
|
+
if (accountFetched) {
|
|
220
|
+
accountCache[name] = account = accountFetched;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
const accountForNetwork = accountDef[networkName] || accountDef[chainId] || accountDef["default"];
|
|
226
|
+
if (accountForNetwork) {
|
|
227
|
+
const accountFetched = await getAccount(name, accounts, accountForNetwork);
|
|
228
|
+
if (accountFetched) {
|
|
229
|
+
accountCache[name] = account = accountFetched;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return account;
|
|
234
|
+
}
|
|
235
|
+
if (providedContext.accounts) {
|
|
236
|
+
const accountNames = Object.keys(providedContext.accounts);
|
|
237
|
+
for (const accountName of accountNames) {
|
|
238
|
+
let account = await getAccount(accountName, providedContext.accounts, providedContext.accounts[accountName]);
|
|
239
|
+
resolvedAccounts[accountName] = account;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const context = {
|
|
243
|
+
accounts: resolvedAccounts,
|
|
244
|
+
artifacts: providedContext.artifacts,
|
|
245
|
+
network: {
|
|
246
|
+
name: networkName,
|
|
247
|
+
saveDeployments,
|
|
248
|
+
tags
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
const { deployments } = loadDeployments(config.deployments, context.network.name, false, chainId);
|
|
252
|
+
const namedAccounts = {};
|
|
253
|
+
const namedSigners = {};
|
|
254
|
+
const addressSigners = {};
|
|
255
|
+
for (const entry of Object.entries(resolvedAccounts)) {
|
|
256
|
+
const name = entry[0];
|
|
257
|
+
const { address, ...namedSigner } = entry[1];
|
|
258
|
+
namedAccounts[name] = address;
|
|
259
|
+
addressSigners[address] = namedSigner;
|
|
260
|
+
namedSigners[name] = namedSigner;
|
|
261
|
+
}
|
|
262
|
+
const perliminaryEnvironment = {
|
|
263
|
+
config,
|
|
264
|
+
deployments,
|
|
265
|
+
accounts: namedAccounts,
|
|
266
|
+
signers: namedSigners,
|
|
267
|
+
addressSigners,
|
|
268
|
+
artifacts: context.artifacts,
|
|
269
|
+
network: {
|
|
270
|
+
chainId,
|
|
271
|
+
name: context.network.name,
|
|
272
|
+
tags: context.network.tags,
|
|
273
|
+
provider
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
function ensureDeploymentFolder() {
|
|
277
|
+
const folderPath = path3.join(config.deployments, context.network.name);
|
|
278
|
+
fs3.mkdirSync(folderPath, { recursive: true });
|
|
279
|
+
const chainIdFilepath = path3.join(folderPath, ".chainId");
|
|
280
|
+
if (!fs3.existsSync(chainIdFilepath)) {
|
|
281
|
+
fs3.writeFileSync(chainIdFilepath, chainId);
|
|
282
|
+
}
|
|
283
|
+
return folderPath;
|
|
284
|
+
}
|
|
285
|
+
function get(name) {
|
|
286
|
+
return deployments[name];
|
|
287
|
+
}
|
|
288
|
+
async function save(name, deployment) {
|
|
289
|
+
deployments[name] = deployment;
|
|
290
|
+
if (context.network.saveDeployments) {
|
|
291
|
+
const folderPath = ensureDeploymentFolder();
|
|
292
|
+
fs3.writeFileSync(`${folderPath}/${name}.json`, JSONToString(deployment, 2));
|
|
293
|
+
}
|
|
294
|
+
return deployment;
|
|
295
|
+
}
|
|
296
|
+
async function recoverTransactionsIfAny() {
|
|
297
|
+
const filepath = path3.join(config.deployments, context.network.name, ".pending_transactions.json");
|
|
298
|
+
let existingPendingDeployments;
|
|
299
|
+
try {
|
|
300
|
+
existingPendingDeployments = stringToJSON(fs3.readFileSync(filepath, "utf-8"));
|
|
301
|
+
} catch {
|
|
302
|
+
existingPendingDeployments = [];
|
|
303
|
+
}
|
|
304
|
+
if (existingPendingDeployments.length > 0) {
|
|
305
|
+
while (existingPendingDeployments.length > 0) {
|
|
306
|
+
const pendingTransaction = existingPendingDeployments.shift();
|
|
307
|
+
if (pendingTransaction) {
|
|
308
|
+
console.log(
|
|
309
|
+
`recovering ${pendingTransaction.name} with transaction ${pendingTransaction.transaction.txHash}`
|
|
310
|
+
);
|
|
311
|
+
await waitForTransactionAndSave(pendingTransaction.name, pendingTransaction.transaction);
|
|
312
|
+
console.log(`transaction ${pendingTransaction.transaction.txHash} complete`);
|
|
313
|
+
fs3.writeFileSync(filepath, JSONToString(existingPendingDeployments, 2));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
fs3.rmSync(filepath);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
async function saveTransaction(name, transaction) {
|
|
320
|
+
if (context.network.saveDeployments) {
|
|
321
|
+
const folderPath = ensureDeploymentFolder();
|
|
322
|
+
const filepath = path3.join(folderPath, ".pending_transactions.json");
|
|
323
|
+
let existingPendingDeployments;
|
|
324
|
+
try {
|
|
325
|
+
existingPendingDeployments = stringToJSON(fs3.readFileSync(filepath, "utf-8"));
|
|
326
|
+
} catch {
|
|
327
|
+
existingPendingDeployments = [];
|
|
328
|
+
}
|
|
329
|
+
existingPendingDeployments.push({ name, transaction });
|
|
330
|
+
fs3.writeFileSync(filepath, JSONToString(existingPendingDeployments, 2));
|
|
331
|
+
}
|
|
332
|
+
return deployments;
|
|
333
|
+
}
|
|
334
|
+
async function deleteTransaction(hash) {
|
|
335
|
+
if (context.network.saveDeployments) {
|
|
336
|
+
const filepath = path3.join(config.deployments, context.network.name, ".pending_transactions.json");
|
|
337
|
+
let existingPendingDeployments;
|
|
338
|
+
try {
|
|
339
|
+
existingPendingDeployments = stringToJSON(fs3.readFileSync(filepath, "utf-8"));
|
|
340
|
+
} catch {
|
|
341
|
+
existingPendingDeployments = [];
|
|
342
|
+
}
|
|
343
|
+
existingPendingDeployments = existingPendingDeployments.filter((v) => v.transaction.txHash !== hash);
|
|
344
|
+
if (existingPendingDeployments.length === 0) {
|
|
345
|
+
fs3.rmSync(filepath);
|
|
346
|
+
} else {
|
|
347
|
+
fs3.writeFileSync(filepath, JSONToString(existingPendingDeployments, 2));
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async function exportDeploymentsAsTypes() {
|
|
352
|
+
const folderPath = "./generated";
|
|
353
|
+
fs3.mkdirSync(folderPath, { recursive: true });
|
|
354
|
+
fs3.writeFileSync(`${folderPath}/deployments.ts`, `export default ${JSONToString(deployments, 2)} as const;`);
|
|
355
|
+
}
|
|
356
|
+
async function waitForTransactionAndSave(name, pendingDeployment) {
|
|
357
|
+
const receipt = await viemClient.waitForTransactionReceipt({
|
|
358
|
+
hash: pendingDeployment.txHash
|
|
359
|
+
});
|
|
360
|
+
if (!receipt.contractAddress) {
|
|
361
|
+
throw new Error(`failed to deploy contract ${name}`);
|
|
362
|
+
}
|
|
363
|
+
const { abi, ...artifactObjectWithoutABI } = pendingDeployment.partialDeployment;
|
|
364
|
+
if (!artifactObjectWithoutABI.nonce) {
|
|
365
|
+
const transaction = await provider.request({
|
|
366
|
+
method: "eth_getTransactionByHash",
|
|
367
|
+
params: [pendingDeployment.txHash]
|
|
368
|
+
});
|
|
369
|
+
if (transaction) {
|
|
370
|
+
artifactObjectWithoutABI.nonce = transaction.nonce;
|
|
371
|
+
artifactObjectWithoutABI.txOrigin = transaction.from;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
for (const key of Object.keys(artifactObjectWithoutABI)) {
|
|
375
|
+
if (key.startsWith("_")) {
|
|
376
|
+
delete artifactObjectWithoutABI[key];
|
|
377
|
+
}
|
|
378
|
+
if (key === "evm") {
|
|
379
|
+
const { gasEstimates } = artifactObjectWithoutABI.evm;
|
|
380
|
+
artifactObjectWithoutABI.evm = {
|
|
381
|
+
gasEstimates
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const deployment = {
|
|
386
|
+
address: receipt.contractAddress,
|
|
387
|
+
txHash: pendingDeployment.txHash,
|
|
388
|
+
abi,
|
|
389
|
+
...artifactObjectWithoutABI
|
|
390
|
+
};
|
|
391
|
+
return save(name, deployment);
|
|
392
|
+
}
|
|
393
|
+
async function saveWhilePending(name, pendingDeployment) {
|
|
394
|
+
await saveTransaction(name, pendingDeployment);
|
|
395
|
+
const transaction = await provider.request({
|
|
396
|
+
method: "eth_getTransactionByHash",
|
|
397
|
+
params: [pendingDeployment.txHash]
|
|
398
|
+
});
|
|
399
|
+
const deployment = waitForTransactionAndSave(
|
|
400
|
+
name,
|
|
401
|
+
transaction ? {
|
|
402
|
+
...pendingDeployment,
|
|
403
|
+
nonce: transaction.nonce,
|
|
404
|
+
txOrigin: transaction.from
|
|
405
|
+
} : pendingDeployment
|
|
406
|
+
);
|
|
407
|
+
await deleteTransaction(pendingDeployment.txHash);
|
|
408
|
+
return deployment;
|
|
409
|
+
}
|
|
410
|
+
let env = {
|
|
411
|
+
...perliminaryEnvironment,
|
|
412
|
+
save,
|
|
413
|
+
saveWhilePending,
|
|
414
|
+
get
|
|
415
|
+
};
|
|
416
|
+
for (const extension of globalThis.extensions) {
|
|
417
|
+
env = extension(env);
|
|
418
|
+
}
|
|
419
|
+
return {
|
|
420
|
+
external: env,
|
|
421
|
+
internal: {
|
|
422
|
+
exportDeploymentsAsTypes,
|
|
423
|
+
recoverTransactionsIfAny
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// src/executor/index.ts
|
|
429
|
+
__require("esbuild-register/dist/node").register();
|
|
430
|
+
function execute(context, callback, options) {
|
|
431
|
+
const scriptModule = (env) => callback(env);
|
|
432
|
+
scriptModule.providedContext = context;
|
|
433
|
+
scriptModule.tags = options.tags;
|
|
434
|
+
scriptModule.dependencies = options.dependencies;
|
|
435
|
+
return scriptModule;
|
|
436
|
+
}
|
|
437
|
+
function readConfig(options, extra) {
|
|
438
|
+
let configFile;
|
|
439
|
+
try {
|
|
440
|
+
const configString = fs4.readFileSync("./rocketh.json", "utf-8");
|
|
441
|
+
configFile = JSON.parse(configString);
|
|
442
|
+
} catch {
|
|
443
|
+
}
|
|
444
|
+
let nodeUrl;
|
|
445
|
+
const fromEnv = process.env["ETH_NODE_URI_" + options.network];
|
|
446
|
+
if (typeof fromEnv === "string") {
|
|
447
|
+
nodeUrl = fromEnv;
|
|
448
|
+
} else {
|
|
449
|
+
if (configFile) {
|
|
450
|
+
const network = configFile.networks && configFile.networks[options.network];
|
|
451
|
+
if (network) {
|
|
452
|
+
nodeUrl = network.rpcUrl;
|
|
453
|
+
} else {
|
|
454
|
+
if (extra?.ignoreMissingRPC) {
|
|
455
|
+
nodeUrl = "";
|
|
456
|
+
} else {
|
|
457
|
+
console.error(`network "${options.network}" is not configured. Please add it to the rocketh.json file`);
|
|
458
|
+
process.exit(1);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
} else {
|
|
462
|
+
if (extra?.ignoreMissingRPC) {
|
|
463
|
+
nodeUrl = "";
|
|
464
|
+
} else {
|
|
465
|
+
console.error(`network "${options.network}" is not configured. Please add it to the rocketh.json file`);
|
|
466
|
+
process.exit(1);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return {
|
|
471
|
+
nodeUrl,
|
|
472
|
+
networkName: options.network,
|
|
473
|
+
deployments: options.deployments,
|
|
474
|
+
scripts: options.scripts,
|
|
475
|
+
tags: typeof options.tags === "undefined" ? void 0 : options.tags.split(",")
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function readAndResolveConfig(options, extra) {
|
|
479
|
+
return resolveConfig(readConfig(options, extra));
|
|
480
|
+
}
|
|
481
|
+
function resolveConfig(config) {
|
|
482
|
+
const resolvedConfig = {
|
|
483
|
+
...config,
|
|
484
|
+
networkName: config.networkName || "memory",
|
|
485
|
+
deployments: config.deployments || "deployments",
|
|
486
|
+
scripts: config.scripts || "deploy",
|
|
487
|
+
tags: config.tags || []
|
|
488
|
+
};
|
|
489
|
+
return resolvedConfig;
|
|
490
|
+
}
|
|
491
|
+
async function loadAndExecuteDeployments(config) {
|
|
492
|
+
const resolvedConfig = resolveConfig(config);
|
|
493
|
+
return executeDeployScripts(resolvedConfig);
|
|
494
|
+
}
|
|
495
|
+
async function executeDeployScripts(config) {
|
|
496
|
+
let filepaths;
|
|
497
|
+
filepaths = traverseMultipleDirectory([config.scripts]);
|
|
498
|
+
filepaths = filepaths.filter((v) => !path4.basename(v).startsWith("_")).sort((a, b) => {
|
|
499
|
+
if (a < b) {
|
|
500
|
+
return -1;
|
|
501
|
+
}
|
|
502
|
+
if (a > b) {
|
|
503
|
+
return 1;
|
|
504
|
+
}
|
|
505
|
+
return 0;
|
|
506
|
+
});
|
|
507
|
+
let providedContext;
|
|
508
|
+
const scriptModuleByFilePath = {};
|
|
509
|
+
const scriptPathBags = {};
|
|
510
|
+
const scriptFilePaths = [];
|
|
511
|
+
for (const filepath of filepaths) {
|
|
512
|
+
const scriptFilePath = path4.resolve(filepath);
|
|
513
|
+
let scriptModule;
|
|
514
|
+
try {
|
|
515
|
+
if (__require.cache) {
|
|
516
|
+
delete __require.cache[scriptFilePath];
|
|
517
|
+
}
|
|
518
|
+
scriptModule = __require(scriptFilePath);
|
|
519
|
+
if (scriptModule.default) {
|
|
520
|
+
scriptModule = scriptModule.default;
|
|
521
|
+
if (scriptModule.default) {
|
|
522
|
+
console.warn(`double default...`);
|
|
523
|
+
scriptModule = scriptModule.default;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
scriptModuleByFilePath[scriptFilePath] = scriptModule;
|
|
527
|
+
if (providedContext && providedContext !== scriptModule.providedContext) {
|
|
528
|
+
throw new Error(`context between 2 scripts is different, please share the same across them`);
|
|
529
|
+
}
|
|
530
|
+
providedContext = scriptModule.providedContext;
|
|
531
|
+
} catch (e) {
|
|
532
|
+
console.error(`could not import ${filepath}`);
|
|
533
|
+
throw e;
|
|
534
|
+
}
|
|
535
|
+
let scriptTags = scriptModule.tags;
|
|
536
|
+
if (scriptTags !== void 0) {
|
|
537
|
+
if (typeof scriptTags === "string") {
|
|
538
|
+
scriptTags = [scriptTags];
|
|
539
|
+
}
|
|
540
|
+
for (const tag of scriptTags) {
|
|
541
|
+
if (tag.indexOf(",") >= 0) {
|
|
542
|
+
throw new Error("Tag cannot contains commas");
|
|
543
|
+
}
|
|
544
|
+
const bag = scriptPathBags[tag] || [];
|
|
545
|
+
scriptPathBags[tag] = bag;
|
|
546
|
+
bag.push(scriptFilePath);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (config.tags !== void 0 && config.tags.length > 0) {
|
|
550
|
+
let found = false;
|
|
551
|
+
if (scriptTags !== void 0) {
|
|
552
|
+
for (const tagToFind of config.tags) {
|
|
553
|
+
for (const tag of scriptTags) {
|
|
554
|
+
if (tag === tagToFind) {
|
|
555
|
+
scriptFilePaths.push(scriptFilePath);
|
|
556
|
+
found = true;
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
if (found) {
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
} else {
|
|
566
|
+
scriptFilePaths.push(scriptFilePath);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (!providedContext) {
|
|
570
|
+
throw new Error(`no context loaded`);
|
|
571
|
+
}
|
|
572
|
+
const { internal, external } = await createEnvironment(config, providedContext);
|
|
573
|
+
await internal.recoverTransactionsIfAny();
|
|
574
|
+
const scriptsRegisteredToRun = {};
|
|
575
|
+
const scriptsToRun = [];
|
|
576
|
+
const scriptsToRunAtTheEnd = [];
|
|
577
|
+
function recurseDependencies(scriptFilePath) {
|
|
578
|
+
if (scriptsRegisteredToRun[scriptFilePath]) {
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
const scriptModule = scriptModuleByFilePath[scriptFilePath];
|
|
582
|
+
if (scriptModule.dependencies) {
|
|
583
|
+
for (const dependency of scriptModule.dependencies) {
|
|
584
|
+
const scriptFilePathsToAdd = scriptPathBags[dependency];
|
|
585
|
+
if (scriptFilePathsToAdd) {
|
|
586
|
+
for (const scriptFilenameToAdd of scriptFilePathsToAdd) {
|
|
587
|
+
recurseDependencies(scriptFilenameToAdd);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if (!scriptsRegisteredToRun[scriptFilePath]) {
|
|
593
|
+
if (scriptModule.runAtTheEnd) {
|
|
594
|
+
scriptsToRunAtTheEnd.push({
|
|
595
|
+
filePath: scriptFilePath,
|
|
596
|
+
func: scriptModule
|
|
597
|
+
});
|
|
598
|
+
} else {
|
|
599
|
+
scriptsToRun.push({
|
|
600
|
+
filePath: scriptFilePath,
|
|
601
|
+
func: scriptModule
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
scriptsRegisteredToRun[scriptFilePath] = true;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
for (const scriptFilePath of scriptFilePaths) {
|
|
608
|
+
recurseDependencies(scriptFilePath);
|
|
609
|
+
}
|
|
610
|
+
for (const deployScript of scriptsToRun.concat(scriptsToRunAtTheEnd)) {
|
|
611
|
+
const filename = path4.basename(deployScript.filePath);
|
|
612
|
+
let skip = false;
|
|
613
|
+
if (deployScript.func.skip) {
|
|
614
|
+
try {
|
|
615
|
+
skip = await deployScript.func.skip(external);
|
|
616
|
+
} catch (e) {
|
|
617
|
+
console.error(`skip failed for ${deployScript.filePath}`);
|
|
618
|
+
throw e;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
if (!skip) {
|
|
622
|
+
let result;
|
|
623
|
+
try {
|
|
624
|
+
result = await deployScript.func(external);
|
|
625
|
+
} catch (e) {
|
|
626
|
+
console.error(`execution failed for ${deployScript.filePath}`);
|
|
627
|
+
throw e;
|
|
628
|
+
}
|
|
629
|
+
if (result && typeof result === "boolean") {
|
|
630
|
+
const deploymentFolderPath = config.deployments;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
return external.deployments;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
export {
|
|
638
|
+
loadDeployments,
|
|
639
|
+
extendEnvironment,
|
|
640
|
+
handleSignerProtocol,
|
|
641
|
+
execute,
|
|
642
|
+
readConfig,
|
|
643
|
+
readAndResolveConfig,
|
|
644
|
+
resolveConfig,
|
|
645
|
+
loadAndExecuteDeployments,
|
|
646
|
+
executeDeployScripts
|
|
647
|
+
};
|
|
648
|
+
//# sourceMappingURL=chunk-KWY4QLNL.js.map
|