@acala-network/chopsticks-core 0.9.11-2 → 0.9.12
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.
- package/dist/cjs/blockchain/head-state.d.ts +0 -2
- package/dist/cjs/blockchain/head-state.js +0 -16
- package/dist/cjs/rpc/substrate/state.js +8 -5
- package/dist/esm/blockchain/head-state.d.ts +0 -2
- package/dist/esm/blockchain/head-state.js +0 -16
- package/dist/esm/rpc/substrate/state.js +8 -5
- package/package.json +2 -2
|
@@ -8,8 +8,6 @@ export declare class HeadState {
|
|
|
8
8
|
unsubscribeHead(id: string): void;
|
|
9
9
|
subscribeStorage(keys: string[], cb: Callback): Promise<string>;
|
|
10
10
|
unsubscribeStorage(id: string): void;
|
|
11
|
-
subscrubeRuntimeVersion(cb: (block: Block) => void): Promise<string>;
|
|
12
|
-
unsubscribeRuntimeVersion(id: string): void;
|
|
13
11
|
setHead(head: Block): Promise<void>;
|
|
14
12
|
}
|
|
15
13
|
export {};
|
|
@@ -16,7 +16,6 @@ _export(exports, {
|
|
|
16
16
|
return randomId;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
-
const _util = require("@polkadot/util");
|
|
20
19
|
const _logger = require("../logger.js");
|
|
21
20
|
function _check_private_redeclaration(obj, privateCollection) {
|
|
22
21
|
if (privateCollection.has(obj)) {
|
|
@@ -86,21 +85,6 @@ class HeadState {
|
|
|
86
85
|
unsubscribeStorage(id) {
|
|
87
86
|
delete _class_private_field_get(this, _storageListeners)[id];
|
|
88
87
|
}
|
|
89
|
-
async subscrubeRuntimeVersion(cb) {
|
|
90
|
-
const id = randomId();
|
|
91
|
-
const codeKey = (0, _util.stringToHex)(':code');
|
|
92
|
-
_class_private_field_get(this, _storageListeners)[id] = [
|
|
93
|
-
[
|
|
94
|
-
codeKey
|
|
95
|
-
],
|
|
96
|
-
cb
|
|
97
|
-
];
|
|
98
|
-
_class_private_field_get(this, _oldValues)[codeKey] = await _class_private_field_get(this, _head).get(codeKey).then((val)=>val || null);
|
|
99
|
-
return id;
|
|
100
|
-
}
|
|
101
|
-
unsubscribeRuntimeVersion(id) {
|
|
102
|
-
delete _class_private_field_get(this, _storageListeners)[id];
|
|
103
|
-
}
|
|
104
88
|
async setHead(head) {
|
|
105
89
|
_class_private_field_set(this, _head, head);
|
|
106
90
|
for (const cb of Object.values(_class_private_field_get(this, _headListeners))){
|
|
@@ -46,6 +46,7 @@ _export(exports, {
|
|
|
46
46
|
return state_unsubscribeStorage;
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
+
const _util = require("@polkadot/util");
|
|
49
50
|
const _shared = require("../shared.js");
|
|
50
51
|
const _logger = require("../../logger.js");
|
|
51
52
|
const _index = require("../../utils/index.js");
|
|
@@ -101,12 +102,14 @@ const state_call = async (context, [method, data, hash])=>{
|
|
|
101
102
|
};
|
|
102
103
|
const state_subscribeRuntimeVersion = async (context, _params, { subscribe })=>{
|
|
103
104
|
let update = (_block)=>{};
|
|
104
|
-
const id = await context.chain.headState.
|
|
105
|
-
|
|
105
|
+
const id = await context.chain.headState.subscribeStorage([
|
|
106
|
+
(0, _util.stringToHex)(':code')
|
|
107
|
+
], (block)=>update(block));
|
|
108
|
+
const callback = subscribe('state_runtimeVersion', id, ()=>context.chain.headState.unsubscribeStorage(id));
|
|
106
109
|
update = async (block)=>callback(await block.runtimeVersion);
|
|
107
|
-
|
|
108
|
-
context.chain.head
|
|
109
|
-
}
|
|
110
|
+
(async ()=>{
|
|
111
|
+
update(context.chain.head);
|
|
112
|
+
})();
|
|
110
113
|
return id;
|
|
111
114
|
};
|
|
112
115
|
const state_unsubscribeRuntimeVersion = async (_context, [subid], { unsubscribe })=>{
|
|
@@ -8,8 +8,6 @@ export declare class HeadState {
|
|
|
8
8
|
unsubscribeHead(id: string): void;
|
|
9
9
|
subscribeStorage(keys: string[], cb: Callback): Promise<string>;
|
|
10
10
|
unsubscribeStorage(id: string): void;
|
|
11
|
-
subscrubeRuntimeVersion(cb: (block: Block) => void): Promise<string>;
|
|
12
|
-
unsubscribeRuntimeVersion(id: string): void;
|
|
13
11
|
setHead(head: Block): Promise<void>;
|
|
14
12
|
}
|
|
15
13
|
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { stringToHex } from '@polkadot/util';
|
|
2
1
|
import { defaultLogger } from '../logger.js';
|
|
3
2
|
export const randomId = ()=>Math.random().toString(36).substring(2);
|
|
4
3
|
const logger = defaultLogger.child({
|
|
@@ -34,21 +33,6 @@ export class HeadState {
|
|
|
34
33
|
unsubscribeStorage(id) {
|
|
35
34
|
delete this.#storageListeners[id];
|
|
36
35
|
}
|
|
37
|
-
async subscrubeRuntimeVersion(cb) {
|
|
38
|
-
const id = randomId();
|
|
39
|
-
const codeKey = stringToHex(':code');
|
|
40
|
-
this.#storageListeners[id] = [
|
|
41
|
-
[
|
|
42
|
-
codeKey
|
|
43
|
-
],
|
|
44
|
-
cb
|
|
45
|
-
];
|
|
46
|
-
this.#oldValues[codeKey] = await this.#head.get(codeKey).then((val)=>val || null);
|
|
47
|
-
return id;
|
|
48
|
-
}
|
|
49
|
-
unsubscribeRuntimeVersion(id) {
|
|
50
|
-
delete this.#storageListeners[id];
|
|
51
|
-
}
|
|
52
36
|
async setHead(head) {
|
|
53
37
|
this.#head = head;
|
|
54
38
|
for (const cb of Object.values(this.#headListeners)){
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stringToHex } from '@polkadot/util';
|
|
1
2
|
import { ResponseError } from '../shared.js';
|
|
2
3
|
import { defaultLogger } from '../../logger.js';
|
|
3
4
|
import { isPrefixedChildKey, prefixedChildKey, stripChildPrefix } from '../../utils/index.js';
|
|
@@ -85,12 +86,14 @@ const logger = defaultLogger.child({
|
|
|
85
86
|
* @return subscription id
|
|
86
87
|
*/ export const state_subscribeRuntimeVersion = async (context, _params, { subscribe })=>{
|
|
87
88
|
let update = (_block)=>{};
|
|
88
|
-
const id = await context.chain.headState.
|
|
89
|
-
|
|
89
|
+
const id = await context.chain.headState.subscribeStorage([
|
|
90
|
+
stringToHex(':code')
|
|
91
|
+
], (block)=>update(block));
|
|
92
|
+
const callback = subscribe('state_runtimeVersion', id, ()=>context.chain.headState.unsubscribeStorage(id));
|
|
90
93
|
update = async (block)=>callback(await block.runtimeVersion);
|
|
91
|
-
|
|
92
|
-
context.chain.head
|
|
93
|
-
}
|
|
94
|
+
(async ()=>{
|
|
95
|
+
update(context.chain.head);
|
|
96
|
+
})();
|
|
94
97
|
return id;
|
|
95
98
|
};
|
|
96
99
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks-core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.12",
|
|
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.
|
|
15
|
+
"@acala-network/chopsticks-executor": "0.9.12",
|
|
16
16
|
"@polkadot/rpc-provider": "^10.11.2",
|
|
17
17
|
"@polkadot/types": "^10.11.2",
|
|
18
18
|
"@polkadot/types-codec": "^10.11.2",
|