@acala-network/chopsticks-core 0.9.1-2 → 0.9.1-3

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 (93) hide show
  1. package/dist/cjs/api.js +149 -91
  2. package/dist/cjs/blockchain/block-builder.js +192 -118
  3. package/dist/cjs/blockchain/block.js +245 -182
  4. package/dist/cjs/blockchain/head-state.js +115 -51
  5. package/dist/cjs/blockchain/index.js +283 -218
  6. package/dist/cjs/blockchain/inherent/index.js +99 -39
  7. package/dist/cjs/blockchain/inherent/para-enter.js +16 -10
  8. package/dist/cjs/blockchain/inherent/parachain/babe-randomness.js +13 -6
  9. package/dist/cjs/blockchain/inherent/parachain/nimbus-author-inherent.js +13 -6
  10. package/dist/cjs/blockchain/inherent/parachain/validation-data.js +106 -74
  11. package/dist/cjs/blockchain/storage-layer.js +245 -135
  12. package/dist/cjs/blockchain/txpool.js +267 -140
  13. package/dist/cjs/chopsticks-provider.js +188 -106
  14. package/dist/cjs/database.js +3 -1
  15. package/dist/cjs/genesis-provider.js +171 -111
  16. package/dist/cjs/index.js +36 -36
  17. package/dist/cjs/logger.js +54 -36
  18. package/dist/cjs/offchain.js +44 -16
  19. package/dist/cjs/package.json +1 -0
  20. package/dist/cjs/rpc/index.js +35 -16
  21. package/dist/cjs/rpc/shared.js +41 -11
  22. package/dist/cjs/rpc/substrate/author.js +57 -58
  23. package/dist/cjs/rpc/substrate/chain.js +75 -60
  24. package/dist/cjs/rpc/substrate/index.js +79 -39
  25. package/dist/cjs/rpc/substrate/payment.js +27 -26
  26. package/dist/cjs/rpc/substrate/state.js +110 -127
  27. package/dist/cjs/rpc/substrate/system.js +63 -38
  28. package/dist/cjs/schema/index.js +28 -11
  29. package/dist/cjs/setup.js +37 -33
  30. package/dist/cjs/utils/decoder.js +72 -49
  31. package/dist/cjs/utils/index.js +99 -66
  32. package/dist/cjs/utils/key-cache.js +71 -37
  33. package/dist/cjs/utils/proof.js +40 -18
  34. package/dist/cjs/utils/set-storage.js +46 -32
  35. package/dist/cjs/utils/time-travel.js +50 -36
  36. package/dist/cjs/utils/well-known-keys.js +37 -27
  37. package/dist/cjs/wasm-executor/browser-wasm-executor.js +76 -0
  38. package/dist/cjs/wasm-executor/browser-worker.js +16 -12
  39. package/dist/cjs/wasm-executor/index.js +164 -106
  40. package/dist/cjs/wasm-executor/node-wasm-executor.js +78 -0
  41. package/dist/cjs/wasm-executor/node-worker.js +22 -46
  42. package/dist/cjs/xcm/downward.js +32 -21
  43. package/dist/cjs/xcm/horizontal.js +30 -18
  44. package/dist/cjs/xcm/index.js +37 -19
  45. package/dist/cjs/xcm/upward.js +21 -15
  46. package/dist/esm/api.js +70 -73
  47. package/dist/esm/blockchain/block-builder.js +142 -85
  48. package/dist/esm/blockchain/block.js +118 -133
  49. package/dist/esm/blockchain/head-state.js +38 -40
  50. package/dist/esm/blockchain/index.js +158 -166
  51. package/dist/esm/blockchain/inherent/index.js +14 -22
  52. package/dist/esm/blockchain/inherent/para-enter.js +6 -6
  53. package/dist/esm/blockchain/inherent/parachain/babe-randomness.js +3 -1
  54. package/dist/esm/blockchain/inherent/parachain/nimbus-author-inherent.js +3 -1
  55. package/dist/esm/blockchain/inherent/parachain/validation-data.js +74 -50
  56. package/dist/esm/blockchain/storage-layer.js +100 -104
  57. package/dist/esm/blockchain/txpool.js +146 -136
  58. package/dist/esm/chopsticks-provider.js +88 -78
  59. package/dist/esm/database.js +1 -1
  60. package/dist/esm/genesis-provider.js +93 -108
  61. package/dist/esm/index.js +1 -2
  62. package/dist/esm/logger.js +31 -29
  63. package/dist/esm/offchain.js +16 -9
  64. package/dist/esm/rpc/index.js +6 -4
  65. package/dist/esm/rpc/shared.js +6 -3
  66. package/dist/esm/rpc/substrate/author.js +27 -27
  67. package/dist/esm/rpc/substrate/chain.js +24 -25
  68. package/dist/esm/rpc/substrate/index.js +1 -1
  69. package/dist/esm/rpc/substrate/payment.js +4 -6
  70. package/dist/esm/rpc/substrate/state.js +54 -48
  71. package/dist/esm/rpc/substrate/system.js +17 -15
  72. package/dist/esm/schema/index.js +13 -3
  73. package/dist/esm/setup.js +16 -18
  74. package/dist/esm/utils/decoder.js +35 -26
  75. package/dist/esm/utils/index.js +32 -27
  76. package/dist/esm/utils/key-cache.js +25 -21
  77. package/dist/esm/utils/proof.js +7 -7
  78. package/dist/esm/utils/set-storage.js +30 -22
  79. package/dist/esm/utils/time-travel.js +17 -20
  80. package/dist/esm/utils/well-known-keys.js +24 -20
  81. package/dist/esm/wasm-executor/browser-wasm-executor.js +31 -0
  82. package/dist/esm/wasm-executor/browser-worker.js +5 -7
  83. package/dist/esm/wasm-executor/index.js +64 -55
  84. package/dist/esm/wasm-executor/node-wasm-executor.js +28 -0
  85. package/dist/esm/wasm-executor/node-worker.js +5 -37
  86. package/dist/esm/xcm/downward.js +16 -11
  87. package/dist/esm/xcm/horizontal.js +17 -11
  88. package/dist/esm/xcm/index.js +6 -4
  89. package/dist/esm/xcm/upward.js +7 -7
  90. package/package.json +10 -5
  91. package/dist/cjs/wasm-executor/browser-wasm-executor.mjs +0 -32
  92. package/dist/esm/package.json +0 -1
  93. package/dist/esm/wasm-executor/browser-wasm-executor.mjs +0 -32
