@dedot/contracts 0.0.1-alpha.34 → 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 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, ChainApi extends GenericSubstrateApi = SubstrateApi[RpcVersion]> {
5
+ export declare class Contract<ContractApi extends GenericContractApi = GenericContractApi> {
8
6
  #private;
9
- constructor(api: ISubstrateClient<ChainApi>, address: AccountId32Like, metadata: ContractMetadata | string);
7
+ constructor(api: ISubstrateClient, address: AccountId32Like, metadata: ContractMetadata | string);
10
8
  get metadata(): ContractMetadata;
11
9
  get address(): AccountId32;
12
10
  get registry(): TypinkRegistry;
@@ -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, ChainApi extends GenericSubstrateApi = SubstrateApi[RpcVersion]> {
5
+ export declare class ContractDeployer<ContractApi extends GenericContractApi = GenericContractApi> {
8
6
  #private;
9
- constructor(api: ISubstrateClient<ChainApi>, metadata: ContractMetadata | string, codeHashOrWasm: Hash | Uint8Array | string);
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'];
@@ -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, ensureSupportContractsPallet } from './utils.js';
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;
@@ -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, utils_js_2.parseRawMetadata)(metadata) : metadata;
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,16 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConstructorQueryExecutor = void 0;
4
4
  const utils_1 = require("@dedot/utils");
5
- const ConstructorTxExecutor_js_1 = require("./ConstructorTxExecutor.js");
6
- class ConstructorQueryExecutor extends ConstructorTxExecutor_js_1.ConstructorTxExecutor {
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
+ code;
9
+ constructor(api, registry, code) {
10
+ super(api, registry);
11
+ this.code = code;
12
+ }
7
13
  doExecute(constructor) {
8
- const meta = this.findConstructorMeta(constructor);
14
+ const meta = this.#findConstructorMeta(constructor);
9
15
  (0, utils_1.assert)(meta, `Constructor message not found: ${constructor}`);
10
16
  const callFn = (...params) => {
11
- // TODO verify number of arguments/params & call options presence
12
17
  const { args } = meta;
18
+ (0, utils_1.assert)(params.length === args.length + 1, `Expected ${args.length + 1} arguments, got ${params.length}`);
13
19
  const callOptions = params[args.length];
14
20
  const { caller, value = 0n, gasLimit, storageDepositLimit, salt } = callOptions;
21
+ (0, utils_1.assert)(caller, 'Expected a valid caller address in ConstructorCallOptions');
22
+ (0, utils_1.assert)(salt, 'Expected a salt in ConstructorCallOptions');
15
23
  const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
16
24
  const bytes = (0, utils_1.u8aToHex)((0, utils_1.concatU8a)((0, utils_1.hexToU8a)(meta.selector), ...formattedInputs));
17
25
  const code = {
@@ -23,5 +31,8 @@ class ConstructorQueryExecutor extends ConstructorTxExecutor_js_1.ConstructorTxE
23
31
  callFn.meta = meta;
24
32
  return callFn;
25
33
  }
34
+ #findConstructorMeta(constructor) {
35
+ return this.metadata.spec.constructors.find((one) => (0, utils_js_1.normalizeLabel)(one.label) === constructor);
36
+ }
26
37
  }
27
38
  exports.ConstructorQueryExecutor = ConstructorQueryExecutor;
@@ -11,13 +11,15 @@ class ConstructorTxExecutor extends Executor_js_1.Executor {
11
11
  this.code = code;
12
12
  }
13
13
  doExecute(constructor) {
14
- const meta = this.findConstructorMeta(constructor);
14
+ const meta = this.#findConstructorMeta(constructor);
15
15
  (0, utils_1.assert)(meta, `Constructor message not found: ${constructor}`);
16
16
  const callFn = (...params) => {
17
- // TODO verify number of arguments/params & call options presence
18
17
  const { args } = meta;
18
+ (0, utils_1.assert)(params.length === args.length + 1, `Expected ${args.length + 1} arguments, got ${params.length}`);
19
19
  const txCallOptions = params[args.length];
20
20
  const { value = 0n, gasLimit, storageDepositLimit, salt } = txCallOptions;
21
+ (0, utils_1.assert)(gasLimit, 'Expected a gas limit in ConstructorTxOptions');
22
+ (0, utils_1.assert)(salt, 'Expected a salt in ConstructorTxOptions');
21
23
  const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
22
24
  const bytes = (0, utils_1.u8aToHex)((0, utils_1.concatU8a)((0, utils_1.hexToU8a)(meta.selector), ...formattedInputs));
23
25
  if ((0, utils_1.isWasm)(this.code)) {
@@ -30,7 +32,7 @@ class ConstructorTxExecutor extends Executor_js_1.Executor {
30
32
  callFn.meta = meta;
31
33
  return callFn;
32
34
  }
33
- findConstructorMeta(constructor) {
35
+ #findConstructorMeta(constructor) {
34
36
  return this.metadata.spec.constructors.find((one) => (0, utils_js_1.normalizeLabel)(one.label) === constructor);
35
37
  }
36
38
  }
@@ -6,32 +6,33 @@ const utils_js_1 = require("../utils.js");
6
6
  const Executor_js_1 = require("./Executor.js");
7
7
  class QueryExecutor extends Executor_js_1.Executor {
8
8
  doExecute(message) {
9
- const meta = this.findMessage(message);
9
+ const meta = this.#findMessage(message);
10
10
  (0, utils_1.assert)(meta, `Query message not found: ${message}`);
11
11
  const callFn = async (...params) => {
12
- // TODO verify number of arguments/params & call options presence
13
12
  const { args } = meta;
13
+ (0, utils_1.assert)(params.length === args.length + 1, `Expected ${args.length + 1} arguments, got ${params.length}`);
14
14
  const callOptions = params[args.length];
15
15
  const { caller, value = 0n, gasLimit, storageDepositLimit } = callOptions;
16
+ (0, utils_1.assert)(caller, 'Expected a valid caller address in ContractCallOptions');
16
17
  const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
17
18
  const bytes = (0, utils_1.u8aToHex)((0, utils_1.concatU8a)((0, utils_1.hexToU8a)(meta.selector), ...formattedInputs));
18
- const contractResult = await this.api.call.contractsApi.call(caller, this.address, value, gasLimit, storageDepositLimit, bytes);
19
- if (contractResult.result.isOk) {
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
  isOk: true,
22
- data: this.tryDecode(meta, contractResult.result.value.data),
23
- contractResult: contractResult,
24
- };
25
- }
26
- return {
27
- isOk: false,
28
- contractResult: contractResult,
29
- };
23
+ data: this.tryDecode(meta, raw.result.value.data),
24
+ raw,
25
+ }
26
+ : {
27
+ isOk: false,
28
+ err: raw.result.err,
29
+ raw,
30
+ });
30
31
  };
31
32
  callFn.meta = meta;
32
33
  return callFn;
33
34
  }
34
- findMessage(message) {
35
+ #findMessage(message) {
35
36
  return this.metadata.spec.messages.find((one) => (0, utils_js_1.normalizeLabel)(one.label) === message);
36
37
  }
37
38
  }
@@ -6,13 +6,14 @@ const utils_js_1 = require("../utils.js");
6
6
  const Executor_js_1 = require("./Executor.js");
7
7
  class TxExecutor extends Executor_js_1.Executor {
8
8
  doExecute(message) {
9
- const meta = this.findTxMessage(message);
9
+ const meta = this.#findTxMessage(message);
10
10
  (0, utils_1.assert)(meta, `Tx message not found: ${message}`);
11
11
  const callFn = (...params) => {
12
- // TODO verify number of arguments/params & call options presence
13
12
  const { args } = meta;
13
+ (0, utils_1.assert)(params.length === args.length + 1, `Expected ${args.length + 1} arguments, got ${params.length}`);
14
14
  const txCallOptions = params[args.length];
15
15
  const { value = 0n, gasLimit, storageDepositLimit } = txCallOptions;
16
+ (0, utils_1.assert)(gasLimit, 'Expected a gas limit in ContractTxOptions');
16
17
  const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
17
18
  const bytes = (0, utils_1.u8aToHex)((0, utils_1.concatU8a)((0, utils_1.hexToU8a)(meta.selector), ...formattedInputs));
18
19
  return this.api.tx.contracts.call(this.address, value, gasLimit, storageDepositLimit, bytes);
@@ -20,7 +21,7 @@ class TxExecutor extends Executor_js_1.Executor {
20
21
  callFn.meta = meta;
21
22
  return callFn;
22
23
  }
23
- findTxMessage(message) {
24
+ #findTxMessage(message) {
24
25
  return this.metadata.spec.messages.find((one) => one.mutates && (0, utils_js_1.normalizeLabel)(one.label) === message);
25
26
  }
26
27
  }
package/cjs/utils.js CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeLabel = exports.ensureSupportContractsPallet = exports.newProxyChain = exports.parseRawMetadata = exports.normalizeContractTypeDef = exports.extractContractTypes = void 0;
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;
@@ -1,6 +1,13 @@
1
+ import { ISubstrateClient } from '@dedot/api';
2
+ import { Hash } from '@dedot/codecs';
1
3
  import { GenericSubstrateApi } from '@dedot/types';
4
+ import { HexString } from '@dedot/utils';
5
+ import { TypinkRegistry } from '../TypinkRegistry.js';
2
6
  import { GenericConstructorQueryCall } from '../types/index.js';
3
- import { ConstructorTxExecutor } from './ConstructorTxExecutor.js';
4
- export declare class ConstructorQueryExecutor<ChainApi extends GenericSubstrateApi> extends ConstructorTxExecutor<ChainApi> {
7
+ import { Executor } from './Executor.js';
8
+ export declare class ConstructorQueryExecutor<ChainApi extends GenericSubstrateApi> extends Executor<ChainApi> {
9
+ #private;
10
+ protected readonly code: Hash | Uint8Array | HexString | string;
11
+ constructor(api: ISubstrateClient<ChainApi>, registry: TypinkRegistry, code: Hash | Uint8Array | string);
5
12
  doExecute(constructor: string): GenericConstructorQueryCall<ChainApi>;
6
13
  }
@@ -1,14 +1,22 @@
1
1
  import { assert, concatU8a, hexToU8a, isWasm, u8aToHex } from '@dedot/utils';
2
- import { ConstructorTxExecutor } from './ConstructorTxExecutor.js';
3
- export class ConstructorQueryExecutor extends ConstructorTxExecutor {
2
+ import { normalizeLabel } from '../utils.js';
3
+ import { Executor } from './Executor.js';
4
+ export class ConstructorQueryExecutor extends Executor {
5
+ code;
6
+ constructor(api, registry, code) {
7
+ super(api, registry);
8
+ this.code = code;
9
+ }
4
10
  doExecute(constructor) {
5
- const meta = this.findConstructorMeta(constructor);
11
+ const meta = this.#findConstructorMeta(constructor);
6
12
  assert(meta, `Constructor message not found: ${constructor}`);
7
13
  const callFn = (...params) => {
8
- // TODO verify number of arguments/params & call options presence
9
14
  const { args } = meta;
15
+ assert(params.length === args.length + 1, `Expected ${args.length + 1} arguments, got ${params.length}`);
10
16
  const callOptions = params[args.length];
11
17
  const { caller, value = 0n, gasLimit, storageDepositLimit, salt } = callOptions;
18
+ assert(caller, 'Expected a valid caller address in ConstructorCallOptions');
19
+ assert(salt, 'Expected a salt in ConstructorCallOptions');
12
20
  const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
13
21
  const bytes = u8aToHex(concatU8a(hexToU8a(meta.selector), ...formattedInputs));
14
22
  const code = {
@@ -20,4 +28,7 @@ export class ConstructorQueryExecutor extends ConstructorTxExecutor {
20
28
  callFn.meta = meta;
21
29
  return callFn;
22
30
  }
31
+ #findConstructorMeta(constructor) {
32
+ return this.metadata.spec.constructors.find((one) => normalizeLabel(one.label) === constructor);
33
+ }
23
34
  }
@@ -3,11 +3,11 @@ import { Hash } from '@dedot/codecs';
3
3
  import { GenericSubstrateApi } from '@dedot/types';
4
4
  import { HexString } from '@dedot/utils';
5
5
  import { TypinkRegistry } from '../TypinkRegistry.js';
6
- import { ContractConstructorMessage, GenericConstructorTxCall } from '../types/index.js';
6
+ import { GenericConstructorTxCall } from '../types/index.js';
7
7
  import { Executor } from './Executor.js';
8
8
  export declare class ConstructorTxExecutor<ChainApi extends GenericSubstrateApi> extends Executor<ChainApi> {
9
+ #private;
9
10
  protected readonly code: Hash | Uint8Array | HexString | string;
10
11
  constructor(api: ISubstrateClient<ChainApi>, registry: TypinkRegistry, code: Hash | Uint8Array | string);
11
12
  doExecute(constructor: string): GenericConstructorTxCall<ChainApi>;
12
- protected findConstructorMeta(constructor: string): ContractConstructorMessage | undefined;
13
13
  }
@@ -8,13 +8,15 @@ export class ConstructorTxExecutor extends Executor {
8
8
  this.code = code;
9
9
  }
10
10
  doExecute(constructor) {
11
- const meta = this.findConstructorMeta(constructor);
11
+ const meta = this.#findConstructorMeta(constructor);
12
12
  assert(meta, `Constructor message not found: ${constructor}`);
13
13
  const callFn = (...params) => {
14
- // TODO verify number of arguments/params & call options presence
15
14
  const { args } = meta;
15
+ assert(params.length === args.length + 1, `Expected ${args.length + 1} arguments, got ${params.length}`);
16
16
  const txCallOptions = params[args.length];
17
17
  const { value = 0n, gasLimit, storageDepositLimit, salt } = txCallOptions;
18
+ assert(gasLimit, 'Expected a gas limit in ConstructorTxOptions');
19
+ assert(salt, 'Expected a salt in ConstructorTxOptions');
18
20
  const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
19
21
  const bytes = u8aToHex(concatU8a(hexToU8a(meta.selector), ...formattedInputs));
20
22
  if (isWasm(this.code)) {
@@ -27,7 +29,7 @@ export class ConstructorTxExecutor extends Executor {
27
29
  callFn.meta = meta;
28
30
  return callFn;
29
31
  }
30
- findConstructorMeta(constructor) {
32
+ #findConstructorMeta(constructor) {
31
33
  return this.metadata.spec.constructors.find((one) => normalizeLabel(one.label) === constructor);
32
34
  }
33
35
  }
@@ -1,7 +1,7 @@
1
1
  import { GenericSubstrateApi } from '@dedot/types';
2
- import { ContractMessage, GenericContractQueryCall } from '../types/index.js';
2
+ import { GenericContractQueryCall } from '../types/index.js';
3
3
  import { Executor } from './Executor.js';
4
4
  export declare class QueryExecutor<ChainApi extends GenericSubstrateApi> extends Executor<ChainApi> {
5
+ #private;
5
6
  doExecute(message: string): GenericContractQueryCall<ChainApi>;
6
- protected findMessage(message: string): ContractMessage | undefined;
7
7
  }
@@ -3,32 +3,33 @@ import { normalizeLabel } from '../utils.js';
3
3
  import { Executor } from './Executor.js';
4
4
  export class QueryExecutor extends Executor {
5
5
  doExecute(message) {
6
- const meta = this.findMessage(message);
6
+ const meta = this.#findMessage(message);
7
7
  assert(meta, `Query message not found: ${message}`);
8
8
  const callFn = async (...params) => {
9
- // TODO verify number of arguments/params & call options presence
10
9
  const { args } = meta;
10
+ assert(params.length === args.length + 1, `Expected ${args.length + 1} arguments, got ${params.length}`);
11
11
  const callOptions = params[args.length];
12
12
  const { caller, value = 0n, gasLimit, storageDepositLimit } = callOptions;
13
+ assert(caller, 'Expected a valid caller address in ContractCallOptions');
13
14
  const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
14
15
  const bytes = u8aToHex(concatU8a(hexToU8a(meta.selector), ...formattedInputs));
15
- const contractResult = await this.api.call.contractsApi.call(caller, this.address, value, gasLimit, storageDepositLimit, bytes);
16
- if (contractResult.result.isOk) {
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
  isOk: true,
19
- data: this.tryDecode(meta, contractResult.result.value.data),
20
- contractResult: contractResult,
21
- };
22
- }
23
- return {
24
- isOk: false,
25
- contractResult: contractResult,
26
- };
20
+ data: this.tryDecode(meta, raw.result.value.data),
21
+ raw,
22
+ }
23
+ : {
24
+ isOk: false,
25
+ err: raw.result.err,
26
+ raw,
27
+ });
27
28
  };
28
29
  callFn.meta = meta;
29
30
  return callFn;
30
31
  }
31
- findMessage(message) {
32
+ #findMessage(message) {
32
33
  return this.metadata.spec.messages.find((one) => normalizeLabel(one.label) === message);
33
34
  }
34
35
  }
@@ -1,7 +1,7 @@
1
1
  import { GenericSubstrateApi } from '@dedot/types';
2
- import { ContractMessage, GenericContractTxCall } from '../types/index.js';
2
+ import { GenericContractTxCall } from '../types/index.js';
3
3
  import { Executor } from './Executor.js';
4
4
  export declare class TxExecutor<ChainApi extends GenericSubstrateApi> extends Executor<ChainApi> {
5
+ #private;
5
6
  doExecute(message: string): GenericContractTxCall<ChainApi>;
6
- protected findTxMessage(message: string): ContractMessage | undefined;
7
7
  }
@@ -3,13 +3,14 @@ import { normalizeLabel } from '../utils.js';
3
3
  import { Executor } from './Executor.js';
4
4
  export class TxExecutor extends Executor {
5
5
  doExecute(message) {
6
- const meta = this.findTxMessage(message);
6
+ const meta = this.#findTxMessage(message);
7
7
  assert(meta, `Tx message not found: ${message}`);
8
8
  const callFn = (...params) => {
9
- // TODO verify number of arguments/params & call options presence
10
9
  const { args } = meta;
10
+ assert(params.length === args.length + 1, `Expected ${args.length + 1} arguments, got ${params.length}`);
11
11
  const txCallOptions = params[args.length];
12
12
  const { value = 0n, gasLimit, storageDepositLimit } = txCallOptions;
13
+ assert(gasLimit, 'Expected a gas limit in ContractTxOptions');
13
14
  const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
14
15
  const bytes = u8aToHex(concatU8a(hexToU8a(meta.selector), ...formattedInputs));
15
16
  return this.api.tx.contracts.call(this.address, value, gasLimit, storageDepositLimit, bytes);
@@ -17,7 +18,7 @@ export class TxExecutor extends Executor {
17
18
  callFn.meta = meta;
18
19
  return callFn;
19
20
  }
20
- findTxMessage(message) {
21
+ #findTxMessage(message) {
21
22
  return this.metadata.spec.messages.find((one) => one.mutates && normalizeLabel(one.label) === message);
22
23
  }
23
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/contracts",
3
- "version": "0.0.1-alpha.34",
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-alpha.34",
16
- "@dedot/codecs": "0.0.1-alpha.34",
17
- "@dedot/types": "0.0.1-alpha.34",
18
- "@dedot/utils": "0.0.1-alpha.34"
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": "053078f3aed79a3044314421967325b9fe0e6f57",
25
+ "gitHead": "a5b1d2fbb14107e2e5bb9de229b2707d814a02e5",
26
26
  "module": "./index.js",
27
27
  "types": "./index.d.ts",
28
28
  "exports": {
package/types/index.d.ts CHANGED
@@ -1,10 +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> = ({
9
+ isOk: true;
10
+ data: DecodedData;
11
+ } | {
12
+ isOk: false;
13
+ err: DispatchError;
14
+ }) & {
15
+ raw: ContractResult;
16
+ };
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']>;
20
+ export type InstantiateWithCodeSubmittableExtrinsic<ChainApi extends GenericSubstrateApi> = ReturnType<ChainApi['tx']['contracts']['instantiateWithCode']>;
21
+ export type InstantiateSubmittableExtrinsic<ChainApi extends GenericSubstrateApi> = ReturnType<ChainApi['tx']['contracts']['instantiate']>;
22
+ export type GenericInstantiateSubmittableExtrinsic<ChainApi extends GenericSubstrateApi> = InstantiateSubmittableExtrinsic<ChainApi> | InstantiateWithCodeSubmittableExtrinsic<ChainApi>;
8
23
  export type ContractMetadata = ContractMetadataV4 | ContractMetadataV5;
9
24
  export type CallOptions = {
10
25
  value?: bigint;
@@ -25,16 +40,16 @@ export type ContractCallOptions = CallOptions & {
25
40
  export type ContractTxOptions = CallOptions & {
26
41
  gasLimit: Weight;
27
42
  };
28
- export type GenericContractQueryCall<_ extends GenericSubstrateApi, F extends AsyncMethod = AsyncMethod> = F & {
43
+ export type GenericContractQueryCall<ChainApi extends GenericSubstrateApi, F extends AsyncMethod = (...args: any[]) => Promise<GenericContractCallResult<any, ContractCallResult<ChainApi>>>> = F & {
29
44
  meta: ContractMessage;
30
45
  };
31
- export type GenericContractTxCall<_ extends GenericSubstrateApi, F extends AnyFunc = AnyFunc> = F & {
46
+ export type GenericContractTxCall<ChainApi extends GenericSubstrateApi, F extends AnyFunc = (...args: any[]) => ContractSubmittableExtrinsic<ChainApi>> = F & {
32
47
  meta: ContractMessage;
33
48
  };
34
- export type GenericConstructorQueryCall<_ extends GenericSubstrateApi, F extends AsyncMethod = AsyncMethod> = F & {
49
+ export type GenericConstructorQueryCall<ChainApi extends GenericSubstrateApi, F extends AsyncMethod = (...args: any[]) => Promise<ContractInstantiateResult<ChainApi>>> = F & {
35
50
  meta: ContractConstructorMessage;
36
51
  };
37
- export type GenericConstructorTxCall<_ extends GenericSubstrateApi, F extends AnyFunc = AnyFunc> = F & {
52
+ export type GenericConstructorTxCall<ChainApi extends GenericSubstrateApi, F extends AnyFunc = (...args: any[]) => GenericInstantiateSubmittableExtrinsic<ChainApi>> = F & {
38
53
  meta: ContractConstructorMessage;
39
54
  };
40
55
  export interface GenericContractQuery<ChainApi extends GenericSubstrateApi> {
@@ -49,9 +64,9 @@ export interface GenericConstructorQuery<ChainApi extends GenericSubstrateApi> {
49
64
  export interface GenericConstructorTx<ChainApi extends GenericSubstrateApi> {
50
65
  [method: string]: GenericConstructorTxCall<ChainApi>;
51
66
  }
52
- export interface GenericContractApi<ChainApi extends GenericSubstrateApi = SubstrateApi[RpcVersion]> {
53
- query: GenericContractQuery<ChainApi>;
54
- tx: GenericContractTx<ChainApi>;
55
- constructorQuery: GenericConstructorQuery<ChainApi>;
56
- 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]>;
57
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
- buildInfo: BuildInfo;
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
- buildMode: string;
15
- cargoContractVersion: string;
16
- rustToolchain: string;
17
- wasmOptSettings: WasmOptSettings;
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
- keepDebugSymbols: boolean;
21
- optimizationPasses: string;
20
+ keep_debug_symbols: boolean;
21
+ optimization_passes: string;
22
22
  }
23
23
  export interface ContractMessageArg {
24
24
  label: string;
@@ -28,7 +28,7 @@ export interface ContractTypeInfo {
28
28
  displayName: string[];
29
29
  type: number;
30
30
  }
31
- export interface ContractConstructorMessage {
31
+ export interface Message {
32
32
  args: ContractMessageArg[];
33
33
  default: boolean;
34
34
  docs: string[];
@@ -37,15 +37,10 @@ export interface ContractConstructorMessage {
37
37
  returnType: ContractTypeInfo;
38
38
  selector: string;
39
39
  }
40
- export interface ContractMessage {
41
- args: ContractMessageArg[];
42
- default: boolean;
43
- docs: string[];
44
- label: string;
40
+ export interface ContractConstructorMessage extends Message {
41
+ }
42
+ export interface ContractMessage extends Message {
45
43
  mutates: boolean;
46
- payable: boolean;
47
- returnType: ContractTypeInfo;
48
- selector: string;
49
44
  }
50
45
  export interface ContractType {
51
46
  id: number;
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
- langError: ContractTypeInfo;
15
+ lang_error: ContractTypeInfo;
16
16
  messages: ContractMessage[];
17
17
  }
18
18
  export interface ContractEventV4 {