@ton/blueprint 0.14.2 → 0.15.0

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/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.15.0] - 2023-12-15
9
+
10
+ ### Added
11
+
12
+ - Added flags `--custom-version`, `--custom-key`, `--custom-type` to `run` and `verify` commands to allow better control over custom API behavior
13
+
14
+ ### Changed
15
+
16
+ - `--custom` now always adds `jsonRPC` to API URL for v2 APIs
17
+
18
+ ### Fixed
19
+
20
+ - Fixed argument handling
21
+
8
22
  ## [0.14.2] - 2023-12-01
9
23
 
10
24
  ### Changed
package/dist/cli/build.js CHANGED
@@ -23,7 +23,7 @@ const build = async (args, ui) => {
23
23
  await (0, build_1.buildAll)();
24
24
  }
25
25
  else {
26
- const sel = await selectCompile(ui, args);
26
+ const sel = await selectCompile(ui, localArgs);
27
27
  await (0, build_1.buildOne)(sel.name, ui);
28
28
  }
29
29
  };
package/dist/cli/cli.js CHANGED
@@ -91,22 +91,7 @@ async function main() {
91
91
  process.exit(1);
92
92
  }
93
93
  const ui = new InquirerUIProvider_1.InquirerUIProvider();
94
- const waitingForCustomLink = args._.includes('--custom');
95
- await runner({
96
- ...args,
97
- _: args._.filter((a, inx) => {
98
- // filter out the flags
99
- if (a.length > 1 && a[0] === '-')
100
- return false;
101
- // and endpoint urls
102
- if (waitingForCustomLink) {
103
- if (args._[inx - 1] === '--custom' && // url goes after --custom
104
- a.startsWith('http'))
105
- return false;
106
- }
107
- return true;
108
- }),
109
- }, ui);
94
+ await runner(args, ui);
110
95
  ui.close();
111
96
  }
