@dedot/api 1.0.4 → 1.1.1
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/client/BaseSubstrateClient.js +3 -0
- package/cjs/client/DedotClient.js +25 -0
- package/cjs/client/LegacyClient.js +3 -0
- package/cjs/client/V2Client.js +3 -0
- package/cjs/extrinsic/submittable/BaseSubmittableExtrinsic.js +3 -1
- package/client/BaseSubstrateClient.d.ts +2 -1
- package/client/BaseSubstrateClient.js +3 -0
- package/client/DedotClient.d.ts +24 -1
- package/client/DedotClient.js +25 -0
- package/client/LegacyClient.d.ts +2 -1
- package/client/LegacyClient.js +3 -0
- package/client/V2Client.d.ts +2 -1
- package/client/V2Client.js +3 -0
- package/extrinsic/submittable/BaseSubmittableExtrinsic.js +3 -1
- package/package.json +9 -9
- package/types.d.ts +24 -1
|
@@ -410,6 +410,9 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
|
|
|
410
410
|
sendTx(tx, callback) {
|
|
411
411
|
throw new Error('Unimplemented!');
|
|
412
412
|
}
|
|
413
|
+
toTx(tx) {
|
|
414
|
+
throw new Error('Unimplemented!');
|
|
415
|
+
}
|
|
413
416
|
get chainSpec() {
|
|
414
417
|
throw new Error('Unimplemented!');
|
|
415
418
|
}
|
|
@@ -394,6 +394,31 @@ class DedotClient {
|
|
|
394
394
|
sendTx(tx, callback) {
|
|
395
395
|
return this.#client.sendTx(tx, callback);
|
|
396
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* Convert a raw hex-encoded transaction or an Extrinsic instance into a submittable extrinsic
|
|
399
|
+
* with `sign`, `signAndSend`, `send`, and `paymentInfo` methods.
|
|
400
|
+
*
|
|
401
|
+
* @param tx - A hex-encoded transaction string or an Extrinsic instance
|
|
402
|
+
* @returns A submittable extrinsic instance
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* // Convert a raw hex transaction to a submittable extrinsic
|
|
407
|
+
* const submittable = client.toTx(rawTxHex);
|
|
408
|
+
*
|
|
409
|
+
* // Sign and send
|
|
410
|
+
* const unsub = await submittable.signAndSend(alice, (result) => {
|
|
411
|
+
* console.log('Status:', result.status);
|
|
412
|
+
* });
|
|
413
|
+
*
|
|
414
|
+
* // Or query payment info
|
|
415
|
+
* const paymentInfo = await submittable.paymentInfo(alice);
|
|
416
|
+
* console.log('Estimated fee:', paymentInfo.partialFee);
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
toTx(tx) {
|
|
420
|
+
return this.#client.toTx(tx);
|
|
421
|
+
}
|
|
397
422
|
/**
|
|
398
423
|
* Clear internal caches.
|
|
399
424
|
*
|
package/cjs/client/V2Client.js
CHANGED
|
@@ -50,7 +50,9 @@ class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
|
|
|
50
50
|
return result;
|
|
51
51
|
}
|
|
52
52
|
async paymentInfo(account, options) {
|
|
53
|
-
|
|
53
|
+
if (!this.signed) {
|
|
54
|
+
await this.sign(account, { ...options, signer: fakeSigner_js_1.fakeSigner });
|
|
55
|
+
}
|
|
54
56
|
const txU8a = this.toU8a();
|
|
55
57
|
const api = this.client;
|
|
56
58
|
return api.call.transactionPaymentApi.queryInfo(txU8a, txU8a.length);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BlockHash, Extrinsic, Hash, Metadata, PortableRegistry, RuntimeVersion } from '@dedot/codecs';
|
|
2
2
|
import { type JsonRpcProvider } from '@dedot/providers';
|
|
3
3
|
import { type IStorage } from '@dedot/storage';
|
|
4
|
-
import { Callback, GenericStorageQuery, GenericSubstrateApi, InjectedSigner, ISubmittableResult, Query, QueryFnResult, RpcVersion, TxUnsub, Unsub } from '@dedot/types';
|
|
4
|
+
import { Callback, ChainSubmittableExtrinsic, GenericStorageQuery, GenericSubstrateApi, InjectedSigner, ISubmittableResult, Query, QueryFnResult, RpcVersion, TxUnsub, Unsub } from '@dedot/types';
|
|
5
5
|
import { Deferred, HexString, LRUCache } from '@dedot/utils';
|
|
6
6
|
import type { SubstrateApi } from '../chaintypes/index.js';
|
|
7
7
|
import { JsonRpcClient } from '../json-rpc/index.js';
|
|
@@ -133,6 +133,7 @@ export declare abstract class BaseSubstrateClient<ChainApi extends GenericSubstr
|
|
|
133
133
|
}>): Promise<Unsub>;
|
|
134
134
|
protected getStorageQuery(): BaseStorageQuery;
|
|
135
135
|
sendTx(tx: HexString | Extrinsic, callback?: Callback<ISubmittableResult<ChainApi['types']['EventRecord']>>): TxUnsub;
|
|
136
|
+
toTx(tx: HexString | Extrinsic): ChainSubmittableExtrinsic<ChainApi>;
|
|
136
137
|
get chainSpec(): IChainSpec;
|
|
137
138
|
on<Event extends Events = Events>(event: Event, handler: EventHandlerFn<Event>): () => void;
|
|
138
139
|
}
|
|
@@ -406,6 +406,9 @@ export class BaseSubstrateClient extends JsonRpcClient {
|
|
|
406
406
|
sendTx(tx, callback) {
|
|
407
407
|
throw new Error('Unimplemented!');
|
|
408
408
|
}
|
|
409
|
+
toTx(tx) {
|
|
410
|
+
throw new Error('Unimplemented!');
|
|
411
|
+
}
|
|
409
412
|
get chainSpec() {
|
|
410
413
|
throw new Error('Unimplemented!');
|
|
411
414
|
}
|
package/client/DedotClient.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Extrinsic, Metadata, PortableRegistry } from '@dedot/codecs';
|
|
2
2
|
import { ConnectionStatus, JsonRpcProvider } from '@dedot/providers';
|
|
3
|
-
import { Callback, GenericStorageQuery, GenericSubstrateApi, InjectedSigner, ISubmittableResult, Query, QueryFnResult, RpcVersion, TxUnsub, Unsub } from '@dedot/types';
|
|
3
|
+
import { Callback, ChainSubmittableExtrinsic, GenericStorageQuery, GenericSubstrateApi, InjectedSigner, ISubmittableResult, Query, QueryFnResult, RpcVersion, TxUnsub, Unsub } from '@dedot/types';
|
|
4
4
|
import { HexString } from '@dedot/utils';
|
|
5
5
|
import { SubstrateApi } from '../chaintypes/index.js';
|
|
6
6
|
import { ApiEvent, ApiOptions, BlockExplorer, ISubstrateClient, ISubstrateClientAt, SubstrateRuntimeVersion, IChainSpec, type EventHandlerFn } from '../types.js';
|
|
@@ -359,6 +359,29 @@ export declare class DedotClient<ChainApi extends GenericSubstrateApi = Substrat
|
|
|
359
359
|
* ```
|
|
360
360
|
*/
|
|
361
361
|
sendTx(tx: HexString | Extrinsic, callback?: Callback<ISubmittableResult<ChainApi['types']['EventRecord']>>): TxUnsub;
|
|
362
|
+
/**
|
|
363
|
+
* Convert a raw hex-encoded transaction or an Extrinsic instance into a submittable extrinsic
|
|
364
|
+
* with `sign`, `signAndSend`, `send`, and `paymentInfo` methods.
|
|
365
|
+
*
|
|
366
|
+
* @param tx - A hex-encoded transaction string or an Extrinsic instance
|
|
367
|
+
* @returns A submittable extrinsic instance
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```typescript
|
|
371
|
+
* // Convert a raw hex transaction to a submittable extrinsic
|
|
372
|
+
* const submittable = client.toTx(rawTxHex);
|
|
373
|
+
*
|
|
374
|
+
* // Sign and send
|
|
375
|
+
* const unsub = await submittable.signAndSend(alice, (result) => {
|
|
376
|
+
* console.log('Status:', result.status);
|
|
377
|
+
* });
|
|
378
|
+
*
|
|
379
|
+
* // Or query payment info
|
|
380
|
+
* const paymentInfo = await submittable.paymentInfo(alice);
|
|
381
|
+
* console.log('Estimated fee:', paymentInfo.partialFee);
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
toTx(tx: HexString | Extrinsic): ChainSubmittableExtrinsic<ChainApi>;
|
|
362
385
|
/**
|
|
363
386
|
* Clear internal caches.
|
|
364
387
|
*
|
package/client/DedotClient.js
CHANGED
|
@@ -391,6 +391,31 @@ export class DedotClient {
|
|
|
391
391
|
sendTx(tx, callback) {
|
|
392
392
|
return this.#client.sendTx(tx, callback);
|
|
393
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Convert a raw hex-encoded transaction or an Extrinsic instance into a submittable extrinsic
|
|
396
|
+
* with `sign`, `signAndSend`, `send`, and `paymentInfo` methods.
|
|
397
|
+
*
|
|
398
|
+
* @param tx - A hex-encoded transaction string or an Extrinsic instance
|
|
399
|
+
* @returns A submittable extrinsic instance
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* ```typescript
|
|
403
|
+
* // Convert a raw hex transaction to a submittable extrinsic
|
|
404
|
+
* const submittable = client.toTx(rawTxHex);
|
|
405
|
+
*
|
|
406
|
+
* // Sign and send
|
|
407
|
+
* const unsub = await submittable.signAndSend(alice, (result) => {
|
|
408
|
+
* console.log('Status:', result.status);
|
|
409
|
+
* });
|
|
410
|
+
*
|
|
411
|
+
* // Or query payment info
|
|
412
|
+
* const paymentInfo = await submittable.paymentInfo(alice);
|
|
413
|
+
* console.log('Estimated fee:', paymentInfo.partialFee);
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
toTx(tx) {
|
|
417
|
+
return this.#client.toTx(tx);
|
|
418
|
+
}
|
|
394
419
|
/**
|
|
395
420
|
* Clear internal caches.
|
|
396
421
|
*
|
package/client/LegacyClient.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BlockHash, type Extrinsic, Metadata } from '@dedot/codecs';
|
|
2
2
|
import type { JsonRpcProvider } from '@dedot/providers';
|
|
3
|
-
import { Callback, GenericSubstrateApi, ISubmittableResult, TxUnsub } from '@dedot/types';
|
|
3
|
+
import { Callback, ChainSubmittableExtrinsic, GenericSubstrateApi, ISubmittableResult, TxUnsub } from '@dedot/types';
|
|
4
4
|
import { HexString } from '@dedot/utils';
|
|
5
5
|
import type { SubstrateApi } from '../chaintypes/index.js';
|
|
6
6
|
import { BaseStorageQuery } from '../storage/index.js';
|
|
@@ -137,4 +137,5 @@ export declare class LegacyClient<ChainApi extends GenericSubstrateApi = Substra
|
|
|
137
137
|
at<ChainApiAt extends GenericSubstrateApi = ChainApi>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
|
|
138
138
|
protected getStorageQuery(): BaseStorageQuery;
|
|
139
139
|
sendTx(tx: HexString | Extrinsic, callback?: Callback<ISubmittableResult<ChainApi['types']['EventRecord']>>): TxUnsub;
|
|
140
|
+
toTx(tx: HexString | Extrinsic): ChainSubmittableExtrinsic<ChainApi>;
|
|
140
141
|
}
|
package/client/LegacyClient.js
CHANGED
package/client/V2Client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BlockHash, type Extrinsic, Metadata } from '@dedot/codecs';
|
|
2
2
|
import type { JsonRpcProvider } from '@dedot/providers';
|
|
3
|
-
import { Callback, GenericSubstrateApi, ISubmittableResult, TxUnsub } from '@dedot/types';
|
|
3
|
+
import { Callback, ChainSubmittableExtrinsic, GenericSubstrateApi, ISubmittableResult, TxUnsub } from '@dedot/types';
|
|
4
4
|
import { HexString } from '@dedot/utils';
|
|
5
5
|
import type { SubstrateApi } from '../chaintypes/index.js';
|
|
6
6
|
import { Archive, ChainHead, ChainSpec, PinnedBlock } from '../json-rpc/index.js';
|
|
@@ -72,4 +72,5 @@ export declare class V2Client<ChainApi extends GenericSubstrateApi = SubstrateAp
|
|
|
72
72
|
at<ChainApiAt extends GenericSubstrateApi = ChainApi>(hash: BlockHash): Promise<ISubstrateClientAt<ChainApiAt>>;
|
|
73
73
|
protected getStorageQuery(): BaseStorageQuery;
|
|
74
74
|
sendTx(tx: HexString | Extrinsic, callback?: Callback<ISubmittableResult<ChainApi['types']['EventRecord']>>): TxUnsub;
|
|
75
|
+
toTx(tx: HexString | Extrinsic): ChainSubmittableExtrinsic<ChainApi>;
|
|
75
76
|
}
|
package/client/V2Client.js
CHANGED
|
@@ -24,7 +24,9 @@ export class BaseSubmittableExtrinsic extends Extrinsic {
|
|
|
24
24
|
return result;
|
|
25
25
|
}
|
|
26
26
|
async paymentInfo(account, options) {
|
|
27
|
-
|
|
27
|
+
if (!this.signed) {
|
|
28
|
+
await this.sign(account, { ...options, signer: fakeSigner });
|
|
29
|
+
}
|
|
28
30
|
const txU8a = this.toU8a();
|
|
29
31
|
const api = this.client;
|
|
30
32
|
return api.call.transactionPaymentApi.queryInfo(txU8a, txU8a.length);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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": "1.
|
|
17
|
-
"@dedot/providers": "1.
|
|
18
|
-
"@dedot/runtime-specs": "1.
|
|
19
|
-
"@dedot/shape": "1.
|
|
20
|
-
"@dedot/storage": "1.
|
|
21
|
-
"@dedot/types": "1.
|
|
22
|
-
"@dedot/utils": "1.
|
|
16
|
+
"@dedot/codecs": "^1.1.1",
|
|
17
|
+
"@dedot/providers": "^1.1.1",
|
|
18
|
+
"@dedot/runtime-specs": "^1.1.1",
|
|
19
|
+
"@dedot/shape": "^1.1.1",
|
|
20
|
+
"@dedot/storage": "^1.1.1",
|
|
21
|
+
"@dedot/types": "^1.1.1",
|
|
22
|
+
"@dedot/utils": "^1.1.1"
|
|
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": "d64c5da3433f21b17fcf1e431235b8694ed11fa2",
|
|
52
52
|
"module": "./index.js",
|
|
53
53
|
"types": "./index.d.ts"
|
|
54
54
|
}
|
package/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BlockHash, Extrinsic, Hash, Header, Metadata, PortableRegistry } from '
|
|
|
2
2
|
import type { ConnectionStatus, JsonRpcProvider, ProviderEvent } from '@dedot/providers';
|
|
3
3
|
import type { AnyShape } from '@dedot/shape';
|
|
4
4
|
import type { IStorage } from '@dedot/storage';
|
|
5
|
-
import { Callback, GenericStorageQuery, GenericSubstrateApi, InjectedSigner, ISubmittableResult, Query, QueryFnResult, RpcVersion, RuntimeApiName, RuntimeApiSpec, TxUnsub, Unsub } from '@dedot/types';
|
|
5
|
+
import { Callback, ChainSubmittableExtrinsic, GenericStorageQuery, GenericSubstrateApi, InjectedSigner, ISubmittableResult, Query, QueryFnResult, RpcVersion, RuntimeApiName, RuntimeApiSpec, TxUnsub, Unsub } from '@dedot/types';
|
|
6
6
|
import { Properties } from '@dedot/types/json-rpc';
|
|
7
7
|
import type { HashFn, HexString, IEventEmitter } from '@dedot/utils';
|
|
8
8
|
import type { SubstrateApi } from './chaintypes/index.js';
|
|
@@ -225,6 +225,29 @@ Events extends string = ApiEvent> extends IJsonRpcClient<ChainApi, Events>, IGen
|
|
|
225
225
|
* console.log('Transaction finalized:', result);
|
|
226
226
|
*/
|
|
227
227
|
sendTx(tx: HexString | Extrinsic, callback?: Callback<ISubmittableResult<ChainApi['types']['EventRecord']>>): TxUnsub;
|
|
228
|
+
/**
|
|
229
|
+
* Convert a raw hex-encoded transaction or an Extrinsic instance into a submittable extrinsic
|
|
230
|
+
* with `sign`, `signAndSend`, `send`, and `paymentInfo` methods.
|
|
231
|
+
*
|
|
232
|
+
* @param tx - A hex-encoded transaction string or an Extrinsic instance
|
|
233
|
+
* @returns A submittable extrinsic instance
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* // Convert a raw hex transaction to a submittable extrinsic
|
|
238
|
+
* const submittable = client.toTx(rawTxHex);
|
|
239
|
+
*
|
|
240
|
+
* // Sign and send
|
|
241
|
+
* const unsub = await submittable.signAndSend(alice, (result) => {
|
|
242
|
+
* console.log('Status:', result.status);
|
|
243
|
+
* });
|
|
244
|
+
*
|
|
245
|
+
* // Or query payment info
|
|
246
|
+
* const paymentInfo = await submittable.paymentInfo(alice);
|
|
247
|
+
* console.log('Estimated fee:', paymentInfo.partialFee);
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
toTx(tx: HexString | Extrinsic): ChainSubmittableExtrinsic<ChainApi>;
|
|
228
251
|
/**
|
|
229
252
|
* Query multiple storage items in a single call or subscribe to multiple storage items
|
|
230
253
|
*
|