Skip to content

Commit 39ff956

Browse files
authored
Expose constructoir meta on Blueprint/Code (#4486)
1 parent faa22fc commit 39ff956

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

packages/api-contract/src/base/Blueprint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
4747

4848
this.abi.constructors.forEach((c): void => {
4949
if (isUndefined(this.#tx[c.method])) {
50-
this.#tx[c.method] = createBluePrintTx((o, p) => this.#deploy(c, o, p));
50+
this.#tx[c.method] = createBluePrintTx(c, (o, p) => this.#deploy(c, o, p));
5151
}
5252
});
5353
}

packages/api-contract/src/base/Code.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
5252

5353
this.abi.constructors.forEach((c): void => {
5454
if (isUndefined(this.#tx[c.method])) {
55-
this.#tx[c.method] = createBluePrintTx((o, p) => this.#instantiate(c, o, p));
55+
this.#tx[c.method] = createBluePrintTx(c, (o, p) => this.#instantiate(c, o, p));
5656
}
5757
});
5858
}

packages/api-contract/src/base/Contract.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { assert, BN, BN_HUNDRED, BN_ONE, BN_ZERO, bnToBn, isFunction, isUndefine
1818
import { Abi } from '../Abi';
1919
import { applyOnEvent, extractOptions, isOptions } from '../util';
2020
import { Base } from './Base';
21+
import { withMeta } from './util';
2122

2223
export interface ContractConstructor<ApiType extends ApiTypes> {
2324
new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId): Contract<ApiType>;
@@ -29,12 +30,6 @@ const ERROR_NO_CALL = 'Your node does not expose the contracts.call RPC. This is
2930

3031
const l = logger('Contract');
3132

32-
function withMeta <T extends { meta: AbiMessage }> (meta: AbiMessage, creator: Omit<T, 'meta'>): T {
33-
(creator as T).meta = meta;
34-
35-
return creator as T;
36-
}
37-
3833
function createQuery <ApiType extends ApiTypes> (meta: AbiMessage, fn: (origin: string | AccountId | Uint8Array, options: ContractOptions, params: unknown[]) => ContractCallResult<ApiType, ContractCallOutcome>): ContractQuery<ApiType> {
3934
return withMeta(meta, (origin: string | AccountId | Uint8Array, options: bigint | string | number | BN | ContractOptions, ...params: unknown[]): ContractCallResult<ApiType, ContractCallOutcome> =>
4035
isOptions(options)

packages/api-contract/src/base/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import type { AccountId } from '@polkadot/types/interfaces';
88
import type { BN } from '@polkadot/util';
99
import type { AbiMessage, BlueprintOptions, ContractCallOutcome, ContractOptions } from '../types';
1010

11-
export interface BlueprintDeploy<ApiType extends ApiTypes> {
11+
export interface MessageMeta {
12+
readonly meta: AbiMessage;
13+
}
14+
15+
export interface BlueprintDeploy<ApiType extends ApiTypes> extends MessageMeta {
1216
(options: BlueprintOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType>;
1317
// @deprecated Use options form (to be dropped in a major update)
1418
(value: bigint | string | number | BN, gasLimit: bigint | string | number | BN, ...params: unknown[]): SubmittableExtrinsic<ApiType>;
1519
}
1620

17-
export interface MessageMeta {
18-
readonly meta: AbiMessage;
19-
}
20-
2121
export interface ContractQuery<ApiType extends ApiTypes> extends MessageMeta {
2222
(origin: AccountId | string | Uint8Array, options: ContractOptions, ...params: unknown[]): ContractCallResult<ApiType, ContractCallOutcome>;
2323
// @deprecated Use options form (to be dropped in a major update)

packages/api-contract/src/base/util.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { SubmittableResult } from '@polkadot/api';
55
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
66
import type { ApiTypes } from '@polkadot/api/types';
77
import type { BN } from '@polkadot/util';
8-
import type { AbiConstructor, BlueprintOptions } from '../types';
8+
import type { AbiConstructor, AbiMessage, BlueprintOptions } from '../types';
99
import type { BlueprintDeploy, ContractGeneric } from './types';
1010

1111
import { Bytes } from '@polkadot/types';
@@ -16,11 +16,18 @@ import { extractOptions, isOptions } from '../util';
1616

1717
export const EMPTY_SALT = new Uint8Array();
1818

19-
export function createBluePrintTx <ApiType extends ApiTypes, R extends SubmittableResult> (fn: (options: BlueprintOptions, params: unknown[]) => SubmittableExtrinsic<ApiType, R>): BlueprintDeploy<ApiType> {
20-
return (options: bigint | string | number | BN | BlueprintOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType, R> =>
19+
export function withMeta <T extends { meta: AbiMessage }> (meta: AbiMessage, creator: Omit<T, 'meta'>): T {
20+
(creator as T).meta = meta;
21+
22+
return creator as T;
23+
}
24+
25+
export function createBluePrintTx <ApiType extends ApiTypes, R extends SubmittableResult> (meta: AbiMessage, fn: (options: BlueprintOptions, params: unknown[]) => SubmittableExtrinsic<ApiType, R>): BlueprintDeploy<ApiType> {
26+
return withMeta(meta, (options: bigint | string | number | BN | BlueprintOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType, R> =>
2127
isOptions(options)
2228
? fn(options, params)
23-
: fn(...extractOptions<BlueprintOptions>(options, params));
29+
: fn(...extractOptions<BlueprintOptions>(options, params))
30+
);
2431
}
2532

2633
export function createBluePrintWithId <T> (fn: (constructorOrId: AbiConstructor | string | number, options: BlueprintOptions, params: unknown[]) => T): ContractGeneric<BlueprintOptions, T> {

0 commit comments

Comments
 (0)