@dedot/api 0.13.1 → 0.14.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/extrinsic/submittable/BaseSubmittableExtrinsic.js +14 -0
- package/cjs/extrinsic/submittable/SubmittableExtrinsic.js +3 -3
- package/cjs/extrinsic/submittable/SubmittableExtrinsicV2.js +1 -0
- package/cjs/extrinsic/submittable/index.js +1 -0
- package/extrinsic/submittable/BaseSubmittableExtrinsic.d.ts +7 -0
- package/extrinsic/submittable/BaseSubmittableExtrinsic.js +14 -0
- package/extrinsic/submittable/SubmittableExtrinsic.js +3 -3
- package/extrinsic/submittable/SubmittableExtrinsicV2.js +1 -0
- package/extrinsic/submittable/index.d.ts +1 -0
- package/extrinsic/submittable/index.js +1 -0
- package/package.json +9 -9
|
@@ -9,10 +9,21 @@ const utils_js_1 = require("./utils.js");
|
|
|
9
9
|
class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
|
|
10
10
|
client;
|
|
11
11
|
#alterTx;
|
|
12
|
+
#hooks;
|
|
12
13
|
constructor(client, call) {
|
|
13
14
|
super(client.registry, call);
|
|
14
15
|
this.client = client;
|
|
15
16
|
}
|
|
17
|
+
withHooks(hooks) {
|
|
18
|
+
this.#hooks = hooks;
|
|
19
|
+
}
|
|
20
|
+
transformTxResult(result) {
|
|
21
|
+
const transform = this.#hooks?.transformResult;
|
|
22
|
+
if (typeof transform === 'function') {
|
|
23
|
+
return transform(result);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
16
27
|
async paymentInfo(account, options) {
|
|
17
28
|
await this.sign(account, { ...options, signer: fakeSigner_js_1.fakeSigner });
|
|
18
29
|
const txU8a = this.toU8a();
|
|
@@ -21,6 +32,9 @@ class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
|
|
|
21
32
|
}
|
|
22
33
|
async sign(fromAccount, options) {
|
|
23
34
|
const address = (0, utils_js_1.isKeyringPair)(fromAccount) ? fromAccount.address : fromAccount.toString();
|
|
35
|
+
const beforeSign = this.#hooks?.beforeSign;
|
|
36
|
+
if (beforeSign)
|
|
37
|
+
await beforeSign(this, address);
|
|
24
38
|
const extra = new index_js_1.ExtraSignedExtension(this.client, {
|
|
25
39
|
signerAddress: address,
|
|
26
40
|
payloadOptions: options,
|
|
@@ -35,17 +35,17 @@ class SubmittableExtrinsic extends BaseSubmittableExtrinsic_js_1.BaseSubmittable
|
|
|
35
35
|
const events = blockEvents.filter(({ phase }) => phase.type === 'ApplyExtrinsic' && phase.value === txIndex);
|
|
36
36
|
const blockNumber = signedBlock.block.header.number;
|
|
37
37
|
const status = (0, utils_js_1.toTxStatus)(txStatus, { txIndex, blockNumber });
|
|
38
|
-
const result = new SubmittableResult_js_1.SubmittableResult({ status, txHash, events, txIndex });
|
|
38
|
+
const result = this.transformTxResult(new SubmittableResult_js_1.SubmittableResult({ status, txHash, events, txIndex }));
|
|
39
39
|
onTxProgress(result);
|
|
40
40
|
!isSubscription && deferTx.resolve(txHash);
|
|
41
41
|
return callback?.(result);
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
44
|
const status = (0, utils_js_1.toTxStatus)(txStatus);
|
|
45
|
-
const result = new SubmittableResult_js_1.SubmittableResult({ status, txHash });
|
|
45
|
+
const result = this.transformTxResult(new SubmittableResult_js_1.SubmittableResult({ status, txHash }));
|
|
46
46
|
onTxProgress(result);
|
|
47
47
|
!isSubscription && deferTx.resolve(txHash);
|
|
48
|
-
return callback?.(
|
|
48
|
+
return callback?.(result);
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
51
|
if (isSubscription) {
|
|
@@ -184,6 +184,7 @@ class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic_js_1.BaseSubmittab
|
|
|
184
184
|
// just in-case we somehow can't find the tx in any block
|
|
185
185
|
let unsub;
|
|
186
186
|
this.#send((result) => {
|
|
187
|
+
result = this.transformTxResult(result);
|
|
187
188
|
onTxProgress(result);
|
|
188
189
|
if (isSubscription) {
|
|
189
190
|
try {
|
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.signRawMessage = void 0;
|
|
18
18
|
__exportStar(require("./errors.js"), exports);
|
|
19
|
+
__exportStar(require("./BaseSubmittableExtrinsic.js"), exports);
|
|
19
20
|
__exportStar(require("./SubmittableResult.js"), exports);
|
|
20
21
|
__exportStar(require("./SubmittableExtrinsic.js"), exports);
|
|
21
22
|
__exportStar(require("./SubmittableExtrinsicV2.js"), exports);
|
|
@@ -3,10 +3,16 @@ import { AddressOrPair, Callback, IRuntimeTxCall, ISubmittableExtrinsic, ISubmit
|
|
|
3
3
|
import { HexString } from '@dedot/utils';
|
|
4
4
|
import type { FrameSystemEventRecord } from '../../chaintypes/index.js';
|
|
5
5
|
import type { ISubstrateClient } from '../../types.js';
|
|
6
|
+
interface TxHooks {
|
|
7
|
+
beforeSign?: (tx: Extrinsic & ISubmittableExtrinsic, signerAddress: string) => Promise<void>;
|
|
8
|
+
transformResult?: <R extends ISubmittableResult = ISubmittableResult>(result: ISubmittableResult) => R;
|
|
9
|
+
}
|
|
6
10
|
export declare abstract class BaseSubmittableExtrinsic extends Extrinsic implements ISubmittableExtrinsic {
|
|
7
11
|
#private;
|
|
8
12
|
readonly client: ISubstrateClient;
|
|
9
13
|
constructor(client: ISubstrateClient, call: IRuntimeTxCall);
|
|
14
|
+
withHooks(hooks: TxHooks): void;
|
|
15
|
+
protected transformTxResult<R extends ISubmittableResult = ISubmittableResult>(result: ISubmittableResult): R;
|
|
10
16
|
paymentInfo(account: AddressOrPair, options?: Partial<PayloadOptions>): Promise<TxPaymentInfo>;
|
|
11
17
|
sign(fromAccount: AddressOrPair, options?: Partial<SignerOptions>): Promise<this>;
|
|
12
18
|
signAndSend(account: AddressOrPair, options?: Partial<SignerOptions>): TxHash;
|
|
@@ -17,3 +23,4 @@ export declare abstract class BaseSubmittableExtrinsic extends Extrinsic impleme
|
|
|
17
23
|
protected getSystemEventsAt(hash: BlockHash): Promise<FrameSystemEventRecord[]>;
|
|
18
24
|
toHex(): HexString;
|
|
19
25
|
}
|
|
26
|
+
export {};
|
|
@@ -6,10 +6,21 @@ import { isKeyringPair, signRawMessage, txDefer } from './utils.js';
|
|
|
6
6
|
export class BaseSubmittableExtrinsic extends Extrinsic {
|
|
7
7
|
client;
|
|
8
8
|
#alterTx;
|
|
9
|
+
#hooks;
|
|
9
10
|
constructor(client, call) {
|
|
10
11
|
super(client.registry, call);
|
|
11
12
|
this.client = client;
|
|
12
13
|
}
|
|
14
|
+
withHooks(hooks) {
|
|
15
|
+
this.#hooks = hooks;
|
|
16
|
+
}
|
|
17
|
+
transformTxResult(result) {
|
|
18
|
+
const transform = this.#hooks?.transformResult;
|
|
19
|
+
if (typeof transform === 'function') {
|
|
20
|
+
return transform(result);
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
13
24
|
async paymentInfo(account, options) {
|
|
14
25
|
await this.sign(account, { ...options, signer: fakeSigner });
|
|
15
26
|
const txU8a = this.toU8a();
|
|
@@ -18,6 +29,9 @@ export class BaseSubmittableExtrinsic extends Extrinsic {
|
|
|
18
29
|
}
|
|
19
30
|
async sign(fromAccount, options) {
|
|
20
31
|
const address = isKeyringPair(fromAccount) ? fromAccount.address : fromAccount.toString();
|
|
32
|
+
const beforeSign = this.#hooks?.beforeSign;
|
|
33
|
+
if (beforeSign)
|
|
34
|
+
await beforeSign(this, address);
|
|
21
35
|
const extra = new ExtraSignedExtension(this.client, {
|
|
22
36
|
signerAddress: address,
|
|
23
37
|
payloadOptions: options,
|
|
@@ -32,17 +32,17 @@ export class SubmittableExtrinsic extends BaseSubmittableExtrinsic {
|
|
|
32
32
|
const events = blockEvents.filter(({ phase }) => phase.type === 'ApplyExtrinsic' && phase.value === txIndex);
|
|
33
33
|
const blockNumber = signedBlock.block.header.number;
|
|
34
34
|
const status = toTxStatus(txStatus, { txIndex, blockNumber });
|
|
35
|
-
const result = new SubmittableResult({ status, txHash, events, txIndex });
|
|
35
|
+
const result = this.transformTxResult(new SubmittableResult({ status, txHash, events, txIndex }));
|
|
36
36
|
onTxProgress(result);
|
|
37
37
|
!isSubscription && deferTx.resolve(txHash);
|
|
38
38
|
return callback?.(result);
|
|
39
39
|
}
|
|
40
40
|
else {
|
|
41
41
|
const status = toTxStatus(txStatus);
|
|
42
|
-
const result = new SubmittableResult({ status, txHash });
|
|
42
|
+
const result = this.transformTxResult(new SubmittableResult({ status, txHash }));
|
|
43
43
|
onTxProgress(result);
|
|
44
44
|
!isSubscription && deferTx.resolve(txHash);
|
|
45
|
-
return callback?.(
|
|
45
|
+
return callback?.(result);
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
if (isSubscription) {
|
|
@@ -181,6 +181,7 @@ export class SubmittableExtrinsicV2 extends BaseSubmittableExtrinsic {
|
|
|
181
181
|
// just in-case we somehow can't find the tx in any block
|
|
182
182
|
let unsub;
|
|
183
183
|
this.#send((result) => {
|
|
184
|
+
result = this.transformTxResult(result);
|
|
184
185
|
onTxProgress(result);
|
|
185
186
|
if (isSubscription) {
|
|
186
187
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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.14.0",
|
|
17
|
+
"@dedot/providers": "0.14.0",
|
|
18
|
+
"@dedot/runtime-specs": "0.14.0",
|
|
19
|
+
"@dedot/shape": "0.14.0",
|
|
20
|
+
"@dedot/storage": "0.14.0",
|
|
21
|
+
"@dedot/types": "0.14.0",
|
|
22
|
+
"@dedot/utils": "0.14.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": "cde1e77566038990fcdd69b291a4231013c16528",
|
|
52
52
|
"module": "./index.js",
|
|
53
53
|
"types": "./index.d.ts"
|
|
54
54
|
}
|