package/dist/cjs/api.js CHANGED
@@ -1,141 +1,199 @@
1
1
  "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _Api_provider, _Api_ready, _Api_chain, _Api_chainProperties;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Api = void 0;
16
- const utils_1 = require("./utils");
17
- /**
18
- * API class. Calls provider to get on-chain data.
19
- * Either `endpoint` or `genesis` porvider must be provided.
20
- *
21
- * @example Instantiate an API
22
- *
23
- * ```ts
24
- * const provider = new WsProvider(options.endpoint)
25
- * const api = new Api(provider)
26
- * await api.isReady
27
- * ```
28
- */
29
- class Api {
30
- constructor(provider, signedExtensions) {
31
- _Api_provider.set(this, void 0);
32
- _Api_ready.set(this, void 0);
33
- _Api_chain.set(this, void 0);
34
- _Api_chainProperties.set(this, void 0);
35
- __classPrivateFieldSet(this, _Api_provider, provider, "f");
36
- this.signedExtensions = signedExtensions || {};
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "Api", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return Api;
9
+ }
10
+ });
11
+ const _utils = require("./utils");
12
+ function _check_private_redeclaration(obj, privateCollection) {
13
+ if (privateCollection.has(obj)) {
14
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
15
+ }
16
+ }
17
+ function _class_apply_descriptor_get(receiver, descriptor) {
18
+ if (descriptor.get) {
19
+ return descriptor.get.call(receiver);
20
+ }
21
+ return descriptor.value;
22
+ }
23
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
24
+ if (descriptor.set) {
25
+ descriptor.set.call(receiver, value);
26
+ } else {
27
+ if (!descriptor.writable) {
28
+ throw new TypeError("attempted to set read only private field");
29
+ }
30
+ descriptor.value = value;
31
+ }
32
+ }
33
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
34
+ if (!privateMap.has(receiver)) {
35
+ throw new TypeError("attempted to " + action + " private field on non-instance");
37
36
  }
