@dedot/contracts 0.0.1-next.9c1d51fe.10 → 0.0.1-next.a5b1d2fb.22
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/Contract.d.ts +2 -4
- package/ContractDeployer.d.ts +2 -4
- package/ContractDeployer.js +1 -2
- package/cjs/ContractDeployer.js +1 -2
- package/cjs/executor/ConstructorQueryExecutor.js +4 -4
- package/cjs/executor/QueryExecutor.js +7 -6
- package/cjs/utils.js +4 -4
- package/executor/ConstructorQueryExecutor.d.ts +2 -2
- package/executor/ConstructorQueryExecutor.js +2 -2
- package/executor/QueryExecutor.js +7 -6
- package/package.json +6 -6
- package/types/index.d.ts +19 -18
- package/types/shared.d.ts +7 -7
- package/types/v4.d.ts +1 -1
package/Contract.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { ISubstrateClient } from '@dedot/api';
|
|
2
|
-
import { SubstrateApi } from '@dedot/api/chaintypes';
|
|
3
2
|
import { AccountId32, AccountId32Like } from '@dedot/codecs';
|
|
4
|
-
import { GenericSubstrateApi, RpcVersion } from '@dedot/types';
|
|
5
3
|
import { TypinkRegistry } from './TypinkRegistry.js';
|
|
6
4
|
import { ContractMetadata, GenericContractApi } from './types/index.js';
|
|
7
|
-
export declare class Contract<ContractApi extends GenericContractApi = GenericContractApi
|
|
5
|
+
export declare class Contract<ContractApi extends GenericContractApi = GenericContractApi> {
|
|
8
6
|
#private;
|
|
9
|
-
constructor(api: ISubstrateClient
|
|
7
|
+
constructor(api: ISubstrateClient, address: AccountId32Like, metadata: ContractMetadata | string);
|
|
10
8
|
get metadata(): ContractMetadata;
|
|
11
9
|
get address(): AccountId32;
|
|
12
10
|
get registry(): TypinkRegistry;
|
package/ContractDeployer.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { ISubstrateClient } from '@dedot/api';
|
|
2
|
-
import { SubstrateApi } from '@dedot/api/chaintypes';
|
|
3
2
|
import { Hash } from '@dedot/codecs';
|
|
4
|
-
import { GenericSubstrateApi, RpcVersion } from '@dedot/types';
|
|
5
3
|
import { TypinkRegistry } from './TypinkRegistry.js';
|
|
6
4
|
import { ContractMetadata, GenericContractApi } from './types/index.js';
|
|
7
|
-
export declare class ContractDeployer<ContractApi extends GenericContractApi = GenericContractApi
|
|
5
|
+
export declare class ContractDeployer<ContractApi extends GenericContractApi = GenericContractApi> {
|
|
8
6
|
#private;
|
|
9
|
-
constructor(api: ISubstrateClient
|
|
7
|
+
constructor(api: ISubstrateClient, metadata: ContractMetadata | string, codeHashOrWasm: Hash | Uint8Array | string);
|
|
10
8
|
get metadata(): ContractMetadata;
|
|
11
9
|
get registry(): TypinkRegistry;
|
|
12
10
|
get tx(): ContractApi['constructorTx'];
|
package/ContractDeployer.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { TypinkRegistry } from './TypinkRegistry.js';
|
|
2
2
|
import { ConstructorQueryExecutor } from './executor/ConstructorQueryExecutor.js';
|
|
3
3
|
import { ConstructorTxExecutor } from './executor/index.js';
|
|
4
|
-
import { newProxyChain,
|
|
5
|
-
import { parseRawMetadata } from './utils.js';
|
|
4
|
+
import { ensureSupportContractsPallet, newProxyChain, parseRawMetadata } from './utils.js';
|
|
6
5
|
export class ContractDeployer {
|
|
7
6
|
#api;
|
|
8
7
|
#metadata;
|
package/cjs/ContractDeployer.js
CHANGED
|
@@ -5,7 +5,6 @@ const TypinkRegistry_js_1 = require("./TypinkRegistry.js");
|
|
|
5
5
|
const ConstructorQueryExecutor_js_1 = require("./executor/ConstructorQueryExecutor.js");
|
|
6
6
|
const index_js_1 = require("./executor/index.js");
|
|
7
7
|
const utils_js_1 = require("./utils.js");
|
|
8
|
-
const utils_js_2 = require("./utils.js");
|
|
9
8
|
class ContractDeployer {
|
|
10
9
|
#api;
|
|
11
10
|
#metadata;
|
|
@@ -14,7 +13,7 @@ class ContractDeployer {
|
|
|
14
13
|
constructor(api, metadata, codeHashOrWasm) {
|
|
15
14
|
(0, utils_js_1.ensureSupportContractsPallet)(api);
|
|
16
15
|
this.#api = api;
|
|
17
|
-
this.#metadata = typeof metadata === 'string' ? (0,
|
|
16
|
+
this.#metadata = typeof metadata === 'string' ? (0, utils_js_1.parseRawMetadata)(metadata) : metadata;
|
|
18
17
|
this.#registry = new TypinkRegistry_js_1.TypinkRegistry(this.#metadata);
|
|
19
18
|
this.#code = codeHashOrWasm;
|
|
20
19
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConstructorQueryExecutor = void 0;
|
|
4
4
|
const utils_1 = require("@dedot/utils");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
class ConstructorQueryExecutor extends
|
|
5
|
+
const utils_js_1 = require("../utils.js");
|
|
6
|
+
const Executor_js_1 = require("./Executor.js");
|
|
7
|
+
class ConstructorQueryExecutor extends Executor_js_1.Executor {
|
|
8
8
|
code;
|
|
9
9
|
constructor(api, registry, code) {
|
|
10
10
|
super(api, registry);
|
|
@@ -32,7 +32,7 @@ class ConstructorQueryExecutor extends Executor_1.Executor {
|
|
|
32
32
|
return callFn;
|
|
33
33
|
}
|
|
34
34
|
#findConstructorMeta(constructor) {
|
|
35
|
-
return this.metadata.spec.constructors.find((one) => (0,
|
|
35
|
+
return this.metadata.spec.constructors.find((one) => (0, utils_js_1.normalizeLabel)(one.label) === constructor);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
exports.ConstructorQueryExecutor = ConstructorQueryExecutor;
|
|
@@ -16,17 +16,18 @@ class QueryExecutor extends Executor_js_1.Executor {
|
|
|
16
16
|
(0, utils_1.assert)(caller, 'Expected a valid caller address in ContractCallOptions');
|
|
17
17
|
const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
|
|
18
18
|
const bytes = (0, utils_1.u8aToHex)((0, utils_1.concatU8a)((0, utils_1.hexToU8a)(meta.selector), ...formattedInputs));
|
|
19
|
-
const
|
|
20
|
-
return
|
|
19
|
+
const raw = await this.api.call.contractsApi.call(caller, this.address, value, gasLimit, storageDepositLimit, bytes);
|
|
20
|
+
return (raw.result.isOk
|
|
21
21
|
? {
|
|
22
22
|
isOk: true,
|
|
23
|
-
data: this.tryDecode(meta,
|
|
24
|
-
|
|
23
|
+
data: this.tryDecode(meta, raw.result.value.data),
|
|
24
|
+
raw,
|
|
25
25
|
}
|
|
26
26
|
: {
|
|
27
27
|
isOk: false,
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
err: raw.result.err,
|
|
29
|
+
raw,
|
|
30
|
+
});
|
|
30
31
|
};
|
|
31
32
|
callFn.meta = meta;
|
|
32
33
|
return callFn;
|
package/cjs/utils.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.parseRawMetadata = exports.normalizeContractTypeDef = exports.extractContractTypes = void 0;
|
|
4
|
+
exports.newProxyChain = newProxyChain;
|
|
5
|
+
exports.ensureSupportContractsPallet = ensureSupportContractsPallet;
|
|
6
|
+
exports.normalizeLabel = normalizeLabel;
|
|
4
7
|
const utils_1 = require("@dedot/utils");
|
|
5
8
|
const extractContractTypes = (contractMetadata) => {
|
|
6
9
|
const { types } = contractMetadata;
|
|
@@ -90,7 +93,6 @@ function newProxyChain(carrier) {
|
|
|
90
93
|
},
|
|
91
94
|
});
|
|
92
95
|
}
|
|
93
|
-
exports.newProxyChain = newProxyChain;
|
|
94
96
|
function ensureSupportContractsPallet(api) {
|
|
95
97
|
try {
|
|
96
98
|
!!api.call.contractsApi.call.meta && !!api.tx.contracts.call.meta;
|
|
@@ -99,10 +101,8 @@ function ensureSupportContractsPallet(api) {
|
|
|
99
101
|
throw new Error('Contracts pallet is not available');
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
|
-
exports.ensureSupportContractsPallet = ensureSupportContractsPallet;
|
|
103
104
|
function normalizeLabel(label) {
|
|
104
105
|
if (!label)
|
|
105
106
|
return '';
|
|
106
107
|
return (0, utils_1.stringCamelCase)(label.replaceAll('::', '_'));
|
|
107
108
|
}
|
|
108
|
-
exports.normalizeLabel = normalizeLabel;
|
|
@@ -2,9 +2,9 @@ import { ISubstrateClient } from '@dedot/api';
|
|
|
2
2
|
import { Hash } from '@dedot/codecs';
|
|
3
3
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
4
4
|
import { HexString } from '@dedot/utils';
|
|
5
|
-
import { TypinkRegistry } from '../TypinkRegistry';
|
|
5
|
+
import { TypinkRegistry } from '../TypinkRegistry.js';
|
|
6
6
|
import { GenericConstructorQueryCall } from '../types/index.js';
|
|
7
|
-
import { Executor } from './Executor';
|
|
7
|
+
import { Executor } from './Executor.js';
|
|
8
8
|
export declare class ConstructorQueryExecutor<ChainApi extends GenericSubstrateApi> extends Executor<ChainApi> {
|
|
9
9
|
#private;
|
|
10
10
|
protected readonly code: Hash | Uint8Array | HexString | string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assert, concatU8a, hexToU8a, isWasm, u8aToHex } from '@dedot/utils';
|
|
2
|
-
import { normalizeLabel } from '../utils';
|
|
3
|
-
import { Executor } from './Executor';
|
|
2
|
+
import { normalizeLabel } from '../utils.js';
|
|
3
|
+
import { Executor } from './Executor.js';
|
|
4
4
|
export class ConstructorQueryExecutor extends Executor {
|
|
5
5
|
code;
|
|
6
6
|
constructor(api, registry, code) {
|
|
@@ -13,17 +13,18 @@ export class QueryExecutor extends Executor {
|
|
|
13
13
|
assert(caller, 'Expected a valid caller address in ContractCallOptions');
|
|
14
14
|
const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
|
|
15
15
|
const bytes = u8aToHex(concatU8a(hexToU8a(meta.selector), ...formattedInputs));
|
|
16
|
-
const
|
|
17
|
-
return
|
|
16
|
+
const raw = await this.api.call.contractsApi.call(caller, this.address, value, gasLimit, storageDepositLimit, bytes);
|
|
17
|
+
return (raw.result.isOk
|
|
18
18
|
? {
|
|
19
19
|
isOk: true,
|
|
20
|
-
data: this.tryDecode(meta,
|
|
21
|
-
|
|
20
|
+
data: this.tryDecode(meta, raw.result.value.data),
|
|
21
|
+
raw,
|
|
22
22
|
}
|
|
23
23
|
: {
|
|
24
24
|
isOk: false,
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
err: raw.result.err,
|
|
26
|
+
raw,
|
|
27
|
+
});
|
|
27
28
|
};
|
|
28
29
|
callFn.meta = meta;
|
|
29
30
|
return callFn;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/contracts",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.a5b1d2fb.22+a5b1d2f",
|
|
4
4
|
"description": "Delightful ink! Contract APIs",
|
|
5
5
|
"author": "Tung Vu <tung@coongcrafts.io>",
|
|
6
6
|
"main": "./cjs/index.js",
|
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
"test": "vitest --watch=false"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@dedot/api": "0.0.1-next.
|
|
16
|
-
"@dedot/codecs": "0.0.1-next.
|
|
17
|
-
"@dedot/types": "0.0.1-next.
|
|
18
|
-
"@dedot/utils": "0.0.1-next.
|
|
15
|
+
"@dedot/api": "0.0.1-next.a5b1d2fb.22+a5b1d2f",
|
|
16
|
+
"@dedot/codecs": "0.0.1-next.a5b1d2fb.22+a5b1d2f",
|
|
17
|
+
"@dedot/types": "0.0.1-next.a5b1d2fb.22+a5b1d2f",
|
|
18
|
+
"@dedot/utils": "0.0.1-next.a5b1d2fb.22+a5b1d2f"
|
|
19
19
|
},
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"access": "public",
|
|
22
22
|
"directory": "dist"
|
|
23
23
|
},
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "a5b1d2fbb14107e2e5bb9de229b2707d814a02e5",
|
|
26
26
|
"module": "./index.js",
|
|
27
27
|
"types": "./index.d.ts",
|
|
28
28
|
"exports": {
|
package/types/index.d.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { SubstrateApi } from '@dedot/api/chaintypes';
|
|
2
|
-
import { AccountId32Like, BytesLike, Weight } from '@dedot/codecs';
|
|
3
|
-
import { AnyFunc, AsyncMethod, GenericSubstrateApi, RpcVersion } from '@dedot/types';
|
|
2
|
+
import { AccountId32Like, BytesLike, DispatchError, Weight } from '@dedot/codecs';
|
|
3
|
+
import { AnyFunc, AsyncMethod, GenericSubstrateApi, RpcVersion, VersionedGenericSubstrateApi } from '@dedot/types';
|
|
4
4
|
import { ContractConstructorMessage, ContractMessage } from './shared.js';
|
|
5
5
|
import { ContractMetadataV4 } from './v4.js';
|
|
6
6
|
import { ContractMetadataV5 } from './v5.js';
|
|
7
7
|
export * from './shared.js';
|
|
8
|
-
export type GenericContractCallResult<DecodedData, ContractResult> = {
|
|
8
|
+
export type GenericContractCallResult<DecodedData, ContractResult> = ({
|
|
9
9
|
isOk: true;
|
|
10
10
|
data: DecodedData;
|
|
11
|
-
rawResult: ContractResult;
|
|
12
11
|
} | {
|
|
13
12
|
isOk: false;
|
|
14
|
-
|
|
13
|
+
err: DispatchError;
|
|
14
|
+
}) & {
|
|
15
|
+
raw: ContractResult;
|
|
15
16
|
};
|
|
16
|
-
export type
|
|
17
|
-
export type
|
|
18
|
-
export type
|
|
17
|
+
export type ContractCallResult<ChainApi extends GenericSubstrateApi> = Awaited<ReturnType<ChainApi['call']['contractsApi']['call']>>;
|
|
18
|
+
export type ContractInstantiateResult<ChainApi extends GenericSubstrateApi> = Awaited<ReturnType<ChainApi['call']['contractsApi']['instantiate']>>;
|
|
19
|
+
export type ContractSubmittableExtrinsic<ChainApi extends GenericSubstrateApi> = ReturnType<ChainApi['tx']['contracts']['call']>;
|
|
19
20
|
export type InstantiateWithCodeSubmittableExtrinsic<ChainApi extends GenericSubstrateApi> = ReturnType<ChainApi['tx']['contracts']['instantiateWithCode']>;
|
|
20
21
|
export type InstantiateSubmittableExtrinsic<ChainApi extends GenericSubstrateApi> = ReturnType<ChainApi['tx']['contracts']['instantiate']>;
|
|
21
|
-
export type
|
|
22
|
+
export type GenericInstantiateSubmittableExtrinsic<ChainApi extends GenericSubstrateApi> = InstantiateSubmittableExtrinsic<ChainApi> | InstantiateWithCodeSubmittableExtrinsic<ChainApi>;
|
|
22
23
|
export type ContractMetadata = ContractMetadataV4 | ContractMetadataV5;
|
|
23
24
|
export type CallOptions = {
|
|
24
25
|
value?: bigint;
|
|
@@ -39,16 +40,16 @@ export type ContractCallOptions = CallOptions & {
|
|
|
39
40
|
export type ContractTxOptions = CallOptions & {
|
|
40
41
|
gasLimit: Weight;
|
|
41
42
|
};
|
|
42
|
-
export type GenericContractQueryCall<ChainApi extends GenericSubstrateApi, F extends AsyncMethod = (...args: any[]) => Promise<GenericContractCallResult<
|
|
43
|
+
export type GenericContractQueryCall<ChainApi extends GenericSubstrateApi, F extends AsyncMethod = (...args: any[]) => Promise<GenericContractCallResult<any, ContractCallResult<ChainApi>>>> = F & {
|
|
43
44
|
meta: ContractMessage;
|
|
44
45
|
};
|
|
45
|
-
export type GenericContractTxCall<ChainApi extends GenericSubstrateApi, F extends AnyFunc = (...args: any[]) =>
|
|
46
|
+
export type GenericContractTxCall<ChainApi extends GenericSubstrateApi, F extends AnyFunc = (...args: any[]) => ContractSubmittableExtrinsic<ChainApi>> = F & {
|
|
46
47
|
meta: ContractMessage;
|
|
47
48
|
};
|
|
48
|
-
export type GenericConstructorQueryCall<ChainApi extends GenericSubstrateApi, F extends AsyncMethod = (...args: any[]) => Promise<
|
|
49
|
+
export type GenericConstructorQueryCall<ChainApi extends GenericSubstrateApi, F extends AsyncMethod = (...args: any[]) => Promise<ContractInstantiateResult<ChainApi>>> = F & {
|
|
49
50
|
meta: ContractConstructorMessage;
|
|
50
51
|
};
|
|
51
|
-
export type GenericConstructorTxCall<ChainApi extends GenericSubstrateApi, F extends AnyFunc = (...args: any[]) =>
|
|
52
|
+
export type GenericConstructorTxCall<ChainApi extends GenericSubstrateApi, F extends AnyFunc = (...args: any[]) => GenericInstantiateSubmittableExtrinsic<ChainApi>> = F & {
|
|
52
53
|
meta: ContractConstructorMessage;
|
|
53
54
|
};
|
|
54
55
|
export interface GenericContractQuery<ChainApi extends GenericSubstrateApi> {
|
|
@@ -63,9 +64,9 @@ export interface GenericConstructorQuery<ChainApi extends GenericSubstrateApi> {
|
|
|
63
64
|
export interface GenericConstructorTx<ChainApi extends GenericSubstrateApi> {
|
|
64
65
|
[method: string]: GenericConstructorTxCall<ChainApi>;
|
|
65
66
|
}
|
|
66
|
-
export interface GenericContractApi<ChainApi extends
|
|
67
|
-
query: GenericContractQuery<ChainApi>;
|
|
68
|
-
tx: GenericContractTx<ChainApi>;
|
|
69
|
-
constructorQuery: GenericConstructorQuery<ChainApi>;
|
|
70
|
-
constructorTx: GenericConstructorTx<ChainApi>;
|
|
67
|
+
export interface GenericContractApi<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> {
|
|
68
|
+
query: GenericContractQuery<ChainApi[RpcVersion]>;
|
|
69
|
+
tx: GenericContractTx<ChainApi[RpcVersion]>;
|
|
70
|
+
constructorQuery: GenericConstructorQuery<ChainApi[RpcVersion]>;
|
|
71
|
+
constructorTx: GenericConstructorTx<ChainApi[RpcVersion]>;
|
|
71
72
|
}
|
package/types/shared.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export interface ContractSource {
|
|
|
3
3
|
wasm?: string;
|
|
4
4
|
language: string;
|
|
5
5
|
compiler: string;
|
|
6
|
-
|
|
6
|
+
build_info: BuildInfo;
|
|
7
7
|
}
|
|
8
8
|
export interface ContractInformation {
|
|
9
9
|
name: string;
|
|
@@ -11,14 +11,14 @@ export interface ContractInformation {
|
|
|
11
11
|
authors: string[];
|
|
12
12
|
}
|
|
13
13
|
export interface BuildInfo {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
build_mode: string;
|
|
15
|
+
cargo_contract_version: string;
|
|
16
|
+
rust_toolchain: string;
|
|
17
|
+
wasm_opt_settings: WasmOptSettings;
|
|
18
18
|
}
|
|
19
19
|
export interface WasmOptSettings {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
keep_debug_symbols: boolean;
|
|
21
|
+
optimization_passes: string;
|
|
22
22
|
}
|
|
23
23
|
export interface ContractMessageArg {
|
|
24
24
|
label: string;
|
package/types/v4.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface ContractSpecV4 {
|
|
|
12
12
|
docs: string[];
|
|
13
13
|
environment: ContractEnvironmentV4;
|
|
14
14
|
events: ContractEventV4[];
|
|
15
|
-
|
|
15
|
+
lang_error: ContractTypeInfo;
|
|
16
16
|
messages: ContractMessage[];
|
|
17
17
|
}
|
|
18
18
|
export interface ContractEventV4 {
|