1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const argparse_1 = require("argparse");
|
4 |
|
5 | const colors = require("colors/safe");
|
6 | const path_1 = require("path");
|
7 | const tsrepl_1 = require("./tsrepl");
|
8 | function main(originalArgs) {
|
9 | const parser = new argparse_1.ArgumentParser({ description: "The IOV-Core REPL" });
|
10 | parser.addArgument("--version", {
|
11 | action: "storeTrue",
|
12 | help: "Print version and exit",
|
13 | });
|
14 | const maintainerGroup = parser.addArgumentGroup({
|
15 | title: "Maintainer options",
|
16 | description: "Don't use those unless a maintainer tells you to.",
|
17 | });
|
18 | maintainerGroup.addArgument("--selftest", {
|
19 | action: "storeTrue",
|
20 | help: "Run a selftext and exit",
|
21 | });
|
22 | maintainerGroup.addArgument("--debug", {
|
23 | action: "storeTrue",
|
24 | help: "Enable debugging",
|
25 | });
|
26 | const args = parser.parseArgs([...originalArgs]);
|
27 | if (args.version) {
|
28 | const version = require(path_1.join(__dirname, "..", "package.json")).version;
|
29 | console.info(version);
|
30 | return;
|
31 | }
|
32 | const imports = new Map([
|
33 | [
|
34 | "@iov/bcp",
|
35 | [
|
36 | "Address",
|
37 | "Algorithm",
|
38 | "ChainId",
|
39 | "Nonce",
|
40 | "PubkeyBytes",
|
41 | "SendTransaction",
|
42 | "TokenTicker",
|
43 | "TransactionId",
|
44 |
|
45 | "BlockInfoPending",
|
46 | "BlockInfoSucceeded",
|
47 | "BlockInfoFailed",
|
48 | "BlockInfo",
|
49 | "isBlockInfoPending",
|
50 | "isBlockInfoSucceeded",
|
51 | "isBlockInfoFailed",
|
52 | ],
|
53 | ],
|
54 | [
|
55 | "@iov/bns",
|
56 | [
|
57 | "bnsCodec",
|
58 | "BnsConnection",
|
59 | "createBnsConnector",
|
60 |
|
61 | "electionRuleIdToAddress",
|
62 | "escrowIdToAddress",
|
63 | "multisignatureIdToAddress",
|
64 | "swapToAddress",
|
65 |
|
66 | "ChainAddressPair",
|
67 | "BnsUsernamesByOwnerQuery",
|
68 | "BnsUsernamesByUsernameQuery",
|
69 | "BnsUsernamesQuery",
|
70 | "BnsUsernameNft",
|
71 | "RegisterUsernameTx",
|
72 | "isRegisterUsernameTx",
|
73 | "UpdateTargetsOfUsernameTx",
|
74 | "isUpdateTargetsOfUsernameTx",
|
75 | "TransferUsernameTx",
|
76 | "isTransferUsernameTx",
|
77 |
|
78 | "Participant",
|
79 | "CreateMultisignatureTx",
|
80 | "isCreateMultisignatureTx",
|
81 | "UpdateMultisignatureTx",
|
82 | "isUpdateMultisignatureTx",
|
83 | "MultisignatureTx",
|
84 | "isMultisignatureTx",
|
85 |
|
86 | "CreateEscrowTx",
|
87 | "isCreateEscrowTx",
|
88 | "ReleaseEscrowTx",
|
89 | "isReleaseEscrowTx",
|
90 | "ReturnEscrowTx",
|
91 | "isReturnEscrowTx",
|
92 | "UpdateEscrowPartiesTx",
|
93 | "isUpdateEscrowPartiesTx",
|
94 |
|
95 | "AccountNft",
|
96 | "AddAccountCertificateTx",
|
97 | "DeleteAccountCertificateTx",
|
98 | "DeleteAccountTx",
|
99 | "DeleteAllAccountsTx",
|
100 | "DeleteDomainTx",
|
101 | "isAddAccountCertificateTx",
|
102 | "isDeleteAccountCertificateTx",
|
103 | "isDeleteAccountTx",
|
104 | "isDeleteAllAccountsTx",
|
105 | "isDeleteDomainTx",
|
106 | "isRegisterAccountTx",
|
107 | "isRegisterDomainTx",
|
108 | "isRenewAccountTx",
|
109 | "isRenewDomainTx",
|
110 | "isReplaceAccountMsgFeesTx",
|
111 | "isReplaceAccountTargetsTx",
|
112 | "isTransferAccountTx",
|
113 | "isTransferDomainTx",
|
114 | "isUpdateAccountConfigurationTx",
|
115 | "RegisterAccountTx",
|
116 | "RegisterDomainTx",
|
117 | "RenewAccountTx",
|
118 | "RenewDomainTx",
|
119 | "ReplaceAccountMsgFeesTx",
|
120 | "ReplaceAccountTargetsTx",
|
121 | "TransferAccountTx",
|
122 | "TransferDomainTx",
|
123 | "UpdateAccountConfigurationTx",
|
124 | ],
|
125 | ],
|
126 | [
|
127 | "@iov/crypto",
|
128 | [
|
129 | "Bip39",
|
130 | "Ed25519",
|
131 | "Ed25519Keypair",
|
132 | "EnglishMnemonic",
|
133 | "Random",
|
134 | "Secp256k1",
|
135 | "Sha256",
|
136 | "Sha512",
|
137 | "Slip10",
|
138 | "Slip10Curve",
|
139 | "Slip10RawIndex",
|
140 | ],
|
141 | ],
|
142 | [
|
143 | "@iov/encoding",
|
144 | [
|
145 | "Bech32",
|
146 | "Encoding",
|
147 | "toAscii",
|
148 | "fromAscii",
|
149 | "fromUtf8",
|
150 | "toUtf8",
|
151 | "fromHex",
|
152 | "toHex",
|
153 | "fromBase64",
|
154 | "toBase64",
|
155 |
|
156 | "Int53",
|
157 | "Uint32",
|
158 | "Uint53",
|
159 | "Uint64",
|
160 | ],
|
161 | ],
|
162 | [
|
163 | "@iov/ethereum",
|
164 | [
|
165 | "EthereumConnection",
|
166 | "EthereumConnectionOptions",
|
167 | "createEthereumConnector",
|
168 | "ethereumCodec",
|
169 | "pubkeyToAddress as ethereumPubkeyToAddress",
|
170 | ],
|
171 | ],
|
172 | ["@iov/faucets", ["IovFaucet"]],
|
173 | [
|
174 | "@iov/keycontrol",
|
175 | [
|
176 | "Ed25519HdWallet",
|
177 | "HdPaths",
|
178 | "Keyring",
|
179 | "Secp256k1HdWallet",
|
180 | "UserProfile",
|
181 | "Wallet",
|
182 | "WalletId",
|
183 | "WalletImplementationIdString",
|
184 | "WalletSerializationString",
|
185 | ],
|
186 | ],
|
187 | ["@iov/lisk", ["liskCodec", "LiskConnection", "createLiskConnector"]],
|
188 | ["@iov/multichain", ["MultiChainSigner"]],
|
189 | ]);
|
190 | console.info(colors.green("Initializing session for you. Have fun!"));
|
191 | console.info(colors.yellow("Available imports:"));
|
192 | console.info(colors.yellow(" * http"));
|
193 | console.info(colors.yellow(" * https"));
|
194 | console.info(colors.yellow(" * leveldown"));
|
195 | console.info(colors.yellow(" * levelup"));
|
196 | console.info(colors.yellow(" * from long"));
|
197 | console.info(colors.yellow(" - Long"));
|
198 | for (const moduleName of imports.keys()) {
|
199 | console.info(colors.yellow(` * from ${moduleName}`));
|
200 |
|
201 | for (const symbol of imports.get(moduleName)) {
|
202 | console.info(colors.yellow(` - ${symbol}`));
|
203 | }
|
204 | }
|
205 | let init = `
|
206 | import leveldown = require('leveldown');
|
207 | import levelup from "levelup";
|
208 | import * as http from 'http';
|
209 | import * as https from 'https';
|
210 | import Long from "long";
|
211 | `;
|
212 | for (const moduleName of imports.keys()) {
|
213 |
|
214 | init += `import { ${imports.get(moduleName).join(", ")} } from "${moduleName}";\n`;
|
215 | }
|
216 | if (args.selftest) {
|
217 |
|
218 | init += `
|
219 | const hash = new Sha512(new Uint8Array([])).digest();
|
220 | const hexHash = toHex(hash);
|
221 | export class NewDummyClass {};
|
222 |
|
223 | const profile = new UserProfile();
|
224 | const wallet = profile.addWallet(Ed25519HdWallet.fromMnemonic("degree tackle suggest window test behind mesh extra cover prepare oak script"));
|
225 | const db = levelup(leveldown('./selftest_userprofile_db'));
|
226 | await profile.storeIn(db, "secret passwd");
|
227 | const profileFromDb = await UserProfile.loadFrom(db, "secret passwd");
|
228 |
|
229 | console.info("Done testing, will exit now.");
|
230 | process.exit(0);
|
231 | `;
|
232 | }
|
233 | const tsconfigPath = path_1.join(__dirname, "..", "tsconfig_repl.json");
|
234 | const installationDir = path_1.join(__dirname, "..");
|
235 | new tsrepl_1.TsRepl(tsconfigPath, init, !!args.debug, installationDir).start().catch((error) => {
|
236 | console.error(error);
|
237 | process.exit(1);
|
238 | });
|
239 | }
|
240 | exports.main = main;
|
241 |
|
\ | No newline at end of file |