37
+ return privateMap.get(receiver);
38
+ }
39
+ function _class_private_field_get(receiver, privateMap) {
40
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
41
+ return _class_apply_descriptor_get(receiver, descriptor);
42
+ }
43
+ function _class_private_field_init(obj, privateMap, value) {
44
+ _check_private_redeclaration(obj, privateMap);
45
+ privateMap.set(obj, value);
46
+ }
47
+ function _class_private_field_set(receiver, privateMap, value) {
48
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
49
+ _class_apply_descriptor_set(receiver, descriptor, value);
50
+ return value;
51
+ }
52
+ function _define_property(obj, key, value) {
53
+ if (key in obj) {
54
+ Object.defineProperty(obj, key, {
55
+ value: value,
56
+ enumerable: true,
57
+ configurable: true,
58
+ writable: true
59
+ });
60
+ } else {
61
+ obj[key] = value;
62
+ }
63
+ return obj;
64
+ }
65
+ var _provider = /*#__PURE__*/ new WeakMap(), _ready = /*#__PURE__*/ new WeakMap(), _chain = /*#__PURE__*/ new WeakMap(), _chainProperties = /*#__PURE__*/ new WeakMap();
66
+ class Api {
38
67
  async disconnect() {
39
- return __classPrivateFieldGet(this, _Api_provider, "f").disconnect();
68
+ return _class_private_field_get(this, _provider).disconnect();
40
69
  }
41
70
  get isReady() {
42
- if (!__classPrivateFieldGet(this, _Api_ready, "f")) {
43
- if (__classPrivateFieldGet(this, _Api_provider, "f")['isReady']) {
44
- __classPrivateFieldSet(this, _Api_ready, __classPrivateFieldGet(this, _Api_provider, "f")['isReady'], "f");
45
- }
46
- else {
47
- __classPrivateFieldSet(this, _Api_ready, new Promise((resolve) => {
48
- if (__classPrivateFieldGet(this, _Api_provider, "f").hasSubscriptions) {
49
- __classPrivateFieldGet(this, _Api_provider, "f").on('connected', resolve);
50
- __classPrivateFieldGet(this, _Api_provider, "f").connect();
51
- }
52
- else {
71
+ if (!_class_private_field_get(this, _ready)) {
72
+ if (_class_private_field_get(this, _provider)['isReady']) {
73
+ _class_private_field_set(this, _ready, _class_private_field_get(this, _provider)['isReady']);
74
+ } else {
75
+ _class_private_field_set(this, _ready, new Promise((resolve)=>{
76
+ if (_class_private_field_get(this, _provider).hasSubscriptions) {
77
+ _class_private_field_get(this, _provider).on('connected', resolve);
78
+ _class_private_field_get(this, _provider).connect();
79
+ } else {
53
80
  resolve();
54
81
  }
55
- }), "f");
82
+ }));
56
83
  }
57
84
  }
58
- return __classPrivateFieldGet(this, _Api_ready, "f");
85
+ return _class_private_field_get(this, _ready);
59
86
  }
60
87
  get chain() {
61
- if (!__classPrivateFieldGet(this, _Api_chain, "f")) {
62
- __classPrivateFieldSet(this, _Api_chain, this.getSystemChain(), "f");
88
+ if (!_class_private_field_get(this, _chain)) {
89
+ _class_private_field_set(this, _chain, this.getSystemChain());
63
90
  }
64
- return __classPrivateFieldGet(this, _Api_chain, "f");
91
+ return _class_private_field_get(this, _chain);
65
92
  }
66
93
  get chainProperties() {
67
- if (!__classPrivateFieldGet(this, _Api_chainProperties, "f")) {
68
- __classPrivateFieldSet(this, _Api_chainProperties, this.getSystemProperties(), "f");
94
+ if (!_class_private_field_get(this, _chainProperties)) {
95
+ _class_private_field_set(this, _chainProperties, this.getSystemProperties());
69
96
  }
70
- return __classPrivateFieldGet(this, _Api_chainProperties, "f");
97
+ return _class_private_field_get(this, _chainProperties);
71
98
  }
72
99
  async getSystemName() {
73
- return __classPrivateFieldGet(this, _Api_provider, "f").send('system_name', []);
100
+ return _class_private_field_get(this, _provider).send('system_name', []);
74
101
  }
75
102
  async getSystemProperties() {
76
- return __classPrivateFieldGet(this, _Api_provider, "f").send('system_properties', []);
103
+ return _class_private_field_get(this, _provider).send('system_properties', []);
77
104
  }
78
105
  async getSystemChain() {
79
- return __classPrivateFieldGet(this, _Api_provider, "f").send('system_chain', []);
106
+ return _class_private_field_get(this, _provider).send('system_chain', []);
80
107
  }
81
108
  async getBlockHash(blockNumber) {
82
- return __classPrivateFieldGet(this, _Api_provider, "f").send('chain_getBlockHash', Number.isInteger(blockNumber) ? [blockNumber] : [], !!blockNumber);
109
+ return _class_private_field_get(this, _provider).send('chain_getBlockHash', Number.isInteger(blockNumber) ? [
110
+ blockNumber
111
+ ] : [], !!blockNumber);
83
112
  }
84
113
  async getHeader(hash) {
85
- return __classPrivateFieldGet(this, _Api_provider, "f").send('chain_getHeader', hash ? [hash] : [], !!hash);
114
+ return _class_private_field_get(this, _provider).send('chain_getHeader', hash ? [
115
+ hash
116
+ ] : [], !!hash);
86
117
  }
87
118
  async getBlock(hash) {
88
- return __classPrivateFieldGet(this, _Api_provider, "f").send('chain_getBlock', hash ? [hash] : [], !!hash);
119
+ return _class_private_field_get(this, _provider).send('chain_getBlock', hash ? [
120
+ hash
121
+ ] : [], !!hash);
89
122
  }
90
123
  async getStorage(key, hash) {
91
- const [child, storageKey] = (0, utils_1.splitChildKey)(key);
124
+ const [child, storageKey] = (0, _utils.splitChildKey)(key);
92
125
  if (child) {
93
126
  // child storage key, use childstate_getStorage
94
- const params = [child, storageKey];
95
- if (hash)
96
- params.push(hash);
97
- return __classPrivateFieldGet(this, _Api_provider, "f").send('childstate_getStorage', params, !!hash);
98
- }
99
- else {
127
+ const params = [
128
+ child,
129
+ storageKey
130
+ ];
131
+ if (hash) params.push(hash);
132
+ return _class_private_field_get(this, _provider).send('childstate_getStorage', params, !!hash);
133
+ } else {
100
134
  // main storage key, use state_getStorage
101
- const params = [key];
102
- if (hash)
103
- params.push(hash);
104
- return __classPrivateFieldGet(this, _Api_provider, "f").send('state_getStorage', params, !!hash);
135
+ const params = [
136
+ key
137
+ ];
138
+ if (hash) params.push(hash);
139
+ return _class_private_field_get(this, _provider).send('state_getStorage', params, !!hash);
105
140
  }
106
141
  }
107
142
  async getKeysPaged(prefix, pageSize, startKey, hash) {
108
- const [child, storageKey] = (0, utils_1.splitChildKey)(prefix);
143
+ const [child, storageKey] = (0, _utils.splitChildKey)(prefix);
109
144
  if (child) {
110
145
  // child storage key, use childstate_getKeysPaged
111
146
  // strip child prefix from startKey
112
- const params = [child, storageKey, pageSize, (0, utils_1.stripChildPrefix)(startKey)];
113
- if (hash)
114
- params.push(hash);
115
- return __classPrivateFieldGet(this, _Api_provider, "f")
116
- .send('childstate_getKeysPaged', params, !!hash)
117
- .then((keys) => keys.map((key) => (0, utils_1.prefixedChildKey)(child, key)));
118
- }
119
- else {
147
+ const params = [
148
+ child,
149
+ storageKey,
150
+ pageSize,
151
+ (0, _utils.stripChildPrefix)(startKey)
152
+ ];
153
+ if (hash) params.push(hash);
154
+ return _class_private_field_get(this, _provider).send('childstate_getKeysPaged', params, !!hash).then((keys)=>keys.map((key)=>(0, _utils.prefixedChildKey)(child, key)));
155
+ } else {
120
156
  // main storage key, use state_getKeysPaged
121
- const params = [prefix, pageSize, startKey];
122
- if (hash)
123
- params.push(hash);
124
- return __classPrivateFieldGet(this, _Api_provider, "f").send('state_getKeysPaged', params, !!hash);
157
+ const params = [
158
+ prefix,
159
+ pageSize,
160
+ startKey
161
+ ];
162
+ if (hash) params.push(hash);
163
+ return _class_private_field_get(this, _provider).send('state_getKeysPaged', params, !!hash);
125
164
  }
126
165
  }
127
166
  async subscribeRemoteNewHeads(cb) {
128
- if (!__classPrivateFieldGet(this, _Api_provider, "f").hasSubscriptions) {
167
+ if (!_class_private_field_get(this, _provider).hasSubscriptions) {
129
168
  throw new Error('subscribeRemoteNewHeads only works with subscriptions');
130
169
  }
131
- return __classPrivateFieldGet(this, _Api_provider, "f").subscribe('chain_newHead', 'chain_subscribeNewHeads', [], cb);
170
+ return _class_private_field_get(this, _provider).subscribe('chain_newHead', 'chain_subscribeNewHeads', [], cb);
132
171
  }
133
172
  async subscribeRemoteFinalizedHeads(cb) {
134
- if (!__classPrivateFieldGet(this, _Api_provider, "f").hasSubscriptions) {
173
+ if (!_class_private_field_get(this, _provider).hasSubscriptions) {
135
174
  throw new Error('subscribeRemoteFinalizedHeads only works with subscriptions');
136
175
  }
137
- return __classPrivateFieldGet(this, _Api_provider, "f").subscribe('chain_finalizedHead', 'chain_subscribeFinalizedHeads', [], cb);
176
+ return _class_private_field_get(this, _provider).subscribe('chain_finalizedHead', 'chain_subscribeFinalizedHeads', [], cb);
177
+ }
178
+ constructor(provider, signedExtensions){
179
+ _class_private_field_init(this, _provider, {
180
+ writable: true,
181
+ value: void 0
182
+ });
183
+ _class_private_field_init(this, _ready, {
184
+ writable: true,
185
+ value: void 0
186
+ });
187
+ _class_private_field_init(this, _chain, {
188
+ writable: true,
189
+ value: void 0
190
+ });
191
+ _class_private_field_init(this, _chainProperties, {
192
+ writable: true,
193
+ value: void 0
194
+ });
195
+ _define_property(this, "signedExtensions", void 0);
196
+ _class_private_field_set(this, _provider, provider);
197
+ this.signedExtensions = signedExtensions || {};
138
198
  }
139
199
  }
140
- exports.Api = Api;
141
- _Api_provider = new WeakMap(), _Api_ready = new WeakMap(), _Api_chain = new WeakMap(), _Api_chainProperties = new WeakMap();