@acala-network/chopsticks-core 0.9.4 → 0.9.5-2

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.
@@ -63,7 +63,6 @@ export interface Options {
63
63
  */
64
64
  export declare class Blockchain {
65
65
  #private;
66
- readonly uid: string;
67
66
  /** API instance, for getting on-chain data. */
68
67
  readonly api: Api;
69
68
  /** Datasource for caching storage and blocks data. */
@@ -423,7 +423,6 @@ class Blockchain {
423
423
  * @param options - Options for instantiating the blockchain
424
424
  */ constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost = false, allowUnresolvedImports = false, runtimeLogLevel = 0, registeredTypes = {}, offchainWorker = false, maxMemoryBlockCount = 500 }){
425
425
  _class_private_method_init(this, _registerBlock);
426
- _define_property(this, "uid", Math.random().toString(36).substring(2));
427
426
  /** API instance, for getting on-chain data. */ _define_property(this, "api", void 0);
428
427
  /** Datasource for caching storage and blocks data. */ _define_property(this, "db", void 0);
429
428
  /** Enable mock signature. Any signature starts with 0xdeadbeef and filled by 0xcd is considered valid */ _define_property(this, "mockSignatureHost", void 0);
@@ -4,11 +4,11 @@ import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
4
4
  import { HexString } from '@polkadot/util/types';
5
5
  import { StorageEntry } from '@polkadot/types/primitive/types';
6
6
  import { StorageKey } from '@polkadot/types';
7
- export declare const decodeKey: (meta: DecoratedMeta, block: Block, key: HexString) => {
7
+ export declare const decodeKey: (meta: DecoratedMeta, key: HexString) => {
8
8
  storage?: StorageEntry | undefined;
9
9
  decodedKey?: StorageKey<import("@polkadot/types-codec/types").AnyTuple> | undefined;
10
10
  };
11
- export declare const decodeKeyValue: (meta: DecoratedMeta, block: Block, key: HexString, value?: HexString | null, toHuman?: boolean) => {
11
+ export declare const decodeKeyValue: (meta: DecoratedMeta, key: HexString, value?: HexString | null, toHuman?: boolean) => {
12
12
  section: string;
13
13
  method: string;
14
14
  key: any[];
@@ -36,20 +36,22 @@ function _interop_require_default(obj) {
36
36
  const logger = _logger.defaultLogger.child({
37
37
  module: 'decoder'
38
38
  });
39
- const _CACHE = {};
40
- function createCache() {
41
- return new _lrucache.LRUCache({
42
- max: 50
43
- });
44
- }
45
- const getCache = (uid)=>{
46
- if (!_CACHE[uid]) {
47
- _CACHE[uid] = createCache();
39
+ const _CACHE = new _lrucache.LRUCache({
40
+ max: 20 /* max 20 registries */
41
+ });
42
+ const getCache = (registry)=>{
43
+ const cache = _CACHE.get(registry);
44
+ if (cache) {
45
+ return cache;
48
46
  }
49
- return _CACHE[uid];
47
+ const newCache = new _lrucache.LRUCache({
48
+ max: 100 /* max 100 storage entries */
49
+ });
50
+ _CACHE.set(registry, newCache);
51
+ return newCache;
50
52
  };
51
- const getStorageEntry = (meta, block, key)=>{
52
- const cache = getCache(block.chain.uid);
53
+ const getStorageEntry = (meta, key)=>{
54
+ const cache = getCache(meta.registry);
53
55
  for (const prefix of cache.keys()){
54
56
  if (key.startsWith(prefix)) // update the recency of the cache entry
55
57
  return cache.get(prefix);
@@ -65,8 +67,8 @@ const getStorageEntry = (meta, block, key)=>{
65
67
  }
66
68
  return undefined;
67
69
  };
68
- const decodeKey = (meta, block, key)=>{
69
- const storage = getStorageEntry(meta, block, key);
70
+ const decodeKey = (meta, key)=>{
71
+ const storage = getStorageEntry(meta, key);
70
72
  const decodedKey = meta.registry.createType('StorageKey', key);
71
73
  if (storage) {
72
74
  decodedKey.setMeta(storage.meta);
@@ -77,7 +79,7 @@ const decodeKey = (meta, block, key)=>{
77
79
  }
78
80
  return {};
79
81
  };
80
- const decodeKeyValue = (meta, block, key, value, toHuman = true)=>{
82
+ const decodeKeyValue = (meta, key, value, toHuman = true)=>{
81
83
  const res = (0, _wellknownkeys.decodeWellKnownKey)(meta.registry, key, value);
82
84
  if (res) {
83
85
  return {
@@ -87,7 +89,7 @@ const decodeKeyValue = (meta, block, key, value, toHuman = true)=>{
87
89
  value: res.value
88
90
  };
89
91
  }
90
- const { storage, decodedKey } = decodeKey(meta, block, key);
92
+ const { storage, decodedKey } = decodeKey(meta, key);
91
93
  if (!storage || !decodedKey) {
92
94
  logger.warn({
93
95
  key,
@@ -149,11 +151,11 @@ const decodeBlockStorageDiff = async (block, diff)=>{
149
151
  const meta = await block.meta;
150
152
  for (const [key, value] of diff){
151
153
  const oldValue = await block.get(key);
152
- const oldDecoded = toStorageObject(decodeKeyValue(meta, block, key, oldValue)) ?? {
154
+ const oldDecoded = toStorageObject(decodeKeyValue(meta, key, oldValue)) ?? {
153
155
  [key]: oldValue
154
156
  };
155
157
  _lodash.default.merge(oldState, oldDecoded);
156
- const newDecoded = toStorageObject(decodeKeyValue(meta, block, key, value)) ?? {
158
+ const newDecoded = toStorageObject(decodeKeyValue(meta, key, value)) ?? {
157
159
  [key]: value
158
160
  };
159
161
  _lodash.default.merge(newState, newDecoded);
@@ -63,7 +63,6 @@ export interface Options {
63
63
  */
64
64
  export declare class Blockchain {
65
65
  #private;
66
- readonly uid: string;
67
66
  /** API instance, for getting on-chain data. */
68
67
  readonly api: Api;
69
68
  /** Datasource for caching storage and blocks data. */
@@ -36,7 +36,6 @@ const logger = defaultLogger.child({
36
36
  * chain.newBlock()
37
37
  * ```
38
38
  */ export class Blockchain {
39
- uid = Math.random().toString(36).substring(2);
40
39
  /** API instance, for getting on-chain data. */ api;
41
40
  /** Datasource for caching storage and blocks data. */ db;
42
41
  /** Enable mock signature. Any signature starts with 0xdeadbeef and filled by 0xcd is considered valid */ mockSignatureHost;
@@ -4,11 +4,11 @@ import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
4
4
  import { HexString } from '@polkadot/util/types';
5
5
  import { StorageEntry } from '@polkadot/types/primitive/types';
6
6
  import { StorageKey } from '@polkadot/types';
7
- export declare const decodeKey: (meta: DecoratedMeta, block: Block, key: HexString) => {
7
+ export declare const decodeKey: (meta: DecoratedMeta, key: HexString) => {
8
8
  storage?: StorageEntry | undefined;
9
9
  decodedKey?: StorageKey<import("@polkadot/types-codec/types").AnyTuple> | undefined;
10
10
  };
11
- export declare const decodeKeyValue: (meta: DecoratedMeta, block: Block, key: HexString, value?: HexString | null, toHuman?: boolean) => {
11
+ export declare const decodeKeyValue: (meta: DecoratedMeta, key: HexString, value?: HexString | null, toHuman?: boolean) => {
12
12
  section: string;
13
13
  method: string;
14
14
  key: any[];
@@ -7,20 +7,22 @@ import { defaultLogger } from '../logger.js';
7
7
  const logger = defaultLogger.child({
8
8
  module: 'decoder'
9
9
  });
10
- const _CACHE = {};
11
- function createCache() {
12
- return new LRUCache({
13
- max: 50
14
- });
15
- }
16
- const getCache = (uid)=>{
17
- if (!_CACHE[uid]) {
18
- _CACHE[uid] = createCache();
10
+ const _CACHE = new LRUCache({
11
+ max: 20 /* max 20 registries */
12
+ });
13
+ const getCache = (registry)=>{
14
+ const cache = _CACHE.get(registry);
15
+ if (cache) {
16
+ return cache;
19
17
  }
20
- return _CACHE[uid];
18
+ const newCache = new LRUCache({
19
+ max: 100 /* max 100 storage entries */
20
+ });
21
+ _CACHE.set(registry, newCache);
22
+ return newCache;
21
23
  };
22
- const getStorageEntry = (meta, block, key)=>{
23
- const cache = getCache(block.chain.uid);
24
+ const getStorageEntry = (meta, key)=>{
25
+ const cache = getCache(meta.registry);
24
26
  for (const prefix of cache.keys()){
25
27
  if (key.startsWith(prefix)) // update the recency of the cache entry
26
28
  return cache.get(prefix);
@@ -36,8 +38,8 @@ const getStorageEntry = (meta, block, key)=>{
36
38
  }
37
39
  return undefined;
38
40
  };
39
- export const decodeKey = (meta, block, key)=>{
40
- const storage = getStorageEntry(meta, block, key);
41
+ export const decodeKey = (meta, key)=>{
42
+ const storage = getStorageEntry(meta, key);
41
43
  const decodedKey = meta.registry.createType('StorageKey', key);
42
44
  if (storage) {
43
45
  decodedKey.setMeta(storage.meta);
@@ -48,7 +50,7 @@ export const decodeKey = (meta, block, key)=>{
48
50
  }
49
51
  return {};
50
52
  };
51
- export const decodeKeyValue = (meta, block, key, value, toHuman = true)=>{
53
+ export const decodeKeyValue = (meta, key, value, toHuman = true)=>{
52
54
  const res = decodeWellKnownKey(meta.registry, key, value);
53
55
  if (res) {
54
56
  return {
@@ -58,7 +60,7 @@ export const decodeKeyValue = (meta, block, key, value, toHuman = true)=>{
58
60
  value: res.value
59
61
  };
60
62
  }
61
- const { storage, decodedKey } = decodeKey(meta, block, key);
63
+ const { storage, decodedKey } = decodeKey(meta, key);
62
64
  if (!storage || !decodedKey) {
63
65
  logger.warn({
64
66
  key,
@@ -125,11 +127,11 @@ export const toStorageObject = (decoded)=>{
125
127
  const meta = await block.meta;
126
128
  for (const [key, value] of diff){
127
129
  const oldValue = await block.get(key);
128
- const oldDecoded = toStorageObject(decodeKeyValue(meta, block, key, oldValue)) ?? {
130
+ const oldDecoded = toStorageObject(decodeKeyValue(meta, key, oldValue)) ?? {
129
131
  [key]: oldValue
130
132
  };
131
133
  _.merge(oldState, oldDecoded);
132
- const newDecoded = toStorageObject(decodeKeyValue(meta, block, key, value)) ?? {
134
+ const newDecoded = toStorageObject(decodeKeyValue(meta, key, value)) ?? {
133
135
  [key]: value
134
136
  };
135
137
  _.merge(newState, newDecoded);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks-core",
3
- "version": "0.9.4",
3
+ "version": "0.9.5-2",
4
4
  "author": "Acala Developers <hello@acala.network>",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -12,7 +12,7 @@
12
12
  "docs:prep": "typedoc"
13
13
  },
14
14
  "dependencies": {
15
- "@acala-network/chopsticks-executor": "0.9.4",
15
+ "@acala-network/chopsticks-executor": "0.9.5-2",
16
16
  "@polkadot/rpc-provider": "^10.10.1",
17
17
  "@polkadot/types": "^10.10.1",
18
18
  "@polkadot/types-codec": "^10.10.1",
@@ -22,7 +22,7 @@
22
22
  "comlink": "^4.4.1",
23
23
  "eventemitter3": "^5.0.1",
24
24
  "lodash": "^4.17.21",
25
- "lru-cache": "^10.0.3",
25
+ "lru-cache": "^10.1.0",
26
26
  "pino": "^8.16.2",
27
27
  "pino-pretty": "^10.2.3",
28
28
  "rxjs": "^7.8.1",
@@ -30,10 +30,10 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@swc/cli": "0.1.63",
33
- "@swc/core": "^1.3.99",
33
+ "@swc/core": "^1.3.100",
34
34
  "@types/lodash": "^4.14.202",
35
- "typescript": "^5.2.2",
36
- "vitest": "^1.0.0-beta.5"
35
+ "typescript": "^5.3.3",
36
+ "vitest": "^1.0.4"
37
37
  },
38
38
  "files": [
39
39
  "dist/esm/**",