@dedot/api 0.12.1-next.c7fd0a6c.2 → 0.13.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.
- package/cjs/executor/ErrorExecutor.js +1 -1
- package/cjs/executor/EventExecutor.js +1 -1
- package/cjs/executor/TxExecutor.js +1 -1
- package/cjs/extrinsic/extensions/ExtraSignedExtension.js +6 -4
- package/cjs/json-rpc/group/ChainHead/ChainHead.js +3 -2
- package/executor/ErrorExecutor.js +1 -1
- package/executor/EventExecutor.js +1 -1
- package/executor/Executor.d.ts +121 -7
- package/executor/TxExecutor.js +1 -1
- package/extrinsic/extensions/ExtraSignedExtension.js +7 -5
- package/json-rpc/group/ChainHead/ChainHead.js +3 -2
- package/package.json +9 -9
|
@@ -12,7 +12,7 @@ class ErrorExecutor extends Executor_js_1.Executor {
|
|
|
12
12
|
const targetPallet = this.getPallet(pallet);
|
|
13
13
|
const errorTypeId = targetPallet.error;
|
|
14
14
|
(0, utils_1.assert)(errorTypeId, new utils_1.UnknownApiError(`Not found error with id ${errorTypeId} in pallet ${pallet}`));
|
|
15
|
-
const errorDef = this.#getErrorDef(errorTypeId, errorName);
|
|
15
|
+
const errorDef = this.#getErrorDef(errorTypeId.typeId, errorName);
|
|
16
16
|
return {
|
|
17
17
|
meta: {
|
|
18
18
|
...errorDef,
|
|
@@ -13,7 +13,7 @@ class EventExecutor extends Executor_js_1.Executor {
|
|
|
13
13
|
const targetPallet = this.getPallet(pallet);
|
|
14
14
|
const eventTypeId = targetPallet.event;
|
|
15
15
|
(0, utils_1.assert)(eventTypeId, new utils_1.UnknownApiError(`Not found event with id ${eventTypeId} in pallet ${pallet}`));
|
|
16
|
-
const eventDef = this.#getEventDef(eventTypeId, eventName);
|
|
16
|
+
const eventDef = this.#getEventDef(eventTypeId.typeId, eventName);
|
|
17
17
|
const is = (event) => {
|
|
18
18
|
if ((0, utils_js_1.isEventRecord)(event)) {
|
|
19
19
|
event = event.event;
|
|
@@ -12,7 +12,7 @@ class TxExecutor extends Executor_js_1.Executor {
|
|
|
12
12
|
doExecute(pallet, functionName) {
|
|
13
13
|
const targetPallet = this.getPallet(pallet);
|
|
14
14
|
(0, utils_1.assert)(targetPallet.calls, new utils_1.UnknownApiError(`Tx calls are not available for pallet ${targetPallet.name}`));
|
|
15
|
-
const txType = this.metadata.types[targetPallet.calls];
|
|
15
|
+
const txType = this.metadata.types[targetPallet.calls.typeId];
|
|
16
16
|
(0, utils_1.assert)(txType.typeDef.type === 'Enum', new utils_1.UnknownApiError('Tx type defs should be enum'));
|
|
17
17
|
const isFlatEnum = txType.typeDef.value.members.every((m) => m.fields.length === 0);
|
|
18
18
|
const txCallDef = txType.typeDef.value.members.find((m) => (0, utils_1.stringCamelCase)(m.name) === functionName);
|
|
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ExtraSignedExtension = void 0;
|
|
27
|
+
const codecs_1 = require("@dedot/codecs");
|
|
27
28
|
const $ = __importStar(require("@dedot/shape"));
|
|
28
29
|
const utils_1 = require("@dedot/utils");
|
|
29
30
|
const FallbackSignedExtension_js_1 = require("./FallbackSignedExtension.js");
|
|
@@ -47,8 +48,7 @@ class ExtraSignedExtension extends SignedExtension_js_1.SignedExtension {
|
|
|
47
48
|
return 'ExtraSignedExtension';
|
|
48
49
|
}
|
|
49
50
|
get $Data() {
|
|
50
|
-
|
|
51
|
-
return (0, utils_1.ensurePresence)(this.registry.findCodec(extraTypeId));
|
|
51
|
+
return (0, utils_1.ensurePresence)(this.registry.$Extra());
|
|
52
52
|
}
|
|
53
53
|
get $AdditionalSigned() {
|
|
54
54
|
const $AdditionalSignedCodecs = this.#signedExtensionDefs.map((se) => this.registry.findCodec(se.additionalSigned));
|
|
@@ -94,12 +94,14 @@ class ExtraSignedExtension extends SignedExtension_js_1.SignedExtension {
|
|
|
94
94
|
}
|
|
95
95
|
toPayload(call = '0x') {
|
|
96
96
|
const signedExtensions = this.#signedExtensions.map((se) => se.identifier);
|
|
97
|
-
const {
|
|
97
|
+
const { versions } = this.registry.metadata.extrinsic;
|
|
98
98
|
const { signerAddress } = this.options;
|
|
99
|
+
(0, utils_1.assert)(versions.includes(codecs_1.DEFAULT_EXTRINSIC_VERSION), // --
|
|
100
|
+
'Extrinsic Version 4 Not Found');
|
|
99
101
|
return Object.assign({
|
|
100
102
|
address: signerAddress,
|
|
101
103
|
signedExtensions,
|
|
102
|
-
version,
|
|
104
|
+
version: codecs_1.DEFAULT_EXTRINSIC_VERSION,
|
|
103
105
|
method: call,
|
|
104
106
|
withSignedTransaction: true, // allow signer/wallet to alter transaction by default
|
|
105
107
|
}, ...this.#signedExtensions.map((se) => se.toPayload()));
|
|
@@ -83,18 +83,19 @@ class ChainHead extends JsonRpcGroup_js_1.JsonRpcGroup {
|
|
|
83
83
|
const defer = (0, utils_1.deferred)();
|
|
84
84
|
try {
|
|
85
85
|
this.#unsub && this.#unsub().catch(utils_1.noop); // ensure unfollowed
|
|
86
|
+
const SIGNAL_THRESHOLD = this.#__unsafe__isSmoldot() ? 2 : 1;
|
|
86
87
|
let signals = 0;
|
|
87
88
|
this.#unsub = await this.send('follow', true, (event, subscription) => {
|
|
88
89
|
this.#followResponseQueue
|
|
89
90
|
.enqueue(async () => {
|
|
90
91
|
await this.#onFollowEvent(event, subscription);
|
|
91
|
-
if (signals >=
|
|
92
|
+
if (signals >= SIGNAL_THRESHOLD)
|
|
92
93
|
return;
|
|
93
94
|
signals += 1;
|
|
94
95
|
// Sometime smoldot send a `stop` event right after `initialized`
|
|
95
96
|
// So requests sending between `initialized` and `stop` will be on pruned hashes -> throwing out errors
|
|
96
97
|
// Here we make sure to receive at least the first 2 signals to resolve
|
|
97
|
-
if (signals >=
|
|
98
|
+
if (signals >= SIGNAL_THRESHOLD) {
|
|
98
99
|
defer.resolve();
|
|
99
100
|
}
|
|
100
101
|
})
|
|
@@ -9,7 +9,7 @@ export class ErrorExecutor extends Executor {
|
|
|
9
9
|
const targetPallet = this.getPallet(pallet);
|
|
10
10
|
const errorTypeId = targetPallet.error;
|
|
11
11
|
assert(errorTypeId, new UnknownApiError(`Not found error with id ${errorTypeId} in pallet ${pallet}`));
|
|
12
|
-
const errorDef = this.#getErrorDef(errorTypeId, errorName);
|
|
12
|
+
const errorDef = this.#getErrorDef(errorTypeId.typeId, errorName);
|
|
13
13
|
return {
|
|
14
14
|
meta: {
|
|
15
15
|
...errorDef,
|
|
@@ -10,7 +10,7 @@ export class EventExecutor extends Executor {
|
|
|
10
10
|
const targetPallet = this.getPallet(pallet);
|
|
11
11
|
const eventTypeId = targetPallet.event;
|
|
12
12
|
assert(eventTypeId, new UnknownApiError(`Not found event with id ${eventTypeId} in pallet ${pallet}`));
|
|
13
|
-
const eventDef = this.#getEventDef(eventTypeId, eventName);
|
|
13
|
+
const eventDef = this.#getEventDef(eventTypeId.typeId, eventName);
|
|
14
14
|
const is = (event) => {
|
|
15
15
|
if (isEventRecord(event)) {
|
|
16
16
|
event = event.event;
|
package/executor/Executor.d.ts
CHANGED
|
@@ -91,33 +91,124 @@ export declare abstract class Executor<ChainApi extends GenericSubstrateApi = Ge
|
|
|
91
91
|
};
|
|
92
92
|
default: `0x${string}`;
|
|
93
93
|
docs: string[];
|
|
94
|
+
deprecationInfo: {
|
|
95
|
+
type: "NotDeprecated";
|
|
96
|
+
} | {
|
|
97
|
+
type: "DeprecatedWithoutNote";
|
|
98
|
+
} | {
|
|
99
|
+
type: "Deprecated";
|
|
100
|
+
value: {
|
|
101
|
+
note: string;
|
|
102
|
+
since: string | undefined;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
94
105
|
}[];
|
|
95
106
|
} | undefined;
|
|
96
|
-
calls:
|
|
97
|
-
|
|
107
|
+
calls: {
|
|
108
|
+
typeId: number;
|
|
109
|
+
deprecationInfo: readonly [ReadonlyMap<number, {
|
|
110
|
+
type: "DeprecatedWithoutNote";
|
|
111
|
+
} | {
|
|
112
|
+
type: "Deprecated";
|
|
113
|
+
value: {
|
|
114
|
+
note: string;
|
|
115
|
+
since: string | undefined;
|
|
116
|
+
};
|
|
117
|
+
}>];
|
|
118
|
+
} | undefined;
|
|
119
|
+
event: {
|
|
120
|
+
typeId: number;
|
|
121
|
+
deprecationInfo: readonly [ReadonlyMap<number, {
|
|
122
|
+
type: "DeprecatedWithoutNote";
|
|
123
|
+
} | {
|
|
124
|
+
type: "Deprecated";
|
|
125
|
+
value: {
|
|
126
|
+
note: string;
|
|
127
|
+
since: string | undefined;
|
|
128
|
+
};
|
|
129
|
+
}>];
|
|
130
|
+
} | undefined;
|
|
98
131
|
constants: {
|
|
99
132
|
name: string;
|
|
100
133
|
typeId: number;
|
|
101
134
|
value: `0x${string}`;
|
|
102
135
|
docs: string[];
|
|
136
|
+
deprecationInfo: {
|
|
137
|
+
type: "NotDeprecated";
|
|
138
|
+
} | {
|
|
139
|
+
type: "DeprecatedWithoutNote";
|
|
140
|
+
} | {
|
|
141
|
+
type: "Deprecated";
|
|
142
|
+
value: {
|
|
143
|
+
note: string;
|
|
144
|
+
since: string | undefined;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
}[];
|
|
148
|
+
error: {
|
|
149
|
+
typeId: number;
|
|
150
|
+
deprecationInfo: readonly [ReadonlyMap<number, {
|
|
151
|
+
type: "DeprecatedWithoutNote";
|
|
152
|
+
} | {
|
|
153
|
+
type: "Deprecated";
|
|
154
|
+
value: {
|
|
155
|
+
note: string;
|
|
156
|
+
since: string | undefined;
|
|
157
|
+
};
|
|
158
|
+
}>];
|
|
159
|
+
} | undefined;
|
|
160
|
+
associatedTypes: {
|
|
161
|
+
name: string;
|
|
162
|
+
typeId: number;
|
|
163
|
+
docs: string[];
|
|
164
|
+
}[];
|
|
165
|
+
viewFunctions: {
|
|
166
|
+
id: readonly [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number];
|
|
167
|
+
name: string;
|
|
168
|
+
inputs: {
|
|
169
|
+
name: string;
|
|
170
|
+
typeId: number;
|
|
171
|
+
}[];
|
|
172
|
+
output: number;
|
|
173
|
+
docs: string[];
|
|
174
|
+
deprecationInfo: {
|
|
175
|
+
type: "NotDeprecated";
|
|
176
|
+
} | {
|
|
177
|
+
type: "DeprecatedWithoutNote";
|
|
178
|
+
} | {
|
|
179
|
+
type: "Deprecated";
|
|
180
|
+
value: {
|
|
181
|
+
note: string;
|
|
182
|
+
since: string | undefined;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
103
185
|
}[];
|
|
104
|
-
error: number | undefined;
|
|
105
186
|
index: number;
|
|
106
187
|
docs: string[];
|
|
188
|
+
deprecationInfo: {
|
|
189
|
+
type: "NotDeprecated";
|
|
190
|
+
} | {
|
|
191
|
+
type: "DeprecatedWithoutNote";
|
|
192
|
+
} | {
|
|
193
|
+
type: "Deprecated";
|
|
194
|
+
value: {
|
|
195
|
+
note: string;
|
|
196
|
+
since: string | undefined;
|
|
197
|
+
};
|
|
198
|
+
};
|
|
107
199
|
}[];
|
|
108
200
|
extrinsic: {
|
|
109
|
-
|
|
201
|
+
versions: number[];
|
|
110
202
|
addressTypeId: number;
|
|
111
|
-
callTypeId: number;
|
|
112
203
|
signatureTypeId: number;
|
|
113
|
-
|
|
204
|
+
callTypeId: number;
|
|
205
|
+
signedExtensionsByVersion: ReadonlyMap<number, number[]>;
|
|
114
206
|
signedExtensions: {
|
|
115
207
|
ident: string;
|
|
116
208
|
typeId: number;
|
|
117
209
|
additionalSigned: number;
|
|
118
210
|
}[];
|
|
119
211
|
};
|
|
120
|
-
runtimeType: number;
|
|
121
212
|
apis: {
|
|
122
213
|
name: string;
|
|
123
214
|
methods: {
|
|
@@ -128,8 +219,31 @@ export declare abstract class Executor<ChainApi extends GenericSubstrateApi = Ge
|
|
|
128
219
|
}[];
|
|
129
220
|
output: number;
|
|
130
221
|
docs: string[];
|
|
222
|
+
deprecationInfo: {
|
|
223
|
+
type: "NotDeprecated";
|
|
224
|
+
} | {
|
|
225
|
+
type: "DeprecatedWithoutNote";
|
|
226
|
+
} | {
|
|
227
|
+
type: "Deprecated";
|
|
228
|
+
value: {
|
|
229
|
+
note: string;
|
|
230
|
+
since: string | undefined;
|
|
231
|
+
};
|
|
232
|
+
};
|
|
131
233
|
}[];
|
|
132
234
|
docs: string[];
|
|
235
|
+
version: number;
|
|
236
|
+
deprecationInfo: {
|
|
237
|
+
type: "NotDeprecated";
|
|
238
|
+
} | {
|
|
239
|
+
type: "DeprecatedWithoutNote";
|
|
240
|
+
} | {
|
|
241
|
+
type: "Deprecated";
|
|
242
|
+
value: {
|
|
243
|
+
note: string;
|
|
244
|
+
since: string | undefined;
|
|
245
|
+
};
|
|
246
|
+
};
|
|
133
247
|
}[];
|
|
134
248
|
outerEnums: {
|
|
135
249
|
callEnumTypeId: number;
|
package/executor/TxExecutor.js
CHANGED
|
@@ -9,7 +9,7 @@ export class TxExecutor extends Executor {
|
|
|
9
9
|
doExecute(pallet, functionName) {
|
|
10
10
|
const targetPallet = this.getPallet(pallet);
|
|
11
11
|
assert(targetPallet.calls, new UnknownApiError(`Tx calls are not available for pallet ${targetPallet.name}`));
|
|
12
|
-
const txType = this.metadata.types[targetPallet.calls];
|
|
12
|
+
const txType = this.metadata.types[targetPallet.calls.typeId];
|
|
13
13
|
assert(txType.typeDef.type === 'Enum', new UnknownApiError('Tx type defs should be enum'));
|
|
14
14
|
const isFlatEnum = txType.typeDef.value.members.every((m) => m.fields.length === 0);
|
|
15
15
|
const txCallDef = txType.typeDef.value.members.find((m) => stringCamelCase(m.name) === functionName);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { DEFAULT_EXTRINSIC_VERSION } from '@dedot/codecs';
|
|
1
2
|
import * as $ from '@dedot/shape';
|
|
2
|
-
import { ensurePresence, u8aToHex } from '@dedot/utils';
|
|
3
|
+
import { assert, ensurePresence, u8aToHex } from '@dedot/utils';
|
|
3
4
|
import { FallbackSignedExtension, isEmptyStructOrTuple } from './FallbackSignedExtension.js';
|
|
4
5
|
import { SignedExtension } from './SignedExtension.js';
|
|
5
6
|
import { knownSignedExtensions } from './known/index.js';
|
|
@@ -21,8 +22,7 @@ export class ExtraSignedExtension extends SignedExtension {
|
|
|
21
22
|
return 'ExtraSignedExtension';
|
|
22
23
|
}
|
|
23
24
|
get $Data() {
|
|
24
|
-
|
|
25
|
-
return ensurePresence(this.registry.findCodec(extraTypeId));
|
|
25
|
+
return ensurePresence(this.registry.$Extra());
|
|
26
26
|
}
|
|
27
27
|
get $AdditionalSigned() {
|
|
28
28
|
const $AdditionalSignedCodecs = this.#signedExtensionDefs.map((se) => this.registry.findCodec(se.additionalSigned));
|
|
@@ -68,12 +68,14 @@ export class ExtraSignedExtension extends SignedExtension {
|
|
|
68
68
|
}
|
|
69
69
|
toPayload(call = '0x') {
|
|
70
70
|
const signedExtensions = this.#signedExtensions.map((se) => se.identifier);
|
|
71
|
-
const {
|
|
71
|
+
const { versions } = this.registry.metadata.extrinsic;
|
|
72
72
|
const { signerAddress } = this.options;
|
|
73
|
+
assert(versions.includes(DEFAULT_EXTRINSIC_VERSION), // --
|
|
74
|
+
'Extrinsic Version 4 Not Found');
|
|
73
75
|
return Object.assign({
|
|
74
76
|
address: signerAddress,
|
|
75
77
|
signedExtensions,
|
|
76
|
-
version,
|
|
78
|
+
version: DEFAULT_EXTRINSIC_VERSION,
|
|
77
79
|
method: call,
|
|
78
80
|
withSignedTransaction: true, // allow signer/wallet to alter transaction by default
|
|
79
81
|
}, ...this.#signedExtensions.map((se) => se.toPayload()));
|
|
@@ -80,18 +80,19 @@ export class ChainHead extends JsonRpcGroup {
|
|
|
80
80
|
const defer = deferred();
|
|
81
81
|
try {
|
|
82
82
|
this.#unsub && this.#unsub().catch(noop); // ensure unfollowed
|
|
83
|
+
const SIGNAL_THRESHOLD = this.#__unsafe__isSmoldot() ? 2 : 1;
|
|
83
84
|
let signals = 0;
|
|
84
85
|
this.#unsub = await this.send('follow', true, (event, subscription) => {
|
|
85
86
|
this.#followResponseQueue
|
|
86
87
|
.enqueue(async () => {
|
|
87
88
|
await this.#onFollowEvent(event, subscription);
|
|
88
|
-
if (signals >=
|
|
89
|
+
if (signals >= SIGNAL_THRESHOLD)
|
|
89
90
|
return;
|
|
90
91
|
signals += 1;
|
|
91
92
|
// Sometime smoldot send a `stop` event right after `initialized`
|
|
92
93
|
// So requests sending between `initialized` and `stop` will be on pruned hashes -> throwing out errors
|
|
93
94
|
// Here we make sure to receive at least the first 2 signals to resolve
|
|
94
|
-
if (signals >=
|
|
95
|
+
if (signals >= SIGNAL_THRESHOLD) {
|
|
95
96
|
defer.resolve();
|
|
96
97
|
}
|
|
97
98
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
|
|
5
5
|
"author": "Thang X. Vu <thang@dedot.dev>",
|
|
6
6
|
"homepage": "https://dedot.dev",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@dedot/codecs": "0.
|
|
17
|
-
"@dedot/providers": "0.
|
|
18
|
-
"@dedot/runtime-specs": "0.
|
|
19
|
-
"@dedot/shape": "0.
|
|
20
|
-
"@dedot/storage": "0.
|
|
21
|
-
"@dedot/types": "0.
|
|
22
|
-
"@dedot/utils": "0.
|
|
16
|
+
"@dedot/codecs": "0.13.0",
|
|
17
|
+
"@dedot/providers": "0.13.0",
|
|
18
|
+
"@dedot/runtime-specs": "0.13.0",
|
|
19
|
+
"@dedot/shape": "0.13.0",
|
|
20
|
+
"@dedot/storage": "0.13.0",
|
|
21
|
+
"@dedot/types": "0.13.0",
|
|
22
|
+
"@dedot/utils": "0.13.0"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"node": ">=18"
|
|
49
49
|
},
|
|
50
50
|
"license": "Apache-2.0",
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "b9193d170fc63ebd64b75f37f8276a7159e2af55",
|
|
52
52
|
"module": "./index.js",
|
|
53
53
|
"types": "./index.d.ts"
|
|
54
54
|
}
|