polkadot-cli 1.16.0 → 1.17.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.
Files changed (3) hide show
  1. package/README.md +498 -150
  2. package/dist/cli.mjs +712 -224
  3. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -674,6 +674,11 @@ function printResult(data, format = "pretty") {
674
674
  function isJsonOutput(opts) {
675
675
  return opts.json === true || opts.output === "json";
676
676
  }
677
+ function writeStdout(text) {
678
+ return new Promise((resolve) => {
679
+ process.stdout.write(text, () => resolve());
680
+ });
681
+ }
677
682
  function printJsonLine(data) {
678
683
  console.log(JSON.stringify(data, replacer));
679
684
  }
@@ -853,6 +858,324 @@ var init_client = __esm(() => {
853
858
  init_errors();
854
859
  });
855
860
 
861
+ // src/core/pretty-type.ts
862
+ function visualWidth(s) {
863
+ return s.replace(ANSI_RE, "").length;
864
+ }
865
+ function paint(color, code, text) {
866
+ return color ? `${code}${text}${RESET2}` : text;
867
+ }
868
+ function defaultWidth() {
869
+ return process.stdout.columns ?? 80;
870
+ }
871
+ function resolveOpts(opts) {
872
+ return {
873
+ indent: opts.indent ?? 0,
874
+ prefix: opts.prefix ?? 0,
875
+ width: opts.width ?? defaultWidth(),
876
+ color: opts.color ?? isTTY
877
+ };
878
+ }
879
+ function compactEntry(entry, color) {
880
+ if (!entry)
881
+ return "";
882
+ switch (entry.type) {
883
+ case "primitive":
884
+ return paint(color, YELLOW2, entry.value);
885
+ case "compact": {
886
+ const inner = entry.isBig ? "u128" : "u64";
887
+ return `${paint(color, MAGENTA2, "Compact")}<${paint(color, YELLOW2, inner)}>`;
888
+ }
889
+ case "AccountId32":
890
+ return paint(color, GREEN2, "AccountId32");
891
+ case "bitSequence":
892
+ return paint(color, MAGENTA2, "BitSequence");
893
+ case "sequence":
894
+ return `${paint(color, MAGENTA2, "Vec")}<${compactEntry(entry.value, color)}>`;
895
+ case "array":
896
+ return `[${compactEntry(entry.value, color)}; ${entry.len}]`;
897
+ case "tuple":
898
+ return `(${entry.value.map((v) => compactEntry(v, color)).join(", ")})`;
899
+ case "struct": {
900
+ const fields = Object.entries(entry.value);
901
+ if (fields.length === 0)
902
+ return "{}";
903
+ const inner = fields.map(([k, v]) => `${paint(color, CYAN2, k)}: ${compactEntry(v, color)}`).join(", ");
904
+ return `{ ${inner} }`;
905
+ }
906
+ case "option":
907
+ return `${paint(color, MAGENTA2, "Option")}<${compactEntry(entry.value, color)}>`;
908
+ case "result":
909
+ return `${paint(color, MAGENTA2, "Result")}<${compactEntry(entry.value.ok, color)}, ${compactEntry(entry.value.ko, color)}>`;
910
+ case "enum": {
911
+ const variants = Object.keys(entry.value);
912
+ if (variants.length > ENUM_COMPACT_LIMIT) {
913
+ return `enum(${variants.length} variants)`;
914
+ }
915
+ return variants.map((v) => paint(color, GREEN2, v)).join(" | ");
916
+ }
917
+ case "void":
918
+ return "()";
919
+ case "lookupEntry":
920
+ return compactEntry(entry.value, color);
921
+ default:
922
+ return "unknown";
923
+ }
924
+ }
925
+ function expandEntry(entry, indent, width, color, prefix = 0) {
926
+ const compact = compactEntry(entry, color);
927
+ if (visualWidth(compact) + indent + prefix <= width)
928
+ return compact;
929
+ switch (entry.type) {
930
+ case "struct":
931
+ return expandStruct(entry.value, indent, width, color);
932
+ case "tuple":
933
+ return expandTuple(entry.value, indent, width, color);
934
+ case "sequence":
935
+ return wrapMultiline("Vec", "<", ">", entry.value, indent, width, color);
936
+ case "array": {
937
+ const inner = expandEntry(entry.value, indent + 1, width, color);
938
+ return `[${inner}; ${entry.len}]`;
939
+ }
940
+ case "option":
941
+ return wrapMultiline("Option", "<", ">", entry.value, indent, width, color);
942
+ case "result": {
943
+ const innerIndent = indent + 2;
944
+ const padding = " ".repeat(innerIndent);
945
+ const closePadding = " ".repeat(indent);
946
+ const ok = expandEntry(entry.value.ok, innerIndent, width, color);
947
+ const ko = expandEntry(entry.value.ko, innerIndent, width, color);
948
+ return `${paint(color, MAGENTA2, "Result")}<
949
+ ${padding}${ok},
950
+ ${padding}${ko}
951
+ ${closePadding}>`;
952
+ }
953
+ case "enum": {
954
+ const variants = Object.keys(entry.value);
955
+ if (variants.length > ENUM_COMPACT_LIMIT)
956
+ return `enum(${variants.length} variants)`;
957
+ return expandEnum(variants, indent, color);
958
+ }
959
+ case "lookupEntry":
960
+ return expandEntry(entry.value, indent, width, color);
961
+ default:
962
+ return compact;
963
+ }
964
+ }
965
+ function expandStruct(fields, indent, width, color) {
966
+ const entries = Object.entries(fields);
967
+ if (entries.length === 0)
968
+ return "{}";
969
+ return renderFieldList(entries, "{", "}", indent, width, color);
970
+ }
971
+ function expandTuple(items, indent, width, color) {
972
+ if (items.length === 0)
973
+ return "()";
974
+ const inner = " ".repeat(indent + 2);
975
+ const close = " ".repeat(indent);
976
+ const lines = items.map((v) => `${inner}${expandEntry(v, indent + 2, width, color)}`);
977
+ return `(
978
+ ${lines.join(`,
979
+ `)},
980
+ ${close})`;
981
+ }
982
+ function wrapMultiline(name, open, close, inner, indent, width, color) {
983
+ const innerIndent = indent + 2;
984
+ const padding = " ".repeat(innerIndent);
985
+ const closePadding = " ".repeat(indent);
986
+ const innerStr = expandEntry(inner, innerIndent, width, color);
987
+ return `${paint(color, MAGENTA2, name)}${open}
988
+ ${padding}${innerStr}
989
+ ${closePadding}${close}`;
990
+ }
991
+ function expandEnum(variants, indent, color) {
992
+ const prefix = `
993
+ ${" ".repeat(indent)}| `;
994
+ const [first, ...rest] = variants;
995
+ const head = paint(color, GREEN2, first ?? "");
996
+ if (rest.length === 0)
997
+ return head;
998
+ const tail = rest.map((v) => paint(color, GREEN2, v)).join(prefix);
999
+ return `${head}${prefix}${tail}`;
1000
+ }
1001
+ function renderFieldList(fields, open, close, indent, width, color) {
1002
+ const innerIndent = indent + 2;
1003
+ const maxNameLen = Math.max(...fields.map(([k]) => k.length));
1004
+ const align = maxNameLen <= ALIGN_PADDING_LIMIT;
1005
+ const padTo = align ? maxNameLen : 0;
1006
+ const padding = " ".repeat(innerIndent);
1007
+ const closePadding = " ".repeat(indent);
1008
+ const lines = fields.map(([k, v]) => {
1009
+ const paddedName = align ? k.padEnd(padTo) : k;
1010
+ const fieldPrefix = (align ? padTo : k.length) + 2;
1011
+ const value = expandEntry(v, innerIndent, width, color, fieldPrefix);
1012
+ return `${padding}${paint(color, CYAN2, paddedName)}: ${value}`;
1013
+ });
1014
+ return `${open}
1015
+ ${lines.join(`,
1016
+ `)},
1017
+ ${closePadding}${close}`;
1018
+ }
1019
+ function prettyType(entry, opts = {}) {
1020
+ const { indent, prefix, width, color } = resolveOpts(opts);
1021
+ const compact = compactEntry(entry, color);
1022
+ if (visualWidth(compact) + indent + prefix <= width)
1023
+ return compact;
1024
+ return expandEntry(entry, indent, width, color);
1025
+ }
1026
+ function prettyTypeById(lookup, typeId, opts = {}) {
1027
+ try {
1028
+ const entry = lookup(typeId);
1029
+ if (!entry || typeof entry.type !== "string")
1030
+ return `type(${typeId})`;
1031
+ return prettyType(entry, opts);
1032
+ } catch {
1033
+ return `type(${typeId})`;
1034
+ }
1035
+ }
1036
+ function prettyCallArgs(meta, palletName, callName, opts = {}) {
1037
+ const fields = getCallFields(meta, palletName, callName);
1038
+ if (fields === null)
1039
+ return "";
1040
+ return renderArgsFromFields(fields, opts);
1041
+ }
1042
+ function prettyEventFields(meta, palletName, eventName, opts = {}) {
1043
+ const fields = getEventFields(meta, palletName, eventName);
1044
+ if (fields === null)
1045
+ return "";
1046
+ return renderArgsFromFields(fields, opts);
1047
+ }
1048
+ function prettyRuntimeApiArgs(lookup, inputs, opts = {}) {
1049
+ if (inputs.length === 0)
1050
+ return "()";
1051
+ const namedFields = inputs.map((i) => {
1052
+ let entry;
1053
+ try {
1054
+ entry = lookup(i.type);
1055
+ if (!entry || typeof entry.type !== "string")
1056
+ entry = { type: "unknown" };
1057
+ } catch {
1058
+ entry = { type: "unknown" };
1059
+ }
1060
+ return [i.name, entry];
1061
+ });
1062
+ return renderArgsFromFields({ kind: "named", fields: namedFields }, opts);
1063
+ }
1064
+ function unwrapVariant(variant) {
1065
+ if (!variant)
1066
+ return null;
1067
+ if (variant.type === "void")
1068
+ return { kind: "void" };
1069
+ if (variant.type === "struct") {
1070
+ return {
1071
+ kind: "named",
1072
+ fields: Object.entries(variant.value)
1073
+ };
1074
+ }
1075
+ if (variant.type === "tuple") {
1076
+ return { kind: "positional", types: variant.value };
1077
+ }
1078
+ if (variant.type === "lookupEntry") {
1079
+ const inner = variant.value;
1080
+ if (inner.type === "void")
1081
+ return { kind: "void" };
1082
+ if (inner.type === "struct") {
1083
+ return {
1084
+ kind: "named",
1085
+ fields: Object.entries(inner.value)
1086
+ };
1087
+ }
1088
+ return { kind: "single", type: inner };
1089
+ }
1090
+ return null;
1091
+ }
1092
+ function getCallFields(meta, palletName, callName) {
1093
+ try {
1094
+ const palletMeta = meta.unified.pallets.find((p) => p.name === palletName);
1095
+ if (!palletMeta?.calls)
1096
+ return null;
1097
+ const callsEntry = meta.lookup(palletMeta.calls.type);
1098
+ if (callsEntry.type !== "enum")
1099
+ return null;
1100
+ const variant = callsEntry.value[callName];
1101
+ return unwrapVariant(variant);
1102
+ } catch {
1103
+ return null;
1104
+ }
1105
+ }
1106
+ function getEventFields(meta, palletName, eventName) {
1107
+ try {
1108
+ const palletMeta = meta.unified.pallets.find((p) => p.name === palletName);
1109
+ if (!palletMeta?.events)
1110
+ return null;
1111
+ const eventsEntry = meta.lookup(palletMeta.events.type);
1112
+ if (eventsEntry.type !== "enum")
1113
+ return null;
1114
+ const variant = eventsEntry.value[eventName];
1115
+ return unwrapVariant(variant);
1116
+ } catch {
1117
+ return null;
1118
+ }
1119
+ }
1120
+ function renderArgsFromFields(fields, opts) {
1121
+ const { indent, prefix, width, color } = resolveOpts(opts);
1122
+ const lead = indent + prefix;
1123
+ switch (fields.kind) {
1124
+ case "void":
1125
+ return "()";
1126
+ case "named": {
1127
+ const compact = `(${fields.fields.map(([k, v]) => `${paint(color, CYAN2, k)}: ${compactEntry(v, color)}`).join(", ")})`;
1128
+ if (visualWidth(compact) + lead <= width)
1129
+ return compact;
1130
+ return renderFieldList(fields.fields, "(", ")", indent, width, color);
1131
+ }
1132
+ case "positional": {
1133
+ const compact = `(${fields.types.map((t) => compactEntry(t, color)).join(", ")})`;
1134
+ if (visualWidth(compact) + lead <= width)
1135
+ return compact;
1136
+ const innerIndent = indent + 2;
1137
+ const padding = " ".repeat(innerIndent);
1138
+ const closePadding = " ".repeat(indent);
1139
+ const lines = fields.types.map((t) => `${padding}${expandEntry(t, innerIndent, width, color)}`);
1140
+ return `(
1141
+ ${lines.join(`,
1142
+ `)},
1143
+ ${closePadding})`;
1144
+ }
1145
+ case "single": {
1146
+ const compact = `(${compactEntry(fields.type, color)})`;
1147
+ if (visualWidth(compact) + lead <= width)
1148
+ return compact;
1149
+ const inner = expandEntry(fields.type, indent + 2, width, color);
1150
+ return `(
1151
+ ${" ".repeat(indent + 2)}${inner},
1152
+ ${" ".repeat(indent)})`;
1153
+ }
1154
+ }
1155
+ }
1156
+ function compactTypeString(entry) {
1157
+ return compactEntry(entry, false);
1158
+ }
1159
+ function compactArgsString(fields) {
1160
+ if (fields === null)
1161
+ return "";
1162
+ switch (fields.kind) {
1163
+ case "void":
1164
+ return "()";
1165
+ case "named":
1166
+ return `(${fields.fields.map(([k, v]) => `${k}: ${compactEntry(v, false)}`).join(", ")})`;
1167
+ case "positional":
1168
+ return `(${fields.types.map((t) => compactEntry(t, false)).join(", ")})`;
1169
+ case "single":
1170
+ return `(${compactEntry(fields.type, false)})`;
1171
+ }
1172
+ }
1173
+ var RESET2 = "\x1B[0m", CYAN2 = "\x1B[36m", GREEN2 = "\x1B[32m", YELLOW2 = "\x1B[33m", MAGENTA2 = "\x1B[35m", ANSI_RE, ENUM_COMPACT_LIMIT = 24, ALIGN_PADDING_LIMIT = 16;
1174
+ var init_pretty_type = __esm(() => {
1175
+ init_output();
1176
+ ANSI_RE = /\x1b\[[0-9;]*m/g;
1177
+ });
1178
+
856
1179
  // src/core/metadata.ts
857
1180
  import { getDynamicBuilder, getLookupFn } from "@polkadot-api/metadata-builders";
858
1181
  import {
@@ -1067,114 +1390,18 @@ function describeRuntimeApiMethodArgs(meta, method) {
1067
1390
  function describeType(lookup, typeId) {
1068
1391
  try {
1069
1392
  const entry = lookup(typeId);
1070
- return formatLookupEntry(entry);
1393
+ if (!entry || typeof entry.type !== "string")
1394
+ return `type(${typeId})`;
1395
+ return compactTypeString(entry);
1071
1396
  } catch {
1072
1397
  return `type(${typeId})`;
1073
1398
  }
1074
1399
  }
1075
- function formatLookupEntry(entry) {
1076
- switch (entry.type) {
1077
- case "primitive":
1078
- return entry.value;
1079
- case "compact":
1080
- return `Compact<${formatLookupEntry(entry.isBig ? { type: "primitive", value: "u128" } : { type: "primitive", value: "u64" })}>`;
1081
- case "AccountId32":
1082
- return "AccountId32";
1083
- case "bitSequence":
1084
- return "BitSequence";
1085
- case "sequence":
1086
- return `Vec<${formatLookupEntry(entry.value)}>`;
1087
- case "array":
1088
- return `[${formatLookupEntry(entry.value)}; ${entry.len}]`;
1089
- case "tuple":
1090
- return `(${entry.value.map(formatLookupEntry).join(", ")})`;
1091
- case "struct":
1092
- return `{ ${Object.entries(entry.value).map(([k, v]) => `${k}: ${formatLookupEntry(v)}`).join(", ")} }`;
1093
- case "option":
1094
- return `Option<${formatLookupEntry(entry.value)}>`;
1095
- case "result":
1096
- return `Result<${formatLookupEntry(entry.value.ok)}, ${formatLookupEntry(entry.value.ko)}>`;
1097
- case "enum": {
1098
- const variants = Object.keys(entry.value);
1099
- if (variants.length <= 4)
1100
- return variants.join(" | ");
1101
- return `enum(${variants.length} variants)`;
1102
- }
1103
- default:
1104
- return "unknown";
1105
- }
1106
- }
1107
1400
  function describeCallArgs(meta, palletName, callName) {
1108
- try {
1109
- const palletMeta = meta.unified.pallets.find((p) => p.name === palletName);
1110
- if (!palletMeta?.calls)
1111
- return "";
1112
- const callsEntry = meta.lookup(palletMeta.calls.type);
1113
- if (callsEntry.type !== "enum")
1114
- return "";
1115
- const variant = callsEntry.value[callName];
1116
- if (!variant)
1117
- return "";
1118
- if (variant.type === "void")
1119
- return "()";
1120
- if (variant.type === "struct") {
1121
- const fields = Object.entries(variant.value).map(([k, v]) => `${k}: ${formatLookupEntry(v)}`).join(", ");
1122
- return `(${fields})`;
1123
- }
1124
- if (variant.type === "lookupEntry") {
1125
- const inner = variant.value;
1126
- if (inner.type === "void")
1127
- return "()";
1128
- if (inner.type === "struct") {
1129
- const fields = Object.entries(inner.value).map(([k, v]) => `${k}: ${formatLookupEntry(v)}`).join(", ");
1130
- return `(${fields})`;
1131
- }
1132
- return `(${formatLookupEntry(inner)})`;
1133
- }
1134
- if (variant.type === "tuple") {
1135
- const types = variant.value.map(formatLookupEntry).join(", ");
1136
- return `(${types})`;
1137
- }
1138
- return "";
1139
- } catch {
1140
- return "";
1141
- }
1401
+ return compactArgsString(getCallFields(meta, palletName, callName));
1142
1402
  }
1143
1403
  function describeEventFields(meta, palletName, eventName) {
1144
- try {
1145
- const palletMeta = meta.unified.pallets.find((p) => p.name === palletName);
1146
- if (!palletMeta?.events)
1147
- return "";
1148
- const eventsEntry = meta.lookup(palletMeta.events.type);
1149
- if (eventsEntry.type !== "enum")
1150
- return "";
1151
- const variant = eventsEntry.value[eventName];
1152
- if (!variant)
1153
- return "";
1154
- if (variant.type === "void")
1155
- return "()";
1156
- if (variant.type === "struct") {
1157
- const fields = Object.entries(variant.value).map(([k, v]) => `${k}: ${formatLookupEntry(v)}`).join(", ");
1158
- return `(${fields})`;
1159
- }
1160
- if (variant.type === "lookupEntry") {
1161
- const inner = variant.value;
1162
- if (inner.type === "void")
1163
- return "()";
1164
- if (inner.type === "struct") {
1165
- const fields = Object.entries(inner.value).map(([k, v]) => `${k}: ${formatLookupEntry(v)}`).join(", ");
1166
- return `(${fields})`;
1167
- }
1168
- return `(${formatLookupEntry(inner)})`;
1169
- }
1170
- if (variant.type === "tuple") {
1171
- const types = variant.value.map(formatLookupEntry).join(", ");
1172
- return `(${types})`;
1173
- }
1174
- return "";
1175
- } catch {
1176
- return "";
1177
- }
1404
+ return compactArgsString(getEventFields(meta, palletName, eventName));
1178
1405
  }
1179
1406
  function hexToBytes(hex) {
1180
1407
  const clean = hex.startsWith("0x") ? hex.slice(2) : hex;
@@ -1188,6 +1415,7 @@ var METADATA_TIMEOUT_MS = 15000, optionalOpaqueBytes, v15Arg, PAPI_BUILTIN_EXTEN
1188
1415
  var init_metadata = __esm(() => {
1189
1416
  init_store();
1190
1417
  init_errors();
1418
+ init_pretty_type();
1191
1419
  optionalOpaqueBytes = Option(Bytes());
1192
1420
  v15Arg = toHex(u32.enc(15));
1193
1421
  PAPI_BUILTIN_EXTENSIONS = new Set([
@@ -1584,6 +1812,7 @@ var init_tx = __esm(() => {
1584
1812
  init_client();
1585
1813
  init_metadata();
1586
1814
  init_output();
1815
+ init_pretty_type();
1587
1816
  init_resolve_address();
1588
1817
  init_binary_display();
1589
1818
  init_errors();
@@ -1799,8 +2028,11 @@ async function handleCalls(target, opts) {
1799
2028
  }
1800
2029
  printHeading(`${pallet.name} Calls`);
1801
2030
  for (const c of pallet.calls) {
1802
- const args2 = describeCallArgs(meta, pallet.name, c.name);
1803
- console.log(` ${CYAN}${c.name}${RESET}${DIM}${args2}${RESET}`);
2031
+ const args2 = prettyCallArgs(meta, pallet.name, c.name, {
2032
+ indent: 2,
2033
+ prefix: c.name.length
2034
+ });
2035
+ console.log(` ${CYAN}${c.name}${RESET}${args2}`);
1804
2036
  const summary = firstSentence(c.docs);
1805
2037
  if (summary) {
1806
2038
  console.log(` ${DIM}${summary}${RESET}`);
@@ -1826,7 +2058,10 @@ async function handleCalls(target, opts) {
1826
2058
  return;
1827
2059
  }
1828
2060
  printHeading(`${pallet.name}.${callItem.name} (Call)`);
1829
- const args = describeCallArgs(meta, pallet.name, callItem.name);
2061
+ const args = prettyCallArgs(meta, pallet.name, callItem.name, {
2062
+ indent: 2,
2063
+ prefix: 6
2064
+ });
1830
2065
  console.log(` ${BOLD}Args:${RESET} ${args}`);
1831
2066
  if (callItem.docs.length) {
1832
2067
  console.log();
@@ -1885,8 +2120,11 @@ async function handleEvents(target, opts) {
1885
2120
  }
1886
2121
  printHeading(`${pallet.name} Events`);
1887
2122
  for (const e of pallet.events) {
1888
- const fields2 = describeEventFields(meta, pallet.name, e.name);
1889
- console.log(` ${CYAN}${e.name}${RESET}${DIM}${fields2}${RESET}`);
2123
+ const fields2 = prettyEventFields(meta, pallet.name, e.name, {
2124
+ indent: 2,
2125
+ prefix: e.name.length
2126
+ });
2127
+ console.log(` ${CYAN}${e.name}${RESET}${fields2}`);
1890
2128
  const summary = firstSentence(e.docs);
1891
2129
  if (summary) {
1892
2130
  console.log(` ${DIM}${summary}${RESET}`);
@@ -1912,7 +2150,10 @@ async function handleEvents(target, opts) {
1912
2150
  return;
1913
2151
  }
1914
2152
  printHeading(`${pallet.name}.${eventItem.name} (Event)`);
1915
- const fields = describeEventFields(meta, pallet.name, eventItem.name);
2153
+ const fields = prettyEventFields(meta, pallet.name, eventItem.name, {
2154
+ indent: 2,
2155
+ prefix: 8
2156
+ });
1916
2157
  console.log(` ${BOLD}Fields:${RESET} ${fields}`);
1917
2158
  if (eventItem.docs.length) {
1918
2159
  console.log();
@@ -2039,24 +2280,30 @@ async function handleStorage(target, opts) {
2039
2280
  chain: chainName,
2040
2281
  pallet: pallet.name,
2041
2282
  storage: pallet.storage.map((s) => {
2042
- const valueType = describeType(meta.lookup, s.valueTypeId);
2283
+ const valueType2 = describeType(meta.lookup, s.valueTypeId);
2043
2284
  const keyType = s.keyTypeId != null ? describeType(meta.lookup, s.keyTypeId) : undefined;
2044
- return { name: s.name, type: s.type, valueType, keyType, docs: firstSentence(s.docs) };
2285
+ return { name: s.name, type: s.type, valueType: valueType2, keyType, docs: firstSentence(s.docs) };
2045
2286
  })
2046
2287
  }));
2047
2288
  return;
2048
2289
  }
2049
2290
  printHeading(`${pallet.name} Storage`);
2050
2291
  for (const s of pallet.storage) {
2051
- const valueType = describeType(meta.lookup, s.valueTypeId);
2052
- let typeSuffix;
2053
- if (s.keyTypeId != null) {
2054
- const keyType = describeType(meta.lookup, s.keyTypeId);
2055
- typeSuffix = `: ${keyType} → ${valueType} [map]`;
2056
- } else {
2057
- typeSuffix = `: ${valueType}`;
2292
+ const isMap = s.keyTypeId != null;
2293
+ const tag = isMap ? `${DIM} [map]${RESET}` : "";
2294
+ console.log(` ${CYAN}${s.name}${RESET}${tag}`);
2295
+ if (isMap) {
2296
+ const keyType = prettyTypeById(meta.lookup, s.keyTypeId, {
2297
+ indent: 4,
2298
+ prefix: 5
2299
+ });
2300
+ console.log(` ${DIM}Key:${RESET} ${keyType}`);
2058
2301
  }
2059
- console.log(` ${CYAN}${s.name}${RESET}${DIM}${typeSuffix}${RESET}`);
2302
+ const valueType2 = prettyTypeById(meta.lookup, s.valueTypeId, {
2303
+ indent: 4,
2304
+ prefix: 7
2305
+ });
2306
+ console.log(` ${DIM}Value:${RESET} ${valueType2}`);
2060
2307
  const summary = firstSentence(s.docs);
2061
2308
  if (summary) {
2062
2309
  console.log(` ${DIM}${summary}${RESET}`);
@@ -2071,7 +2318,7 @@ async function handleStorage(target, opts) {
2071
2318
  throw new Error(suggestMessage(`storage item in ${pallet.name}`, itemName, names));
2072
2319
  }
2073
2320
  if (isJsonOutput(opts)) {
2074
- const valueType = describeType(meta.lookup, storageItem.valueTypeId);
2321
+ const valueType2 = describeType(meta.lookup, storageItem.valueTypeId);
2075
2322
  const keyType = storageItem.keyTypeId != null ? describeType(meta.lookup, storageItem.keyTypeId) : undefined;
2076
2323
  console.log(formatJson({
2077
2324
  chain: chainName,
@@ -2079,18 +2326,26 @@ async function handleStorage(target, opts) {
2079
2326
  item: storageItem.name,
2080
2327
  category: "storage",
2081
2328
  type: storageItem.type,
2082
- valueType,
2329
+ valueType: valueType2,
2083
2330
  keyType,
2084
2331
  docs: storageItem.docs
2085
2332
  }));
2086
2333
  return;
2087
2334
  }
2088
2335
  printHeading(`${pallet.name}.${storageItem.name} (Storage)`);
2089
- console.log(` ${BOLD}Type:${RESET} ${storageItem.type}`);
2090
- console.log(` ${BOLD}Value:${RESET} ${describeType(meta.lookup, storageItem.valueTypeId)}`);
2336
+ console.log(` ${BOLD}Type:${RESET} ${storageItem.type}`);
2091
2337
  if (storageItem.keyTypeId != null) {
2092
- console.log(` ${BOLD}Key:${RESET} ${describeType(meta.lookup, storageItem.keyTypeId)}`);
2338
+ const keyType = prettyTypeById(meta.lookup, storageItem.keyTypeId, {
2339
+ indent: 2,
2340
+ prefix: 7
2341
+ });
2342
+ console.log(` ${BOLD}Key:${RESET} ${keyType}`);
2093
2343
  }
2344
+ const valueType = prettyTypeById(meta.lookup, storageItem.valueTypeId, {
2345
+ indent: 2,
2346
+ prefix: 7
2347
+ });
2348
+ console.log(` ${BOLD}Value:${RESET} ${valueType}`);
2094
2349
  if (storageItem.docs.length) {
2095
2350
  console.log();
2096
2351
  printDocs(storageItem.docs);
@@ -2121,9 +2376,15 @@ async function showItemHelp(category, target, opts) {
2121
2376
  throw new Error(suggestMessage(`method in ${api.name}`, methodName, names));
2122
2377
  }
2123
2378
  printHeading(`${api.name}.${method.name} (Runtime API)`);
2124
- const argStr = describeRuntimeApiMethodArgs(meta, method);
2125
- const retStr = describeType(meta.lookup, method.output);
2126
- console.log(` ${BOLD}Args:${RESET} ${argStr}`);
2379
+ const argStr = prettyRuntimeApiArgs(meta.lookup, method.inputs, {
2380
+ indent: 2,
2381
+ prefix: 9
2382
+ });
2383
+ const retStr = prettyTypeById(meta.lookup, method.output, {
2384
+ indent: 2,
2385
+ prefix: 9
2386
+ });
2387
+ console.log(` ${BOLD}Args:${RESET} ${argStr}`);
2127
2388
  console.log(` ${BOLD}Returns:${RESET} ${retStr}`);
2128
2389
  if (method.docs.length) {
2129
2390
  console.log();
@@ -2166,7 +2427,10 @@ async function showItemHelp(category, target, opts) {
2166
2427
  throw new Error(suggestMessage(`call in ${pallet.name}`, itemName, names));
2167
2428
  }
2168
2429
  printHeading(`${pallet.name}.${callItem.name} (Call)`);
2169
- const args = describeCallArgs(meta, pallet.name, callItem.name);
2430
+ const args = prettyCallArgs(meta, pallet.name, callItem.name, {
2431
+ indent: 2,
2432
+ prefix: 6
2433
+ });
2170
2434
  console.log(` ${BOLD}Args:${RESET} ${args}`);
2171
2435
  if (callItem.docs.length) {
2172
2436
  console.log();
@@ -2193,11 +2457,19 @@ async function showItemHelp(category, target, opts) {
2193
2457
  throw new Error(suggestMessage(`storage item in ${pallet.name}`, itemName, names));
2194
2458
  }
2195
2459
  printHeading(`${pallet.name}.${storageItem.name} (Storage)`);
2196
- console.log(` ${BOLD}Type:${RESET} ${storageItem.type}`);
2197
- console.log(` ${BOLD}Value:${RESET} ${describeType(meta.lookup, storageItem.valueTypeId)}`);
2460
+ console.log(` ${BOLD}Type:${RESET} ${storageItem.type}`);
2198
2461
  if (storageItem.keyTypeId != null) {
2199
- console.log(` ${BOLD}Key:${RESET} ${describeType(meta.lookup, storageItem.keyTypeId)}`);
2462
+ const keyType = prettyTypeById(meta.lookup, storageItem.keyTypeId, {
2463
+ indent: 2,
2464
+ prefix: 7
2465
+ });
2466
+ console.log(` ${BOLD}Key:${RESET} ${keyType}`);
2200
2467
  }
2468
+ const valueType = prettyTypeById(meta.lookup, storageItem.valueTypeId, {
2469
+ indent: 2,
2470
+ prefix: 7
2471
+ });
2472
+ console.log(` ${BOLD}Value:${RESET} ${valueType}`);
2201
2473
  if (storageItem.docs.length) {
2202
2474
  console.log();
2203
2475
  printDocs(storageItem.docs);
@@ -2224,7 +2496,11 @@ async function showItemHelp(category, target, opts) {
2224
2496
  throw new Error(suggestMessage(`constant in ${pallet.name}`, itemName, names));
2225
2497
  }
2226
2498
  printHeading(`${pallet.name}.${constItem.name} (Constant)`);
2227
- console.log(` ${BOLD}Type:${RESET} ${describeType(meta.lookup, constItem.typeId)}`);
2499
+ const constType = prettyTypeById(meta.lookup, constItem.typeId, {
2500
+ indent: 2,
2501
+ prefix: 6
2502
+ });
2503
+ console.log(` ${BOLD}Type:${RESET} ${constType}`);
2228
2504
  if (constItem.docs.length) {
2229
2505
  console.log();
2230
2506
  printDocs(constItem.docs);
@@ -2242,7 +2518,10 @@ async function showItemHelp(category, target, opts) {
2242
2518
  throw new Error(suggestMessage(`event in ${pallet.name}`, itemName, names));
2243
2519
  }
2244
2520
  printHeading(`${pallet.name}.${eventItem.name} (Event)`);
2245
- const fields = describeEventFields(meta, pallet.name, eventItem.name);
2521
+ const fields = prettyEventFields(meta, pallet.name, eventItem.name, {
2522
+ indent: 2,
2523
+ prefix: 8
2524
+ });
2246
2525
  console.log(` ${BOLD}Fields:${RESET} ${fields}`);
2247
2526
  if (eventItem.docs.length) {
2248
2527
  console.log();
@@ -2277,6 +2556,7 @@ var init_focused_inspect = __esm(() => {
2277
2556
  init_client();
2278
2557
  init_metadata();
2279
2558
  init_output();
2559
+ init_pretty_type();
2280
2560
  });
2281
2561
 
2282
2562
  // src/core/hash.ts
@@ -2666,7 +2946,7 @@ var init_complete = __esm(() => {
2666
2946
  ext: "extensions"
2667
2947
  };
2668
2948
  NAMED_COMMANDS = ["chain", "account", "inspect", "hash", "sign", "parachain", "completions"];
2669
- CHAIN_SUBCOMMANDS = ["add", "remove", "update", "list"];
2949
+ CHAIN_SUBCOMMANDS = ["add", "info", "list", "remove", "update"];
2670
2950
  ACCOUNT_SUBCOMMANDS = [
2671
2951
  "add",
2672
2952
  "create",
@@ -2697,7 +2977,7 @@ var init_complete = __esm(() => {
2697
2977
  // src/cli.ts
2698
2978
  import cac from "cac";
2699
2979
  // package.json
2700
- var version = "1.16.0";
2980
+ var version = "1.17.0";
2701
2981
 
2702
2982
  // src/commands/account.ts
2703
2983
  init_accounts_store();
@@ -3540,6 +3820,8 @@ ${BOLD}Usage:${RESET}
3540
3820
  $ dot chain update <name> Re-fetch metadata for a chain
3541
3821
  $ dot chain update --all Re-fetch metadata for all configured chains
3542
3822
  $ dot chain list List configured chains
3823
+ $ dot chain info <name> Show details for a single chain
3824
+ $ dot chain <name> Shortcut for \`chain info <name>\`
3543
3825
  $ dot chain export [names...] Export chain configuration to stdout
3544
3826
  $ dot chain import <file> Import chain configuration from a file
3545
3827
 
@@ -3549,6 +3831,9 @@ ${BOLD}Examples:${RESET}
3549
3831
  $ dot chain add my-para --rpc wss://rpc.example.com --relay polkadot
3550
3832
  $ dot chain add my-para --rpc wss://rpc.example.com --relay polkadot --parachain-id 2000
3551
3833
  $ dot chain list
3834
+ $ dot chains -v
3835
+ $ dot chain info polkadot
3836
+ $ dot chain polkadot
3552
3837
  $ dot chain update kusama
3553
3838
  $ dot chain update --all
3554
3839
  $ dot chain remove kusama
@@ -3561,7 +3846,7 @@ ${BOLD}Examples:${RESET}
3561
3846
  $ dot chain import my-chains.json --no-metadata
3562
3847
  `.trimStart();
3563
3848
  function registerChainCommands(cli) {
3564
- cli.command("chain [action] [...names]", "Manage chains (add, remove, update, list, export, import)").alias("chains").option("--all", "Update/export all configured chains").option("--relay <name>", "Parent relay chain for this parachain").option("--parachain-id <id>", "Parachain ID (auto-detected if omitted with --relay)").option("--file <path>", "Output/input file for export/import").option("--overwrite", "Overwrite existing chains on import").option("--dry-run", "Preview import without applying changes").option("--no-metadata", "Skip automatic metadata fetch after import").action(async (action, names, opts) => {
3849
+ cli.command("chain [action] [...names]", "Manage chains (add, remove, update, list, export, import)").alias("chains").option("--all", "Update/export all configured chains").option("--relay <name>", "Parent relay chain for this parachain").option("--parachain-id <id>", "Parachain ID (auto-detected if omitted with --relay)").option("--file <path>", "Output/input file for export/import").option("--overwrite", "Overwrite existing chains on import").option("--dry-run", "Preview import without applying changes").option("--no-metadata", "Skip automatic metadata fetch after import").option("-v, --verbose", "Show RPC endpoints in `chains` list output").action(async (action, names, opts) => {
3565
3850
  if (!action) {
3566
3851
  if (process.argv[2] === "chains")
3567
3852
  return chainList(opts);
@@ -3575,17 +3860,24 @@ function registerChainCommands(cli) {
3575
3860
  return chainRemove(names[0], opts);
3576
3861
  case "list":
3577
3862
  return chainList(opts);
3863
+ case "info":
3864
+ return chainInfo(names[0], opts);
3578
3865
  case "update":
3579
3866
  return chainUpdate(names[0], opts);
3580
3867
  case "export":
3581
3868
  return chainExport(names, opts);
3582
3869
  case "import":
3583
3870
  return chainImport(names[0], opts);
3584
- default:
3871
+ default: {
3872
+ const config = await loadConfig();
3873
+ if (findChainName(config, action)) {
3874
+ return chainInfo(action, opts);
3875
+ }
3585
3876
  console.error(`Unknown action "${action}".
3586
3877
  `);
3587
3878
  console.log(CHAIN_HELP);
3588
3879
  process.exit(1);
3880
+ }
3589
3881
  }
3590
3882
  });
3591
3883
  }
@@ -3695,6 +3987,7 @@ async function chainList(opts = {}) {
3695
3987
  console.log(formatJson({ chains }));
3696
3988
  return;
3697
3989
  }
3990
+ const verbose = opts.verbose === true;
3698
3991
  printHeading("Configured Chains");
3699
3992
  const parachainsByRelay = new Map;
3700
3993
  const standalone = [];
@@ -3716,7 +4009,7 @@ async function chainList(opts = {}) {
3716
4009
  for (const relayName of relayNames) {
3717
4010
  const relayConfig = config.chains[relayName];
3718
4011
  if (relayConfig) {
3719
- printChainLine(" ", relayName, relayConfig);
4012
+ printChainLine(" ", relayName, relayConfig, "", verbose);
3720
4013
  }
3721
4014
  const paras = parachainsByRelay.get(relayName) ?? [];
3722
4015
  for (let i = 0;i < paras.length; i++) {
@@ -3724,17 +4017,21 @@ async function chainList(opts = {}) {
3724
4017
  const isLast = i === paras.length - 1;
3725
4018
  const prefix = isLast ? " └─ " : " ├─ ";
3726
4019
  const idSuffix = chainConfig.parachainId != null ? ` ${DIM}[${chainConfig.parachainId}]${RESET}` : "";
3727
- printChainLine(prefix, name, chainConfig, idSuffix);
4020
+ printChainLine(prefix, name, chainConfig, idSuffix, verbose);
3728
4021
  }
3729
4022
  console.log();
3730
4023
  }
3731
4024
  for (const [name, chainConfig] of standalone) {
3732
- printChainLine(" ", name, chainConfig);
4025
+ printChainLine(" ", name, chainConfig, "", verbose);
3733
4026
  }
3734
4027
  if (standalone.length > 0)
3735
4028
  console.log();
3736
4029
  }
3737
- function printChainLine(prefix, name, chainConfig, suffix = "") {
4030
+ function printChainLine(prefix, name, chainConfig, suffix = "", verbose = false) {
4031
+ if (!verbose) {
4032
+ console.log(`${prefix}${CYAN}${name}${RESET}${suffix}`);
4033
+ return;
4034
+ }
3738
4035
  const rpcs = Array.isArray(chainConfig.rpc) ? chainConfig.rpc : [chainConfig.rpc];
3739
4036
  console.log(`${prefix}${CYAN}${name}${RESET}${suffix} ${DIM}${rpcs[0]}${RESET}`);
3740
4037
  const indent = prefix.replace(/[^\s]/g, " ");
@@ -3742,6 +4039,56 @@ function printChainLine(prefix, name, chainConfig, suffix = "") {
3742
4039
  console.log(`${indent} ${DIM}${rpcs[i]}${RESET}`);
3743
4040
  }
3744
4041
  }
4042
+ async function chainInfo(name, opts = {}) {
4043
+ if (!name) {
4044
+ console.error("Usage: dot chain info <name>");
4045
+ process.exit(1);
4046
+ }
4047
+ const config = await loadConfig();
4048
+ const { name: resolved, chain } = resolveChain(config, name);
4049
+ const rpcs = Array.isArray(chain.rpc) ? chain.rpc : [chain.rpc];
4050
+ const parachains = Object.entries(config.chains).filter(([, c]) => c.relay === resolved).map(([n, c]) => ({ name: n, parachainId: c.parachainId }));
4051
+ const fingerprint = await loadMetadataFingerprint(resolved);
4052
+ if (isJsonOutput(opts)) {
4053
+ console.log(formatJson({
4054
+ name: resolved,
4055
+ rpc: rpcs,
4056
+ ...chain.relay && { relay: chain.relay },
4057
+ ...chain.parachainId != null && { parachainId: chain.parachainId },
4058
+ ...parachains.length > 0 && { parachains },
4059
+ metadata: fingerprint ? {
4060
+ specName: fingerprint.specName,
4061
+ specVersion: fingerprint.specVersion,
4062
+ fetchedAt: fingerprint.fetchedAt
4063
+ } : null
4064
+ }));
4065
+ return;
4066
+ }
4067
+ printHeading(resolved);
4068
+ console.log(` ${CYAN}rpc:${RESET}`);
4069
+ for (const rpc of rpcs) {
4070
+ console.log(` ${DIM}${rpc}${RESET}`);
4071
+ }
4072
+ if (chain.relay) {
4073
+ console.log(` ${CYAN}relay:${RESET} ${chain.relay}`);
4074
+ }
4075
+ if (chain.parachainId != null) {
4076
+ console.log(` ${CYAN}parachain id:${RESET} ${chain.parachainId}`);
4077
+ }
4078
+ if (parachains.length > 0) {
4079
+ console.log(` ${CYAN}parachains:${RESET}`);
4080
+ for (const p of parachains) {
4081
+ const idSuffix = p.parachainId != null ? ` ${DIM}[${p.parachainId}]${RESET}` : "";
4082
+ console.log(` ${p.name}${idSuffix}`);
4083
+ }
4084
+ }
4085
+ console.log(` ${CYAN}metadata:${RESET}`);
4086
+ if (fingerprint) {
4087
+ console.log(` ${fingerprint.specName} v${fingerprint.specVersion} ${DIM}(cached ${fingerprint.fetchedAt})${RESET}`);
4088
+ } else {
4089
+ console.log(` ${DIM}not cached — run \`dot chain update ${resolved}\`${RESET}`);
4090
+ }
4091
+ }
3745
4092
  async function chainUpdate(name, opts) {
3746
4093
  const config = await loadConfig();
3747
4094
  if (opts.all) {
@@ -4118,6 +4465,7 @@ init_store();
4118
4465
  init_client();
4119
4466
  init_metadata();
4120
4467
  init_output();
4468
+ init_pretty_type();
4121
4469
  async function loadMeta2(chainName, chainConfig, rpcOverride) {
4122
4470
  if (rpcOverride) {
4123
4471
  process.stderr.write(`Fetching metadata from ${chainName}...
@@ -4202,8 +4550,11 @@ async function handleCalls2(target, opts) {
4202
4550
  }
4203
4551
  printHeading(`${pallet.name} Calls`);
4204
4552
  for (const c of pallet.calls) {
4205
- const args2 = describeCallArgs(meta, pallet.name, c.name);
4206
- console.log(` ${CYAN}${c.name}${RESET}${DIM}${args2}${RESET}`);
4553
+ const args2 = prettyCallArgs(meta, pallet.name, c.name, {
4554
+ indent: 2,
4555
+ prefix: c.name.length
4556
+ });
4557
+ console.log(` ${CYAN}${c.name}${RESET}${args2}`);
4207
4558
  const summary = firstSentence(c.docs);
4208
4559
  if (summary) {
4209
4560
  console.log(` ${DIM}${summary}${RESET}`);
@@ -4229,7 +4580,10 @@ async function handleCalls2(target, opts) {
4229
4580
  return;
4230
4581
  }
4231
4582
  printHeading(`${pallet.name}.${callItem.name} (Call)`);
4232
- const args = describeCallArgs(meta, pallet.name, callItem.name);
4583
+ const args = prettyCallArgs(meta, pallet.name, callItem.name, {
4584
+ indent: 2,
4585
+ prefix: 6
4586
+ });
4233
4587
  console.log(` ${BOLD}Args:${RESET} ${args}`);
4234
4588
  if (callItem.docs.length) {
4235
4589
  console.log();
@@ -4288,8 +4642,11 @@ async function handleEvents2(target, opts) {
4288
4642
  }
4289
4643
  printHeading(`${pallet.name} Events`);
4290
4644
  for (const e of pallet.events) {
4291
- const fields2 = describeEventFields(meta, pallet.name, e.name);
4292
- console.log(` ${CYAN}${e.name}${RESET}${DIM}${fields2}${RESET}`);
4645
+ const fields2 = prettyEventFields(meta, pallet.name, e.name, {
4646
+ indent: 2,
4647
+ prefix: e.name.length
4648
+ });
4649
+ console.log(` ${CYAN}${e.name}${RESET}${fields2}`);
4293
4650
  const summary = firstSentence(e.docs);
4294
4651
  if (summary) {
4295
4652
  console.log(` ${DIM}${summary}${RESET}`);
@@ -4315,7 +4672,10 @@ async function handleEvents2(target, opts) {
4315
4672
  return;
4316
4673
  }
4317
4674
  printHeading(`${pallet.name}.${eventItem.name} (Event)`);
4318
- const fields = describeEventFields(meta, pallet.name, eventItem.name);
4675
+ const fields = prettyEventFields(meta, pallet.name, eventItem.name, {
4676
+ indent: 2,
4677
+ prefix: 8
4678
+ });
4319
4679
  console.log(` ${BOLD}Fields:${RESET} ${fields}`);
4320
4680
  if (eventItem.docs.length) {
4321
4681
  console.log();
@@ -4442,24 +4802,30 @@ async function handleStorage2(target, opts) {
4442
4802
  chain: chainName,
4443
4803
  pallet: pallet.name,
4444
4804
  storage: pallet.storage.map((s) => {
4445
- const valueType = describeType(meta.lookup, s.valueTypeId);
4805
+ const valueType2 = describeType(meta.lookup, s.valueTypeId);
4446
4806
  const keyType = s.keyTypeId != null ? describeType(meta.lookup, s.keyTypeId) : undefined;
4447
- return { name: s.name, type: s.type, valueType, keyType, docs: firstSentence(s.docs) };
4807
+ return { name: s.name, type: s.type, valueType: valueType2, keyType, docs: firstSentence(s.docs) };
4448
4808
  })
4449
4809
  }));
4450
4810
  return;
4451
4811
  }
4452
4812
  printHeading(`${pallet.name} Storage`);
4453
4813
  for (const s of pallet.storage) {
4454
- const valueType = describeType(meta.lookup, s.valueTypeId);
4455
- let typeSuffix;
4456
- if (s.keyTypeId != null) {
4457
- const keyType = describeType(meta.lookup, s.keyTypeId);
4458
- typeSuffix = `: ${keyType} → ${valueType} [map]`;
4459
- } else {
4460
- typeSuffix = `: ${valueType}`;
4814
+ const isMap = s.keyTypeId != null;
4815
+ const tag = isMap ? `${DIM} [map]${RESET}` : "";
4816
+ console.log(` ${CYAN}${s.name}${RESET}${tag}`);
4817
+ if (isMap) {
4818
+ const keyType = prettyTypeById(meta.lookup, s.keyTypeId, {
4819
+ indent: 4,
4820
+ prefix: 5
4821
+ });
4822
+ console.log(` ${DIM}Key:${RESET} ${keyType}`);
4461
4823
  }
4462
- console.log(` ${CYAN}${s.name}${RESET}${DIM}${typeSuffix}${RESET}`);
4824
+ const valueType2 = prettyTypeById(meta.lookup, s.valueTypeId, {
4825
+ indent: 4,
4826
+ prefix: 7
4827
+ });
4828
+ console.log(` ${DIM}Value:${RESET} ${valueType2}`);
4463
4829
  const summary = firstSentence(s.docs);
4464
4830
  if (summary) {
4465
4831
  console.log(` ${DIM}${summary}${RESET}`);
@@ -4474,7 +4840,7 @@ async function handleStorage2(target, opts) {
4474
4840
  throw new Error(suggestMessage(`storage item in ${pallet.name}`, itemName, names));
4475
4841
  }
4476
4842
  if (isJsonOutput(opts)) {
4477
- const valueType = describeType(meta.lookup, storageItem.valueTypeId);
4843
+ const valueType2 = describeType(meta.lookup, storageItem.valueTypeId);
4478
4844
  const keyType = storageItem.keyTypeId != null ? describeType(meta.lookup, storageItem.keyTypeId) : undefined;
4479
4845
  console.log(formatJson({
4480
4846
  chain: chainName,
@@ -4482,18 +4848,26 @@ async function handleStorage2(target, opts) {
4482
4848
  item: storageItem.name,
4483
4849
  category: "storage",
4484
4850
  type: storageItem.type,
4485
- valueType,
4851
+ valueType: valueType2,
4486
4852
  keyType,
4487
4853
  docs: storageItem.docs
4488
4854
  }));
4489
4855
  return;
4490
4856
  }
4491
4857
  printHeading(`${pallet.name}.${storageItem.name} (Storage)`);
4492
- console.log(` ${BOLD}Type:${RESET} ${storageItem.type}`);
4493
- console.log(` ${BOLD}Value:${RESET} ${describeType(meta.lookup, storageItem.valueTypeId)}`);
4858
+ console.log(` ${BOLD}Type:${RESET} ${storageItem.type}`);
4494
4859
  if (storageItem.keyTypeId != null) {
4495
- console.log(` ${BOLD}Key:${RESET} ${describeType(meta.lookup, storageItem.keyTypeId)}`);
4860
+ const keyType = prettyTypeById(meta.lookup, storageItem.keyTypeId, {
4861
+ indent: 2,
4862
+ prefix: 7
4863
+ });
4864
+ console.log(` ${BOLD}Key:${RESET} ${keyType}`);
4496
4865
  }
4866
+ const valueType = prettyTypeById(meta.lookup, storageItem.valueTypeId, {
4867
+ indent: 2,
4868
+ prefix: 7
4869
+ });
4870
+ console.log(` ${BOLD}Value:${RESET} ${valueType}`);
4497
4871
  if (storageItem.docs.length) {
4498
4872
  console.log();
4499
4873
  printDocs(storageItem.docs);
@@ -4524,9 +4898,15 @@ async function showItemHelp2(category, target, opts) {
4524
4898
  throw new Error(suggestMessage(`method in ${api.name}`, methodName, names));
4525
4899
  }
4526
4900
  printHeading(`${api.name}.${method.name} (Runtime API)`);
4527
- const argStr = describeRuntimeApiMethodArgs(meta, method);
4528
- const retStr = describeType(meta.lookup, method.output);
4529
- console.log(` ${BOLD}Args:${RESET} ${argStr}`);
4901
+ const argStr = prettyRuntimeApiArgs(meta.lookup, method.inputs, {
4902
+ indent: 2,
4903
+ prefix: 9
4904
+ });
4905
+ const retStr = prettyTypeById(meta.lookup, method.output, {
4906
+ indent: 2,
4907
+ prefix: 9
4908
+ });
4909
+ console.log(` ${BOLD}Args:${RESET} ${argStr}`);
4530
4910
  console.log(` ${BOLD}Returns:${RESET} ${retStr}`);
4531
4911
  if (method.docs.length) {
4532
4912
  console.log();
@@ -4569,7 +4949,10 @@ async function showItemHelp2(category, target, opts) {
4569
4949
  throw new Error(suggestMessage(`call in ${pallet.name}`, itemName, names));
4570
4950
  }
4571
4951
  printHeading(`${pallet.name}.${callItem.name} (Call)`);
4572
- const args = describeCallArgs(meta, pallet.name, callItem.name);
4952
+ const args = prettyCallArgs(meta, pallet.name, callItem.name, {
4953
+ indent: 2,
4954
+ prefix: 6
4955
+ });
4573
4956
  console.log(` ${BOLD}Args:${RESET} ${args}`);
4574
4957
  if (callItem.docs.length) {
4575
4958
  console.log();
@@ -4596,11 +4979,19 @@ async function showItemHelp2(category, target, opts) {
4596
4979
  throw new Error(suggestMessage(`storage item in ${pallet.name}`, itemName, names));
4597
4980
  }
4598
4981
  printHeading(`${pallet.name}.${storageItem.name} (Storage)`);
4599
- console.log(` ${BOLD}Type:${RESET} ${storageItem.type}`);
4600
- console.log(` ${BOLD}Value:${RESET} ${describeType(meta.lookup, storageItem.valueTypeId)}`);
4982
+ console.log(` ${BOLD}Type:${RESET} ${storageItem.type}`);
4601
4983
  if (storageItem.keyTypeId != null) {
4602
- console.log(` ${BOLD}Key:${RESET} ${describeType(meta.lookup, storageItem.keyTypeId)}`);
4984
+ const keyType = prettyTypeById(meta.lookup, storageItem.keyTypeId, {
4985
+ indent: 2,
4986
+ prefix: 7
4987
+ });
4988
+ console.log(` ${BOLD}Key:${RESET} ${keyType}`);
4603
4989
  }
4990
+ const valueType = prettyTypeById(meta.lookup, storageItem.valueTypeId, {
4991
+ indent: 2,
4992
+ prefix: 7
4993
+ });
4994
+ console.log(` ${BOLD}Value:${RESET} ${valueType}`);
4604
4995
  if (storageItem.docs.length) {
4605
4996
  console.log();
4606
4997
  printDocs(storageItem.docs);
@@ -4627,7 +5018,11 @@ async function showItemHelp2(category, target, opts) {
4627
5018
  throw new Error(suggestMessage(`constant in ${pallet.name}`, itemName, names));
4628
5019
  }
4629
5020
  printHeading(`${pallet.name}.${constItem.name} (Constant)`);
4630
- console.log(` ${BOLD}Type:${RESET} ${describeType(meta.lookup, constItem.typeId)}`);
5021
+ const constType = prettyTypeById(meta.lookup, constItem.typeId, {
5022
+ indent: 2,
5023
+ prefix: 6
5024
+ });
5025
+ console.log(` ${BOLD}Type:${RESET} ${constType}`);
4631
5026
  if (constItem.docs.length) {
4632
5027
  console.log();
4633
5028
  printDocs(constItem.docs);
@@ -4645,7 +5040,10 @@ async function showItemHelp2(category, target, opts) {
4645
5040
  throw new Error(suggestMessage(`event in ${pallet.name}`, itemName, names));
4646
5041
  }
4647
5042
  printHeading(`${pallet.name}.${eventItem.name} (Event)`);
4648
- const fields = describeEventFields(meta, pallet.name, eventItem.name);
5043
+ const fields = prettyEventFields(meta, pallet.name, eventItem.name, {
5044
+ indent: 2,
5045
+ prefix: 8
5046
+ });
4649
5047
  console.log(` ${BOLD}Fields:${RESET} ${fields}`);
4650
5048
  if (eventItem.docs.length) {
4651
5049
  console.log();
@@ -4720,8 +5118,16 @@ async function handleExtensions(target, opts) {
4720
5118
  return;
4721
5119
  }
4722
5120
  printHeading(`${described.identifier} (Transaction Extension)`);
4723
- console.log(` ${BOLD}Value type:${RESET} ${described.valueType}`);
4724
- console.log(` ${BOLD}AdditionalSigned:${RESET} ${described.additionalSignedType}`);
5121
+ const valueType = prettyTypeById(meta.lookup, described.valueTypeId, {
5122
+ indent: 2,
5123
+ prefix: 18
5124
+ });
5125
+ const addSigType = prettyTypeById(meta.lookup, described.additionalSignedTypeId, {
5126
+ indent: 2,
5127
+ prefix: 18
5128
+ });
5129
+ console.log(` ${BOLD}Value type:${RESET} ${valueType}`);
5130
+ console.log(` ${BOLD}AdditionalSigned:${RESET} ${addSigType}`);
4725
5131
  console.log(` ${BOLD}Handled by:${RESET} ${described.isBuiltin ? "polkadot-api (builtin)" : "user (custom — provide via --ext)"}`);
4726
5132
  if (!described.isBuiltin) {
4727
5133
  console.log();
@@ -4805,6 +5211,7 @@ init_store();
4805
5211
  init_client();
4806
5212
  init_metadata();
4807
5213
  init_output();
5214
+ init_pretty_type();
4808
5215
 
4809
5216
  // src/utils/parse-target.ts
4810
5217
  function parseTarget(input, options) {
@@ -4981,15 +5388,21 @@ function registerInspectCommand(cli) {
4981
5388
  if (pallet2.storage.length) {
4982
5389
  console.log(` ${BOLD}Storage Items:${RESET}`);
4983
5390
  for (const s of pallet2.storage) {
4984
- const valueType = describeType(meta.lookup, s.valueTypeId);
4985
- let typeSuffix;
4986
- if (s.keyTypeId != null) {
4987
- const keyType = describeType(meta.lookup, s.keyTypeId);
4988
- typeSuffix = `: ${keyType} → ${valueType} [map]`;
4989
- } else {
4990
- typeSuffix = `: ${valueType}`;
5391
+ const isMap = s.keyTypeId != null;
5392
+ const tag = isMap ? `${DIM} [map]${RESET}` : "";
5393
+ console.log(` ${CYAN}${s.name}${RESET}${tag}`);
5394
+ if (isMap) {
5395
+ const keyType = prettyTypeById(meta.lookup, s.keyTypeId, {
5396
+ indent: 6,
5397
+ prefix: 7
5398
+ });
5399
+ console.log(` ${DIM}Key:${RESET} ${keyType}`);
4991
5400
  }
4992
- console.log(` ${CYAN}${s.name}${RESET}${DIM}${typeSuffix}${RESET}`);
5401
+ const valueType = prettyTypeById(meta.lookup, s.valueTypeId, {
5402
+ indent: 6,
5403
+ prefix: 7
5404
+ });
5405
+ console.log(` ${DIM}Value:${RESET} ${valueType}`);
4993
5406
  const summary = firstSentence(s.docs);
4994
5407
  if (summary) {
4995
5408
  console.log(` ${DIM}${summary}${RESET}`);
@@ -5000,8 +5413,11 @@ function registerInspectCommand(cli) {
5000
5413
  if (pallet2.constants.length) {
5001
5414
  console.log(` ${BOLD}Constants:${RESET}`);
5002
5415
  for (const c of pallet2.constants) {
5003
- const typeStr = describeType(meta.lookup, c.typeId);
5004
- console.log(` ${CYAN}${c.name}${RESET}${DIM}: ${typeStr}${RESET}`);
5416
+ const typeStr = prettyTypeById(meta.lookup, c.typeId, {
5417
+ indent: 4,
5418
+ prefix: c.name.length + 2
5419
+ });
5420
+ console.log(` ${CYAN}${c.name}${RESET}: ${typeStr}`);
5005
5421
  const summary = firstSentence(c.docs);
5006
5422
  if (summary) {
5007
5423
  console.log(` ${DIM}${summary}${RESET}`);
@@ -5012,8 +5428,11 @@ function registerInspectCommand(cli) {
5012
5428
  if (pallet2.calls.length) {
5013
5429
  console.log(` ${BOLD}Calls:${RESET}`);
5014
5430
  for (const c of pallet2.calls) {
5015
- const args = describeCallArgs(meta, pallet2.name, c.name);
5016
- console.log(` ${CYAN}${c.name}${RESET}${DIM}${args}${RESET}`);
5431
+ const args = prettyCallArgs(meta, pallet2.name, c.name, {
5432
+ indent: 4,
5433
+ prefix: c.name.length
5434
+ });
5435
+ console.log(` ${CYAN}${c.name}${RESET}${args}`);
5017
5436
  const summary = firstSentence(c.docs);
5018
5437
  if (summary) {
5019
5438
  console.log(` ${DIM}${summary}${RESET}`);
@@ -5024,8 +5443,11 @@ function registerInspectCommand(cli) {
5024
5443
  if (pallet2.events.length) {
5025
5444
  console.log(` ${BOLD}Events:${RESET}`);
5026
5445
  for (const e of pallet2.events) {
5027
- const fields = describeEventFields(meta, pallet2.name, e.name);
5028
- console.log(` ${CYAN}${e.name}${RESET}${DIM}${fields}${RESET}`);
5446
+ const fields = prettyEventFields(meta, pallet2.name, e.name, {
5447
+ indent: 4,
5448
+ prefix: e.name.length
5449
+ });
5450
+ console.log(` ${CYAN}${e.name}${RESET}${fields}`);
5029
5451
  const summary = firstSentence(e.docs);
5030
5452
  if (summary) {
5031
5453
  console.log(` ${DIM}${summary}${RESET}`);
@@ -5127,11 +5549,19 @@ function registerInspectCommand(cli) {
5127
5549
  const storageItem = pallet.storage.find((s) => s.name.toLowerCase() === itemName.toLowerCase());
5128
5550
  if (storageItem) {
5129
5551
  printHeading(`${pallet.name}.${storageItem.name} (Storage)`);
5130
- console.log(` ${BOLD}Type:${RESET} ${storageItem.type}`);
5131
- console.log(` ${BOLD}Value:${RESET} ${describeType(meta.lookup, storageItem.valueTypeId)}`);
5552
+ console.log(` ${BOLD}Type:${RESET} ${storageItem.type}`);
5132
5553
  if (storageItem.keyTypeId != null) {
5133
- console.log(` ${BOLD}Key:${RESET} ${describeType(meta.lookup, storageItem.keyTypeId)}`);
5554
+ const keyType = prettyTypeById(meta.lookup, storageItem.keyTypeId, {
5555
+ indent: 2,
5556
+ prefix: 7
5557
+ });
5558
+ console.log(` ${BOLD}Key:${RESET} ${keyType}`);
5134
5559
  }
5560
+ const valueType = prettyTypeById(meta.lookup, storageItem.valueTypeId, {
5561
+ indent: 2,
5562
+ prefix: 7
5563
+ });
5564
+ console.log(` ${BOLD}Value:${RESET} ${valueType}`);
5135
5565
  if (storageItem.docs.length) {
5136
5566
  console.log();
5137
5567
  printDocs(storageItem.docs);
@@ -5142,7 +5572,11 @@ function registerInspectCommand(cli) {
5142
5572
  const constantItem = pallet.constants.find((c) => c.name.toLowerCase() === itemName.toLowerCase());
5143
5573
  if (constantItem) {
5144
5574
  printHeading(`${pallet.name}.${constantItem.name} (Constant)`);
5145
- console.log(` ${BOLD}Type:${RESET} ${describeType(meta.lookup, constantItem.typeId)}`);
5575
+ const typeStr = prettyTypeById(meta.lookup, constantItem.typeId, {
5576
+ indent: 2,
5577
+ prefix: 6
5578
+ });
5579
+ console.log(` ${BOLD}Type:${RESET} ${typeStr}`);
5146
5580
  if (constantItem.docs.length) {
5147
5581
  console.log();
5148
5582
  printDocs(constantItem.docs);
@@ -5153,7 +5587,10 @@ function registerInspectCommand(cli) {
5153
5587
  const callItem = pallet.calls.find((c) => c.name.toLowerCase() === itemName.toLowerCase());
5154
5588
  if (callItem) {
5155
5589
  printHeading(`${pallet.name}.${callItem.name} (Call)`);
5156
- const args = describeCallArgs(meta, pallet.name, callItem.name);
5590
+ const args = prettyCallArgs(meta, pallet.name, callItem.name, {
5591
+ indent: 2,
5592
+ prefix: 6
5593
+ });
5157
5594
  console.log(` ${BOLD}Args:${RESET} ${args}`);
5158
5595
  if (callItem.docs.length) {
5159
5596
  console.log();
@@ -5165,7 +5602,10 @@ function registerInspectCommand(cli) {
5165
5602
  const eventItem = pallet.events.find((e) => e.name.toLowerCase() === itemName.toLowerCase());
5166
5603
  if (eventItem) {
5167
5604
  printHeading(`${pallet.name}.${eventItem.name} (Event)`);
5168
- const fields = describeEventFields(meta, pallet.name, eventItem.name);
5605
+ const fields = prettyEventFields(meta, pallet.name, eventItem.name, {
5606
+ indent: 2,
5607
+ prefix: 8
5608
+ });
5169
5609
  console.log(` ${BOLD}Fields:${RESET} ${fields}`);
5170
5610
  if (eventItem.docs.length) {
5171
5611
  console.log();
@@ -5240,11 +5680,6 @@ async function handleMetadata(chain, opts) {
5240
5680
  await writeStdout(`${formatJson(buildMetadataPayload(chainName, meta, fingerprint))}
5241
5681
  `);
5242
5682
  }
5243
- function writeStdout(text) {
5244
- return new Promise((resolve) => {
5245
- process.stdout.write(text, () => resolve());
5246
- });
5247
- }
5248
5683
  function registerMetadataCommand(cli) {
5249
5684
  cli.command("metadata <chain>", "Fetch chain metadata (decoded JSON; --raw for SCALE hex)").option("--raw", "Print SCALE-encoded metadata bytes as hex instead of decoded JSON").option("--cached", "Use cached metadata instead of fetching fresh from the chain").option("--rpc <url>", "Override RPC endpoint(s)").action((chain, opts) => handleMetadata(chain, opts));
5250
5685
  }
@@ -5344,6 +5779,7 @@ init_store();
5344
5779
  init_client();
5345
5780
  init_metadata();
5346
5781
  init_output();
5782
+ init_pretty_type();
5347
5783
  init_focused_inspect();
5348
5784
  init_tx();
5349
5785
  async function handleQuery(target, keys, opts) {
@@ -5354,10 +5790,11 @@ async function handleQuery(target, keys, opts) {
5354
5790
  const pallets = listPallets(meta);
5355
5791
  const withStorage = pallets.filter((p) => p.storage.length > 0);
5356
5792
  if (isJsonOutput(opts)) {
5357
- console.log(formatJson({
5793
+ await writeStdout(`${formatJson({
5358
5794
  chain: chainName2,
5359
5795
  pallets: withStorage.map((p) => ({ name: p.name, storage: p.storage.length }))
5360
- }));
5796
+ })}
5797
+ `);
5361
5798
  return;
5362
5799
  }
5363
5800
  printHeading(`Pallets with storage on ${chainName2} (${withStorage.length})`);
@@ -5375,14 +5812,15 @@ async function handleQuery(target, keys, opts) {
5375
5812
  const pallet2 = resolvePallet(meta, palletName(target));
5376
5813
  if (pallet2.storage.length === 0) {
5377
5814
  if (isJsonOutput(opts)) {
5378
- console.log(formatJson({ chain: chainName2, pallet: pallet2.name, storage: [] }));
5815
+ await writeStdout(`${formatJson({ chain: chainName2, pallet: pallet2.name, storage: [] })}
5816
+ `);
5379
5817
  } else {
5380
5818
  console.log(`No storage items in ${pallet2.name}.`);
5381
5819
  }
5382
5820
  return;
5383
5821
  }
5384
5822
  if (isJsonOutput(opts)) {
5385
- console.log(formatJson({
5823
+ await writeStdout(`${formatJson({
5386
5824
  chain: chainName2,
5387
5825
  pallet: pallet2.name,
5388
5826
  storage: pallet2.storage.map((s) => {
@@ -5390,20 +5828,27 @@ async function handleQuery(target, keys, opts) {
5390
5828
  const keyType = s.keyTypeId != null ? describeType(meta.lookup, s.keyTypeId) : undefined;
5391
5829
  return { name: s.name, type: s.type, valueType, keyType, docs: firstSentence(s.docs) };
5392
5830
  })
5393
- }));
5831
+ })}
5832
+ `);
5394
5833
  return;
5395
5834
  }
5396
5835
  printHeading(`${pallet2.name} Storage`);
5397
5836
  for (const s of pallet2.storage) {
5398
- const valueType = describeType(meta.lookup, s.valueTypeId);
5399
- let typeSuffix;
5400
- if (s.keyTypeId != null) {
5401
- const keyType = describeType(meta.lookup, s.keyTypeId);
5402
- typeSuffix = `: ${keyType} → ${valueType} [map]`;
5403
- } else {
5404
- typeSuffix = `: ${valueType}`;
5837
+ const isMap = s.keyTypeId != null;
5838
+ const tag = isMap ? `${DIM} [map]${RESET}` : "";
5839
+ console.log(` ${CYAN}${s.name}${RESET}${tag}`);
5840
+ if (isMap) {
5841
+ const keyType = prettyTypeById(meta.lookup, s.keyTypeId, {
5842
+ indent: 4,
5843
+ prefix: 5
5844
+ });
5845
+ console.log(` ${DIM}Key:${RESET} ${keyType}`);
5405
5846
  }
5406
- console.log(` ${CYAN}${s.name}${RESET}${DIM}${typeSuffix}${RESET}`);
5847
+ const valueType = prettyTypeById(meta.lookup, s.valueTypeId, {
5848
+ indent: 4,
5849
+ prefix: 7
5850
+ });
5851
+ console.log(` ${DIM}Value:${RESET} ${valueType}`);
5407
5852
  const summary = firstSentence(s.docs);
5408
5853
  if (summary) {
5409
5854
  console.log(` ${DIM}${summary}${RESET}`);
@@ -5445,13 +5890,18 @@ async function handleQuery(target, keys, opts) {
5445
5890
  return;
5446
5891
  }
5447
5892
  const entries = await withStalenessSuggestion(chainName, clientHandle, () => storageApi.getEntries(...parsedKeys));
5448
- printResult(entries.map((e) => ({
5893
+ const rows = entries.map((e) => ({
5449
5894
  keys: e.keyArgs,
5450
5895
  value: e.value
5451
- })), format);
5896
+ }));
5897
+ const text = format === "json" ? formatJson(rows) : formatPretty(rows);
5898
+ await writeStdout(`${text}
5899
+ `);
5452
5900
  } else {
5453
5901
  const result = await withStalenessSuggestion(chainName, clientHandle, () => storageApi.getValue(...parsedKeys));
5454
- printResult(result, format);
5902
+ const text = format === "json" ? formatJson(result) : formatPretty(result);
5903
+ await writeStdout(`${text}
5904
+ `);
5455
5905
  }
5456
5906
  } finally {
5457
5907
  clientHandle.destroy();
@@ -5598,6 +6048,7 @@ init_accounts();
5598
6048
  init_client();
5599
6049
  init_metadata();
5600
6050
  init_output();
6051
+ init_pretty_type();
5601
6052
  init_resolve_address();
5602
6053
  init_binary_display();
5603
6054
  init_errors();
@@ -5730,8 +6181,11 @@ async function handleTx(target, args, opts) {
5730
6181
  }
5731
6182
  printHeading(`${pallet2.name} Calls`);
5732
6183
  for (const c of pallet2.calls) {
5733
- const callArgs = describeCallArgs(meta, pallet2.name, c.name);
5734
- console.log(` ${CYAN}${c.name}${RESET}${DIM}${callArgs}${RESET}`);
6184
+ const callArgs = prettyCallArgs(meta, pallet2.name, c.name, {
6185
+ indent: 2,
6186
+ prefix: c.name.length
6187
+ });
6188
+ console.log(` ${CYAN}${c.name}${RESET}${callArgs}`);
5735
6189
  const summary = firstSentence(c.docs);
5736
6190
  if (summary) {
5737
6191
  console.log(` ${DIM}${summary}${RESET}`);
@@ -5882,6 +6336,7 @@ async function handleTx(target, args, opts) {
5882
6336
  callHex = Binary3.toHex(encodedCall);
5883
6337
  }
5884
6338
  const decodedStr = decodeCall(meta, callHex);
6339
+ const decodedObj = decodeCallObject(meta, callHex);
5885
6340
  if (opts.dryRun && opts.unsigned) {
5886
6341
  if (isJsonOutput(opts)) {
5887
6342
  console.log(formatJson({
@@ -5896,7 +6351,7 @@ async function handleTx(target, args, opts) {
5896
6351
  console.log(` ${BOLD}Chain:${RESET} ${chainName}`);
5897
6352
  console.log(` ${BOLD}Type:${RESET} unsigned (bare)`);
5898
6353
  console.log(` ${BOLD}Call:${RESET} ${callHex}`);
5899
- console.log(` ${BOLD}Decode:${RESET} ${decodedStr}`);
6354
+ printDecodedCall(decodedObj, decodedStr);
5900
6355
  console.log(` ${BOLD}Fees:${RESET} ${DIM}N/A (unsigned transaction)${RESET}`);
5901
6356
  return;
5902
6357
  }
@@ -5935,7 +6390,7 @@ async function handleTx(target, args, opts) {
5935
6390
  console.log(` ${BOLD}Chain:${RESET} ${chainName}`);
5936
6391
  console.log(` ${BOLD}From:${RESET} ${opts.from} (${signerAddress})`);
5937
6392
  console.log(` ${BOLD}Call:${RESET} ${callHex}`);
5938
- console.log(` ${BOLD}Decode:${RESET} ${decodedStr}`);
6393
+ printDecodedCall(decodedObj, decodedStr);
5939
6394
  if (nonce !== undefined)
5940
6395
  console.log(` ${BOLD}Nonce:${RESET} ${nonce}`);
5941
6396
  if (tip !== undefined)
@@ -6012,7 +6467,7 @@ async function handleTx(target, args, opts) {
6012
6467
  console.log(` ${BOLD}Chain:${RESET} ${chainName}`);
6013
6468
  console.log(` ${BOLD}Type:${RESET} unsigned (bare)`);
6014
6469
  console.log(` ${BOLD}Call:${RESET} ${callHex}`);
6015
- console.log(` ${BOLD}Decode:${RESET} ${decodedStr}`);
6470
+ printDecodedCall(decodedObj, decodedStr);
6016
6471
  console.log(` ${BOLD}Tx:${RESET} ${result2.txHash}`);
6017
6472
  if (result2.type === "broadcasted") {
6018
6473
  console.log(` ${BOLD}Status:${RESET} ${GREEN}broadcasted${RESET}`);
@@ -6091,7 +6546,7 @@ async function handleTx(target, args, opts) {
6091
6546
  console.log();
6092
6547
  console.log(` ${BOLD}Chain:${RESET} ${chainName}`);
6093
6548
  console.log(` ${BOLD}Call:${RESET} ${callHex}`);
6094
- console.log(` ${BOLD}Decode:${RESET} ${decodedStr}`);
6549
+ printDecodedCall(decodedObj, decodedStr);
6095
6550
  if (nonce !== undefined)
6096
6551
  console.log(` ${BOLD}Nonce:${RESET} ${nonce}`);
6097
6552
  if (tip !== undefined)
@@ -6178,6 +6633,39 @@ function decodeCall(meta, callHex) {
6178
6633
  return "(unable to decode)";
6179
6634
  }
6180
6635
  }
6636
+ function decodeCallObject(meta, callHex) {
6637
+ try {
6638
+ const callTypeId = meta.lookup.call;
6639
+ if (callTypeId == null)
6640
+ return null;
6641
+ const codec = meta.builder.buildDefinition(callTypeId);
6642
+ const decoded = codec.dec(Binary3.fromHex(callHex));
6643
+ return {
6644
+ palletName: decoded.type,
6645
+ callName: decoded.value.type,
6646
+ args: sanitizeForSerialization(decoded.value.value)
6647
+ };
6648
+ } catch {
6649
+ return null;
6650
+ }
6651
+ }
6652
+ function printDecodedCall(obj, fallback) {
6653
+ if (!obj) {
6654
+ console.log(` ${BOLD}Decode:${RESET} ${fallback}`);
6655
+ return;
6656
+ }
6657
+ const header = `${CYAN}${obj.palletName}${RESET}.${CYAN}${obj.callName}${RESET}`;
6658
+ const hasArgs = obj.args !== null && obj.args !== undefined && !(typeof obj.args === "object" && Object.keys(obj.args).length === 0);
6659
+ if (!hasArgs) {
6660
+ console.log(` ${BOLD}Decode:${RESET} ${header}`);
6661
+ return;
6662
+ }
6663
+ console.log(` ${BOLD}Decode:${RESET} ${header}`);
6664
+ const indented = formatPretty(obj.args).split(`
6665
+ `).map((l) => ` ${l}`).join(`
6666
+ `);
6667
+ console.log(indented);
6668
+ }
6181
6669
  function decodeCallFallback(meta, callHex) {
6182
6670
  const callTypeId = meta.lookup.call;
6183
6671
  if (callTypeId == null)
@@ -7321,13 +7809,13 @@ function isNewerVersion(current, latest) {
7321
7809
  return compareSemver(current, latest) < 0;
7322
7810
  }
7323
7811
  function buildNotificationBox(current, latest) {
7324
- const YELLOW2 = "\x1B[33m";
7325
- const GREEN2 = "\x1B[32m";
7326
- const CYAN2 = "\x1B[36m";
7327
- const RESET2 = "\x1B[0m";
7812
+ const YELLOW3 = "\x1B[33m";
7813
+ const GREEN3 = "\x1B[32m";
7814
+ const CYAN3 = "\x1B[36m";
7815
+ const RESET3 = "\x1B[0m";
7328
7816
  const BOLD2 = "\x1B[1m";
7329
- const line1 = `Update available! ${YELLOW2}${current}${RESET2} → ${GREEN2}${BOLD2}${latest}${RESET2}`;
7330
- const line2 = `Run ${CYAN2}npm i -g polkadot-cli${RESET2} to update`;
7817
+ const line1 = `Update available! ${YELLOW3}${current}${RESET3} → ${GREEN3}${BOLD2}${latest}${RESET3}`;
7818
+ const line2 = `Run ${CYAN3}npm i -g polkadot-cli${RESET3} to update`;
7331
7819
  const visibleLine1 = `Update available! ${current} → ${latest}`;
7332
7820
  const visibleLine2 = `Run npm i -g polkadot-cli to update`;
7333
7821
  const innerWidth = Math.max(visibleLine1.length, visibleLine2.length) + 4;