polkadot-cli 1.8.0 → 1.8.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.
Files changed (3) hide show
  1. package/README.md +8 -0
  2. package/dist/cli.mjs +24 -24
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -773,6 +773,14 @@ tx:
773
773
  value: ${AMOUNT}
774
774
  ```
775
775
 
776
+ Hex values passed via `--var` are preserved as-is, including leading zeros. This is important for encoded call data in XCM `Transact` instructions or similar byte-array fields:
777
+
778
+ ```bash
779
+ # Encode a remark, then embed it in an XCM Transact via --var
780
+ CALL=$(dot tx.System.remark 0xdead --encode)
781
+ dot ./xcm-transact.yaml --var CALL=$CALL --encode
782
+ ```
783
+
776
784
  All existing flags work with file input — `--chain` overrides the file's `chain:` field, `--from`, `--dry-run`, `--encode`, `--yaml`, `--json`, `--output`, etc. behave identically to inline commands.
777
785
 
778
786
  ### Compute hashes
package/dist/cli.mjs CHANGED
@@ -2158,7 +2158,7 @@ var init_complete = __esm(() => {
2158
2158
  // src/cli.ts
2159
2159
  import cac from "cac";
2160
2160
  // package.json
2161
- var version = "1.8.0";
2161
+ var version = "1.8.1";
2162
2162
 
2163
2163
  // src/commands/account.ts
2164
2164
  init_accounts_store();
@@ -3440,6 +3440,7 @@ async function showItemHelp2(category, target, opts) {
3440
3440
  init_hash();
3441
3441
  init_output();
3442
3442
  init_errors();
3443
+ import { readFile as readFile3 } from "node:fs/promises";
3443
3444
  async function resolveInput(data, opts) {
3444
3445
  const sources = [data !== undefined, !!opts.file, !!opts.stdin].filter(Boolean).length;
3445
3446
  if (sources > 1) {
@@ -3449,26 +3450,15 @@ async function resolveInput(data, opts) {
3449
3450
  throw new CliError("No input provided. Pass data as argument, or use --file or --stdin");
3450
3451
  }
3451
3452
  if (opts.file) {
3452
- const buf = await Bun.file(opts.file).arrayBuffer();
3453
+ const buf = await readFile3(opts.file);
3453
3454
  return new Uint8Array(buf);
3454
3455
  }
3455
3456
  if (opts.stdin) {
3456
- const reader = Bun.stdin.stream().getReader();
3457
3457
  const chunks = [];
3458
- while (true) {
3459
- const { done, value } = await reader.read();
3460
- if (done)
3461
- break;
3462
- chunks.push(value);
3463
- }
3464
- const totalLen = chunks.reduce((sum, c) => sum + c.length, 0);
3465
- const result = new Uint8Array(totalLen);
3466
- let offset = 0;
3467
- for (const chunk of chunks) {
3468
- result.set(chunk, offset);
3469
- offset += chunk.length;
3458
+ for await (const chunk of process.stdin) {
3459
+ chunks.push(chunk);
3470
3460
  }
3471
- return result;
3461
+ return new Uint8Array(Buffer.concat(chunks));
3472
3462
  }
3473
3463
  return parseInputData(data);
3474
3464
  }
@@ -4958,7 +4948,7 @@ function watchTransaction(observable, level) {
4958
4948
 
4959
4949
  // src/config/store.ts
4960
4950
  init_types();
4961
- import { access as access3, mkdir as mkdir3, readFile as readFile3, rm as rm2, writeFile as writeFile3 } from "node:fs/promises";
4951
+ import { access as access3, mkdir as mkdir3, readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "node:fs/promises";
4962
4952
  import { homedir as homedir2 } from "node:os";
4963
4953
  import { join as join3 } from "node:path";
4964
4954
  var DOT_DIR2 = join3(homedir2(), ".polkadot");
@@ -4978,7 +4968,7 @@ async function fileExists3(path) {
4978
4968
  async function loadConfig2() {
4979
4969
  await ensureDir3(DOT_DIR2);
4980
4970
  if (await fileExists3(CONFIG_PATH2)) {
4981
- const saved = JSON.parse(await readFile3(CONFIG_PATH2, "utf-8"));
4971
+ const saved = JSON.parse(await readFile4(CONFIG_PATH2, "utf-8"));
4982
4972
  return {
4983
4973
  ...saved,
4984
4974
  chains: { ...DEFAULT_CONFIG.chains, ...saved.chains }
@@ -4995,6 +4985,7 @@ async function saveConfig2(config) {
4995
4985
 
4996
4986
  // src/core/file-loader.ts
4997
4987
  init_errors();
4988
+ import { access as access4, readFile as readFile5 } from "node:fs/promises";
4998
4989
  import { parse as parseYaml } from "yaml";
4999
4990
  var CATEGORIES = ["tx", "query", "const", "apis"];
5000
4991
  var FILE_EXTENSIONS = [".json", ".yaml", ".yml"];
@@ -5042,16 +5033,24 @@ function substituteVars(text, vars) {
5042
5033
  return envVal;
5043
5034
  if (defaultValue !== undefined)
5044
5035
  return defaultValue;
5045
- throw new CliError(`Undefined variable "\${${varName}}" in file. ` + `Provide it via --var ${varName}=VALUE, as an environment variable, ` + `or add a default with \${${varName}:-default}.`);
5036
+ throw new CliError(`Undefined variable "\${${varName}}" in file.
5037
+
5038
+ ` + ` Provide it using one of:
5039
+ ` + ` --var ${varName}=VALUE
5040
+ ` + ` ${varName}=VALUE dot ... (environment variable)
5041
+ ` + ` \${${varName}:-default} (inline default in file)`);
5046
5042
  });
5047
5043
  }
5044
+ function quoteYamlHexValues(text) {
5045
+ return text.replace(/^(\s*(?:[^:]+:\s+|-\s+))(0x[0-9a-fA-F]+)\s*$/gm, '$1"$2"');
5046
+ }
5048
5047
  async function loadCommandFile(filePath, cliVars) {
5049
- const file = Bun.file(filePath);
5050
- const exists = await file.exists();
5051
- if (!exists) {
5048
+ try {
5049
+ await access4(filePath);
5050
+ } catch {
5052
5051
  throw new CliError(`File not found: ${filePath}`);
5053
5052
  }
5054
- const rawText = await file.text();
5053
+ const rawText = await readFile5(filePath, "utf-8");
5055
5054
  if (!rawText.trim()) {
5056
5055
  throw new CliError(`File is empty: ${filePath}`);
5057
5056
  }
@@ -5070,9 +5069,10 @@ async function loadCommandFile(filePath, cliVars) {
5070
5069
  } catch {}
5071
5070
  const mergedVars = { ...fileVars, ...cliVars };
5072
5071
  const substituted = substituteVars(rawText, mergedVars);
5072
+ const textToParse = isJson ? substituted : quoteYamlHexValues(substituted);
5073
5073
  let parsed;
5074
5074
  try {
5075
- parsed = isJson ? JSON.parse(substituted) : parseYaml(substituted);
5075
+ parsed = isJson ? JSON.parse(textToParse) : parseYaml(textToParse);
5076
5076
  } catch (err) {
5077
5077
  const format = isJson ? "JSON" : "YAML";
5078
5078
  const msg = err instanceof Error ? err.message : String(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polkadot-cli",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "CLI tool for querying Polkadot-ecosystem on-chain state",
5
5
  "type": "module",
6
6
  "bin": {