@dedot/cli 0.14.1 → 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.
@@ -2,7 +2,7 @@ import { Metadata, RuntimeVersion } from '@dedot/codecs';
2
2
  import { HexString } from '@dedot/utils';
3
3
  import { DecodedMetadataInfo, ParsedResult } from './types.js';
4
4
  export declare const getRuntimeVersion: (metadata: Metadata) => RuntimeVersion;
5
- export declare const decodeMetadata: (metadataHex: HexString) => DecodedMetadataInfo;
5
+ export declare const decodeMetadata: (metadata: HexString | Uint8Array) => DecodedMetadataInfo;
6
6
  export declare const parseMetadataFromRaw: (metadataFile: string) => Promise<ParsedResult>;
7
7
  export declare const parseMetadataFromWasm: (runtimeFile: string) => Promise<ParsedResult>;
8
8
  export declare const parseStaticSubstrate: () => Promise<ParsedResult>;
@@ -3,7 +3,7 @@ import staticSubstrate from '@polkadot/types-support/metadata/v15/substrate-hex'
3
3
  import { ConstantExecutor } from '@dedot/api';
4
4
  import { $Metadata, PortableRegistry, unwrapOpaqueMetadata } from '@dedot/codecs';
5
5
  import * as $ from '@dedot/shape';
6
- import { hexToU8a, u8aToHex } from '@dedot/utils';
6
+ import { hexToU8a, isHex } from '@dedot/utils';
7
7
  import { getMetadataFromRuntime } from '@polkadot-api/wasm-executor';
8
8
  import * as fs from 'fs';
9
9
  export const getRuntimeVersion = (metadata) => {
@@ -14,15 +14,15 @@ export const getRuntimeVersion = (metadata) => {
14
14
  });
15
15
  return executor.execute('system', 'version');
16
16
  };
17
- export const decodeMetadata = (metadataHex) => {
18
- const metadata = $Metadata.tryDecode(metadataHex);
19
- const runtimeVersion = getRuntimeVersion(metadata);
17
+ export const decodeMetadata = (metadata) => {
18
+ const decodedMetadata = $Metadata.tryDecode(metadata);
19
+ const runtimeVersion = getRuntimeVersion(decodedMetadata);
20
20
  const apis = runtimeVersion.apis.reduce((acc, [name, version]) => {
21
21
  acc[name] = version;
22
22
  return acc;
23
23
  }, {});
24
24
  return {
25
- metadata,
25
+ metadata: decodedMetadata,
26
26
  runtimeVersion: {
27
27
  ...runtimeVersion,
28
28
  apis,
@@ -30,8 +30,10 @@ export const decodeMetadata = (metadataHex) => {
30
30
  };
31
31
  };
32
32
  export const parseMetadataFromRaw = async (metadataFile) => {
33
- const metadataHex = fs.readFileSync(metadataFile, 'utf-8').trim();
34
- const { metadata, runtimeVersion } = decodeMetadata(metadataHex);
33
+ const fileContent = fs.readFileSync(metadataFile);
34
+ const contentStr = fileContent.toString('utf-8').trim();
35
+ const metadataInput = isHex(contentStr) ? contentStr : fileContent;
36
+ const { metadata, runtimeVersion } = decodeMetadata(metadataInput);
35
37
  return {
36
38
  metadata,
37
39
  runtimeVersion,
@@ -43,8 +45,8 @@ export const parseMetadataFromWasm = async (runtimeFile) => {
43
45
  // Because this u8aMetadata has compactInt prefixed for it length, we need to get rid of it.
44
46
  const length = $.compactU32.tryDecode(u8aMetadata);
45
47
  const offset = $.compactU32.tryEncode(length).length;
46
- const metadataHex = u8aToHex(u8aMetadata.subarray(offset));
47
- const { metadata, runtimeVersion } = decodeMetadata(metadataHex);
48
+ const metadataU8a = u8aMetadata.subarray(offset);
49
+ const { metadata, runtimeVersion } = decodeMetadata(metadataU8a);
48
50
  return {
49
51
  metadata,
50
52
  runtimeVersion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/cli",
3
- "version": "0.14.1",
3
+ "version": "0.15.0",
4
4
  "author": "Thang X. Vu <thang@dedot.dev>",
5
5
  "homepage": "https://dedot.dev",
6
6
  "repository": {
@@ -22,11 +22,11 @@
22
22
  "test": "npx vitest --watch=false"
23
23
  },
24
24
  "dependencies": {
25
- "@dedot/api": "0.14.1",
26
- "@dedot/codecs": "0.14.1",
27
- "@dedot/codegen": "0.14.1",
25
+ "@dedot/api": "0.15.0",
26
+ "@dedot/codecs": "0.15.0",
27
+ "@dedot/codegen": "0.15.0",
28
28
  "@polkadot-api/wasm-executor": "^0.1.2",
29
- "@polkadot/types-support": "^16.2.2",
29
+ "@polkadot/types-support": "^16.4.3",
30
30
  "ora": "^8.2.0",
31
31
  "yargs": "^17.7.2"
32
32
  },
@@ -41,7 +41,7 @@
41
41
  "node": ">=18"
42
42
  },
43
43
  "license": "Apache-2.0",
44
- "gitHead": "d5adec49781a6e0b45910055dcaf9bf472a39a6b",
44
+ "gitHead": "1424a04811083af9026e84b776abbdf4240c1d78",
45
45
  "module": "./index.js",
46
46
  "types": "./index.d.ts"
47
47
  }