This repository has been archived by the owner on Feb 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommon.ts
68 lines (58 loc) · 1.85 KB
/
common.ts
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
import fs from "fs";
const MAX_GAS_LIMIT = process.env.TX_GAS_LIMIT ? parseInt(process.env.TX_GAS_LIMIT) : 500000000;
/**
* Helper function to deal with account JSON files
* @param {string} filePath full path to file with private key
*/
function getPrivateKeyFromFile(filePath: string): string {
let privateKey;
if (fs.existsSync(filePath)) {
const account = fs.readFileSync(filePath, "utf8");
privateKey = JSON.parse(account).account_key.priv_key;
} else {
console.warn(`Path ${filePath} with private key does not exist`);
}
return privateKey;
}
/**
* Get private key of contract owner, based on several assumptions
*/
function getContractOwnerPrivateKey(
keyFile: string,
bridgeOwnerPathOverride: string,
bridgeOwnerPrivateKeyOverride: string,
): string {
let contractOwnerJsonPath;
if (bridgeOwnerPrivateKeyOverride) {
return bridgeOwnerPrivateKeyOverride;
} else if (bridgeOwnerPathOverride && fs.existsSync(bridgeOwnerPathOverride)) {
contractOwnerJsonPath = bridgeOwnerPathOverride;
} else {
contractOwnerJsonPath = keyFile;
}
return getPrivateKeyFromFile(contractOwnerJsonPath);
}
function getBlockchainNode(): string {
return process.env.BLOCKCHAIN_NODE || "http://127.0.0.1:8545";
}
function getL2BlockchainNode(): string | undefined {
return process.env.L2_BLOCKCHAIN_NODE;
}
/**
* Returns path to JSON file with address of deployed rollup smart config, which contains address and ABI
* @returns {string}
*/
function getRollupContractConfigPath(): string {
return process.env.SMC_CONFIG_PATH || "/smart_contract/data/smc_config.json";
}
function getRollupJsonPath(): string {
return process.env.ROLLUP_JSON_PATH || "/smart_contract/data/rollup.json";
}
export {
MAX_GAS_LIMIT,
getBlockchainNode,
getContractOwnerPrivateKey,
getL2BlockchainNode,
getRollupContractConfigPath,
getRollupJsonPath
};