112
97
  process.on('SIGINT', () => {
@@ -67,8 +67,8 @@ const create = async (args, ui) => {
67
67
  const localArgs = (0, arg_1.default)({
68
68
  '--type': String,
69
69
  });
70
- const name = args._.length > 1 && args._[1].trim().length > 0
71
- ? args._[1].trim()
70
+ const name = localArgs._.length > 1 && localArgs._[1].trim().length > 0
71
+ ? localArgs._[1].trim()
72
72
  : await ui.input('Contract name (PascalCase)');
73
73
  if (name.length === 0)
74
74
  throw new Error(`Cannot create a contract with an empty name`);
package/dist/cli/help.js CHANGED
@@ -34,7 +34,10 @@ Script name is matched (ignoring case) to a file in the scripts directory. If no
34
34
 
35
35
  Flags:
36
36
  --mainnet, --testnet - specifies the network to use when running the script. If not specified on the command line, it will be asked interactively.
37
- --custom [api-v2-endpoint] - indicates that a custom API should be used when running the script, and the API URL optionally.
37
+ --custom [api-endpoint] - indicates that a custom API should be used when running the script, and the API URL optionally. (example: https://testnet.toncenter.com/api/v2/)
38
+ --custom-version - specifies the API version to use with the custom API. Options: v2 (defualt), v4.
39
+ --custom-key - specifies the API key to use with the custom API, can only be used with API v2.
40
+ --custom-type - specifies the network type to be indicated to scripts. Options: custom (default), mainnet, testnet.
38
41
  --tonconnect, --tonhub, --deeplink, --mnemonic - specifies the deployer to use when running the script. If not specified on the command line, it will be asked interactively.
39
42
  --tonscan, --tonviewer, --toncx, --dton - specifies the network explorer to use when displaying links to the deployed contracts. Default: tonscan.`,
40
43
  build: `Usage: blueprint build [contract name] [flags]
@@ -53,7 +56,11 @@ Just runs \`npm test\`, which by default runs \`jest\`.`,
53
56
  Builds a contract (similar to build command) and verifies it on https://verifier.ton.org. The contract must be already deployed on the network. If the contract's name is not specified on the command line, it will be asked interactively.
54
57
 
55
58
  Flags:
56
- --mainnet, --testnet - specifies the network on which to verify the contract. If not specified on the command line, it will be asked interactively.`
59
+ --mainnet, --testnet - specifies the network to use when running the script. If not specified on the command line, it will be asked interactively.
60
+ --custom [api-endpoint] - indicates that a custom API should be used when running the script, and the API URL optionally. (example: https://testnet.toncenter.com/api/v2/) Requires --custom-type to be specified.
61
+ --custom-version - specifies the API version to use with the custom API. Options: v2 (defualt), v4.
62
+ --custom-key - specifies the API key to use with the custom API, can only be used with API v2.
63
+ --custom-type - specifies the network type to be indicated to scripts. Options: mainnet, testnet.`,
57
64
  };
58
65
  exports.additionalHelpMessages = {};
59
66
  const help = async (args, ui) => {
package/dist/cli/run.js CHANGED
@@ -1,17 +1,22 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.run = void 0;
4
7
  const createNetworkProvider_1 = require("../network/createNetworkProvider");
5
8
  const utils_1 = require("../utils");
9
+ const arg_1 = __importDefault(require("arg"));
6
10
  const run = async (args, ui) => {
11
+ const localArgs = (0, arg_1.default)(createNetworkProvider_1.argSpec);
7
12
  const { module: mod } = await (0, utils_1.selectFile)(await (0, utils_1.findScripts)(), {
8
13
  ui,
9
- hint: args._.length > 1 && args._[1].length > 0 ? args._[1] : undefined,
14
+ hint: localArgs._.length > 1 && localArgs._[1].length > 0 ? localArgs._[1] : undefined,
10
15
  });
11
16
  if (typeof mod.run !== 'function') {
12
17
  throw new Error('Function `run` is missing!');
13
18
  }
14
- const networkProvider = await (0, createNetworkProvider_1.createNetworkProvider)(ui);
15
- await mod.run(networkProvider, args._.slice(2));
19
+ const networkProvider = await (0, createNetworkProvider_1.createNetworkProvider)(ui, localArgs);
20
+ await mod.run(networkProvider, localArgs._.slice(2));
16
21
  };
17
22
  exports.run = run;
@@ -9,6 +9,7 @@ const compile_1 = require("../compile/compile");
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const createNetworkProvider_1 = require("../network/createNetworkProvider");
11
11
  const build_1 = require("./build");
12
+ const arg_1 = __importDefault(require("arg"));
12
13
  const backends = {
13
14
  mainnet: {
14
15
  verifierRegistry: core_1.Address.parse('EQDS0AW7NV1w3nFwx-mmryfpH4OGQ3PXnoFGOJA_8PTHuLrw'),
@@ -57,8 +58,9 @@ class VerifierRegistry {
57
58
  }
58
59
  }
59
60
  const verify = async (args, ui) => {
60
- const sel = await (0, build_1.selectCompile)(ui, args);
61
- const networkProvider = await (0, createNetworkProvider_1.createNetworkProvider)(ui, false);
61
+ const localArgs = (0, arg_1.default)(createNetworkProvider_1.argSpec);
62
+ const sel = await (0, build_1.selectCompile)(ui, localArgs);
63
+ const networkProvider = await (0, createNetworkProvider_1.createNetworkProvider)(ui, localArgs, false);
62
64
  const sender = networkProvider.sender();
63
65
  const senderAddress = sender.address;
64
66
  if (senderAddress === undefined) {
@@ -1,3 +1,21 @@
1
+ import arg from 'arg';
1
2
  import { UIProvider } from '../ui/UIProvider';
2
3
  import { NetworkProvider } from './NetworkProvider';
3
- export declare function createNetworkProvider(ui: UIProvider, allowCustom?: boolean): Promise<NetworkProvider>;
4
+ export declare const argSpec: {
5
+ '--mainnet': BooleanConstructor;
6
+ '--testnet': BooleanConstructor;
7
+ '--custom': StringConstructor;
8
+ '--custom-type': StringConstructor;
9
+ '--custom-version': StringConstructor;
10
+ '--custom-key': StringConstructor;
11
+ '--tonconnect': BooleanConstructor;
12
+ '--deeplink': BooleanConstructor;
13
+ '--tonhub': BooleanConstructor;
14
+ '--mnemonic': BooleanConstructor;
15
+ '--tonscan': BooleanConstructor;
16
+ '--tonviewer': BooleanConstructor;
17
+ '--toncx': BooleanConstructor;
18
+ '--dton': BooleanConstructor;
19
+ };
20
+ export type Args = arg.Result<typeof argSpec>;
21
+ export declare function createNetworkProvider(ui: UIProvider, args: Args, allowCustom?: boolean): Promise<NetworkProvider>;
@@ -15,9 +15,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  };
16
16
  var _SendProviderSender_provider, _WrappedContractProvider_address, _WrappedContractProvider_provider, _WrappedContractProvider_init, _NetworkProviderImpl_tc, _NetworkProviderImpl_sender, _NetworkProviderImpl_network, _NetworkProviderImpl_explorer, _NetworkProviderImpl_ui;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.createNetworkProvider = void 0;
18
+ exports.createNetworkProvider = exports.argSpec = void 0;
19
19
  const utils_1 = require("../utils");
20
- const arg_1 = __importDefault(require("arg"));
21
20
  const DeeplinkProvider_1 = require("./send/DeeplinkProvider");
22
21
  const TonConnectProvider_1 = require("./send/TonConnectProvider");
23
22
  const TonHubProvider_1 = require("./send/TonHubProvider");
@@ -29,10 +28,13 @@ const path_1 = __importDefault(require("path"));
29
28
  const paths_1 = require("../paths");
30
29
  const crypto_1 = require("@ton/crypto");
31
30
  const MnemonicProvider_1 = require("./send/MnemonicProvider");
32
- const argSpec = {
31
+ exports.argSpec = {
33
32
  '--mainnet': Boolean,
34
33
  '--testnet': Boolean,
35
34
  '--custom': String,
35
+ '--custom-type': String,
36
+ '--custom-version': String,
37
+ '--custom-key': String,
36
38
  '--tonconnect': Boolean,
37
39
  '--deeplink': Boolean,
38
40
  '--tonhub': Boolean,
@@ -208,22 +210,14 @@ class NetworkProviderBuilder {
208
210
  custom: this.args['--custom'] !== undefined,
209
211
  });
210
212
  if (!network) {
211
- let nets = ['mainnet', 'testnet'];
212
- if (this.allowCustom) {
213
- nets = ['mainnet', 'testnet', 'custom'];
214
- }
215
- network = await this.ui.choose('Which network do you want to use?', nets, (c) => c);
213
+ network = await this.ui.choose('Which network do you want to use?', ['mainnet', 'testnet', 'custom'], (c) => c);
216
214
  if (network === 'custom') {
217
215
  const defaultCustomEndpoint = 'http://localhost:8081/';
218
216
  this.args['--custom'] = (await this.ui.input(`Provide a custom API v2 endpoint (default is ${defaultCustomEndpoint})`)).trim();
219
217
  if (this.args['--custom'] === '')
220
218
  this.args['--custom'] = defaultCustomEndpoint;
221
- this.args['--custom'] += 'jsonRPC';
222
219
  }
223
220
  }
224
- if (network === 'custom' && !this.allowCustom) {
225
- throw new Error('Custom network is not allowed');
226
- }
227
221
  return network;
228
222
  }
229
223
  chooseExplorer() {
@@ -286,11 +280,44 @@ class NetworkProviderBuilder {
286
280
  return provider;
287
281
  }
288
282
  async build() {
289
- const network = await this.chooseNetwork();
283
+ let network = await this.chooseNetwork();
290
284
  const explorer = this.chooseExplorer();
285
+ if (network !== 'custom' &&
286
+ (this.args['--custom-key'] !== undefined ||
287
+ this.args['--custom-type'] !== undefined ||
288
+ this.args['--custom-version'] !== undefined)) {
289
+ throw new Error('Cannot use custom parameters with a non-custom network');
290
+ }
291
291
  let tc;
292
292
  if (network === 'custom') {
293
- tc = new ton_1.TonClient({ endpoint: this.args['--custom'] });
293
+ const endpoint = this.args['--custom'];
294
+ if (this.args['--custom-version'] === undefined || this.args['--custom-version'].toLowerCase() === 'v2') {
295
+ tc = new ton_1.TonClient({
296
+ endpoint: endpoint + 'jsonRPC',
297
+ apiKey: this.args['--custom-key'],
298
+ });
299
+ }
300
+ else if (this.args['--custom-version'].toLowerCase() === 'v4') {
301
+ if (this.args['--custom-key'] !== undefined) {
302
+ throw new Error('Cannot use a custom API key with a v4 API');
303
+ }
304
+ tc = new ton_1.TonClient4({
305
+ endpoint,
306
+ });
307
+ }
308
+ else {
309
+ throw new Error('Unknown API version: ' + this.args['--custom-version']);
310
+ }
311
+ if (this.args['--custom-type'] !== undefined) {
312
+ const ct = this.args['--custom-type'].toLowerCase();
313
+ if (!['mainnet', 'testnet', 'custom'].includes(ct)) {
314
+ throw new Error('Unknown network type: ' + ct);
315
+ }
316
+ network = ct;
317
+ }
318
+ else if (!this.allowCustom) {
319
+ throw new Error('The usage of this network provider requires either mainnet or testnet');
320
+ }
294
321
  }
295
322
  else {
296
323
  tc = new ton_1.TonClient4({
@@ -312,8 +339,7 @@ class NetworkProviderBuilder {
312
339
  return new NetworkProviderImpl(tc, sender, network, explorer, this.ui);
313
340
  }
314
341
  }
315
- async function createNetworkProvider(ui, allowCustom = true) {
316
- const args = (0, arg_1.default)(argSpec);
342
+ async function createNetworkProvider(ui, args, allowCustom = true) {
317
343
  return await new NetworkProviderBuilder(args, ui, allowCustom).build();
318
344
  }
319
345
  exports.createNetworkProvider = createNetworkProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ton/blueprint",
3
- "version": "0.14.2",
3
+ "version": "0.15.0",
4
4
  "description": "Framework for development of TON smart contracts",
5
5
  "main": "dist/index.js",
6
6
  "bin": "./dist/cli/cli.js",
@@ -36,7 +36,7 @@
36
36
  "dependencies": {
37
37
  "@orbs-network/ton-access": "^2.3.3",
38
38
  "@tact-lang/compiler": "^1.1.5",
39
- "@ton-community/func-js": "^0.6.2",
39
+ "@ton-community/func-js": "^0.6.3",
40
40
  "@tonconnect/sdk": "^2.1.3",
41
41
  "arg": "^5.0.2",
42
42
  "chalk": "^4.1.0",