@dedot/contracts 0.5.0 → 0.6.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/Contract.d.ts +3 -2
- package/Contract.js +9 -4
- package/ContractDeployer.d.ts +3 -2
- package/ContractDeployer.js +8 -3
- package/cjs/Contract.js +9 -4
- package/cjs/ContractDeployer.js +8 -3
- package/cjs/executor/ConstructorQueryExecutor.js +7 -14
- package/cjs/executor/ConstructorTxExecutor.js +3 -12
- package/cjs/executor/EventExecutor.js +11 -2
- package/cjs/executor/QueryExecutor.js +7 -9
- package/cjs/executor/TxExecutor.js +3 -7
- package/cjs/executor/abstract/ContractExecutor.js +20 -0
- package/cjs/executor/abstract/DeployerExecutor.js +16 -0
- package/cjs/executor/{Executor.js → abstract/Executor.js} +3 -9
- package/cjs/executor/abstract/index.js +19 -0
- package/cjs/executor/index.js +1 -1
- package/executor/ConstructorQueryExecutor.d.ts +2 -9
- package/executor/ConstructorQueryExecutor.js +9 -16
- package/executor/ConstructorTxExecutor.d.ts +2 -9
- package/executor/ConstructorTxExecutor.js +4 -13
- package/executor/EventExecutor.d.ts +2 -2
- package/executor/EventExecutor.js +11 -2
- package/executor/QueryExecutor.d.ts +2 -3
- package/executor/QueryExecutor.js +9 -11
- package/executor/TxExecutor.d.ts +2 -3
- package/executor/TxExecutor.js +3 -7
- package/executor/abstract/ContractExecutor.d.ts +12 -0
- package/executor/abstract/ContractExecutor.js +16 -0
- package/executor/abstract/DeployerExecutor.d.ts +12 -0
- package/executor/abstract/DeployerExecutor.js +12 -0
- package/executor/{Executor.d.ts → abstract/Executor.d.ts} +4 -7
- package/executor/{Executor.js → abstract/Executor.js} +3 -9
- package/executor/abstract/index.d.ts +3 -0
- package/executor/abstract/index.js +3 -0
- package/executor/index.d.ts +1 -1
- package/executor/index.js +1 -1
- package/package.json +6 -6
- package/types/index.d.ts +7 -3
package/Contract.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { ISubstrateClient } from '@dedot/api';
|
|
|
2
2
|
import { AccountId32, AccountId32Like } from '@dedot/codecs';
|
|
3
3
|
import { IEventRecord } from '@dedot/types';
|
|
4
4
|
import { TypinkRegistry } from './TypinkRegistry.js';
|
|
5
|
-
import { ContractEvent, ContractMetadata, GenericContractApi } from './types/index.js';
|
|
5
|
+
import { ContractEvent, ContractMetadata, GenericContractApi, ExecutionOptions } from './types/index.js';
|
|
6
6
|
export declare class Contract<ContractApi extends GenericContractApi = GenericContractApi> {
|
|
7
7
|
#private;
|
|
8
8
|
readonly client: ISubstrateClient<ContractApi['types']['ChainApi']>;
|
|
9
|
-
constructor(client: ISubstrateClient<ContractApi['types']['ChainApi']>, metadata: ContractMetadata | string, address: AccountId32Like);
|
|
9
|
+
constructor(client: ISubstrateClient<ContractApi['types']['ChainApi']>, metadata: ContractMetadata | string, address: AccountId32Like, options?: ExecutionOptions);
|
|
10
10
|
decodeEvent(eventRecord: IEventRecord): ContractEvent;
|
|
11
11
|
decodeEvents(eventRecords: IEventRecord[]): ContractEvent[];
|
|
12
12
|
get metadata(): ContractMetadata;
|
|
@@ -15,4 +15,5 @@ export declare class Contract<ContractApi extends GenericContractApi = GenericCo
|
|
|
15
15
|
get query(): ContractApi['query'];
|
|
16
16
|
get tx(): ContractApi['tx'];
|
|
17
17
|
get events(): ContractApi['events'];
|
|
18
|
+
get options(): ExecutionOptions | undefined;
|
|
18
19
|
}
|
package/Contract.js
CHANGED
|
@@ -7,12 +7,14 @@ export class Contract {
|
|
|
7
7
|
#registry;
|
|
8
8
|
#address;
|
|
9
9
|
#metadata;
|
|
10
|
-
|
|
10
|
+
#options;
|
|
11
|
+
constructor(client, metadata, address, options) {
|
|
11
12
|
this.client = client;
|
|
12
13
|
ensureSupportContractsPallet(client);
|
|
13
14
|
this.#address = new AccountId32(address);
|
|
14
15
|
this.#metadata = typeof metadata === 'string' ? parseRawMetadata(metadata) : metadata;
|
|
15
16
|
this.#registry = new TypinkRegistry(this.#metadata);
|
|
17
|
+
this.#options = options;
|
|
16
18
|
}
|
|
17
19
|
decodeEvent(eventRecord) {
|
|
18
20
|
return this.#registry.decodeEvent(eventRecord, this.address);
|
|
@@ -30,12 +32,15 @@ export class Contract {
|
|
|
30
32
|
return this.#registry;
|
|
31
33
|
}
|
|
32
34
|
get query() {
|
|
33
|
-
return newProxyChain(new QueryExecutor(this.client, this.#registry, this.#address));
|
|
35
|
+
return newProxyChain(new QueryExecutor(this.client, this.#registry, this.#address, this.#options));
|
|
34
36
|
}
|
|
35
37
|
get tx() {
|
|
36
|
-
return newProxyChain(new TxExecutor(this.client, this.#registry, this.#address));
|
|
38
|
+
return newProxyChain(new TxExecutor(this.client, this.#registry, this.#address, this.#options));
|
|
37
39
|
}
|
|
38
40
|
get events() {
|
|
39
|
-
return newProxyChain(new EventExecutor(this.client, this.#registry, this.#address));
|
|
41
|
+
return newProxyChain(new EventExecutor(this.client, this.#registry, this.#address, this.#options));
|
|
42
|
+
}
|
|
43
|
+
get options() {
|
|
44
|
+
return this.#options;
|
|
40
45
|
}
|
|
41
46
|
}
|
package/ContractDeployer.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { ISubstrateClient } from '@dedot/api';
|
|
2
2
|
import { Hash } from '@dedot/codecs';
|
|
3
3
|
import { TypinkRegistry } from './TypinkRegistry.js';
|
|
4
|
-
import { ContractMetadata, GenericContractApi } from './types/index.js';
|
|
4
|
+
import { ContractMetadata, GenericContractApi, ExecutionOptions } from './types/index.js';
|
|
5
5
|
export declare class ContractDeployer<ContractApi extends GenericContractApi = GenericContractApi> {
|
|
6
6
|
#private;
|
|
7
7
|
readonly client: ISubstrateClient<ContractApi['types']['ChainApi']>;
|
|
8
|
-
constructor(client: ISubstrateClient<ContractApi['types']['ChainApi']>, metadata: ContractMetadata | string, codeHashOrWasm: Hash | Uint8Array | string);
|
|
8
|
+
constructor(client: ISubstrateClient<ContractApi['types']['ChainApi']>, metadata: ContractMetadata | string, codeHashOrWasm: Hash | Uint8Array | string, options?: ExecutionOptions);
|
|
9
9
|
get metadata(): ContractMetadata;
|
|
10
10
|
get registry(): TypinkRegistry;
|
|
11
11
|
get tx(): ContractApi['constructorTx'];
|
|
12
12
|
get query(): ContractApi['constructorQuery'];
|
|
13
|
+
get options(): ExecutionOptions | undefined;
|
|
13
14
|
}
|
package/ContractDeployer.js
CHANGED
|
@@ -7,12 +7,14 @@ export class ContractDeployer {
|
|
|
7
7
|
#metadata;
|
|
8
8
|
#registry;
|
|
9
9
|
#code;
|
|
10
|
-
|
|
10
|
+
#options;
|
|
11
|
+
constructor(client, metadata, codeHashOrWasm, options) {
|
|
11
12
|
this.client = client;
|
|
12
13
|
ensureSupportContractsPallet(client);
|
|
13
14
|
this.#metadata = typeof metadata === 'string' ? parseRawMetadata(metadata) : metadata;
|
|
14
15
|
this.#registry = new TypinkRegistry(this.#metadata);
|
|
15
16
|
this.#code = codeHashOrWasm;
|
|
17
|
+
this.#options = options;
|
|
16
18
|
}
|
|
17
19
|
get metadata() {
|
|
18
20
|
return this.#metadata;
|
|
@@ -21,9 +23,12 @@ export class ContractDeployer {
|
|
|
21
23
|
return this.#registry;
|
|
22
24
|
}
|
|
23
25
|
get tx() {
|
|
24
|
-
return newProxyChain(new ConstructorTxExecutor(this.client, this.#registry, this.#code));
|
|
26
|
+
return newProxyChain(new ConstructorTxExecutor(this.client, this.#registry, this.#code, this.#options));
|
|
25
27
|
}
|
|
26
28
|
get query() {
|
|
27
|
-
return newProxyChain(new ConstructorQueryExecutor(this.client, this.#registry, this.#code));
|
|
29
|
+
return newProxyChain(new ConstructorQueryExecutor(this.client, this.#registry, this.#code, this.#options));
|
|
30
|
+
}
|
|
31
|
+
get options() {
|
|
32
|
+
return this.#options;
|
|
28
33
|
}
|
|
29
34
|
}
|
package/cjs/Contract.js
CHANGED
|
@@ -10,12 +10,14 @@ class Contract {
|
|
|
10
10
|
#registry;
|
|
11
11
|
#address;
|
|
12
12
|
#metadata;
|
|
13
|
-
|
|
13
|
+
#options;
|
|
14
|
+
constructor(client, metadata, address, options) {
|
|
14
15
|
this.client = client;
|
|
15
16
|
(0, utils_js_1.ensureSupportContractsPallet)(client);
|
|
16
17
|
this.#address = new codecs_1.AccountId32(address);
|
|
17
18
|
this.#metadata = typeof metadata === 'string' ? (0, utils_js_1.parseRawMetadata)(metadata) : metadata;
|
|
18
19
|
this.#registry = new TypinkRegistry_js_1.TypinkRegistry(this.#metadata);
|
|
20
|
+
this.#options = options;
|
|
19
21
|
}
|
|
20
22
|
decodeEvent(eventRecord) {
|
|
21
23
|
return this.#registry.decodeEvent(eventRecord, this.address);
|
|
@@ -33,13 +35,16 @@ class Contract {
|
|
|
33
35
|
return this.#registry;
|
|
34
36
|
}
|
|
35
37
|
get query() {
|
|
36
|
-
return (0, utils_js_1.newProxyChain)(new index_js_1.QueryExecutor(this.client, this.#registry, this.#address));
|
|
38
|
+
return (0, utils_js_1.newProxyChain)(new index_js_1.QueryExecutor(this.client, this.#registry, this.#address, this.#options));
|
|
37
39
|
}
|
|
38
40
|
get tx() {
|
|
39
|
-
return (0, utils_js_1.newProxyChain)(new index_js_1.TxExecutor(this.client, this.#registry, this.#address));
|
|
41
|
+
return (0, utils_js_1.newProxyChain)(new index_js_1.TxExecutor(this.client, this.#registry, this.#address, this.#options));
|
|
40
42
|
}
|
|
41
43
|
get events() {
|
|
42
|
-
return (0, utils_js_1.newProxyChain)(new index_js_1.EventExecutor(this.client, this.#registry, this.#address));
|
|
44
|
+
return (0, utils_js_1.newProxyChain)(new index_js_1.EventExecutor(this.client, this.#registry, this.#address, this.#options));
|
|
45
|
+
}
|
|
46
|
+
get options() {
|
|
47
|
+
return this.#options;
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
exports.Contract = Contract;
|
package/cjs/ContractDeployer.js
CHANGED
|
@@ -10,12 +10,14 @@ class ContractDeployer {
|
|
|
10
10
|
#metadata;
|
|
11
11
|
#registry;
|
|
12
12
|
#code;
|
|
13
|
-
|
|
13
|
+
#options;
|
|
14
|
+
constructor(client, metadata, codeHashOrWasm, options) {
|
|
14
15
|
this.client = client;
|
|
15
16
|
(0, utils_js_1.ensureSupportContractsPallet)(client);
|
|
16
17
|
this.#metadata = typeof metadata === 'string' ? (0, utils_js_1.parseRawMetadata)(metadata) : metadata;
|
|
17
18
|
this.#registry = new TypinkRegistry_js_1.TypinkRegistry(this.#metadata);
|
|
18
19
|
this.#code = codeHashOrWasm;
|
|
20
|
+
this.#options = options;
|
|
19
21
|
}
|
|
20
22
|
get metadata() {
|
|
21
23
|
return this.#metadata;
|
|
@@ -24,10 +26,13 @@ class ContractDeployer {
|
|
|
24
26
|
return this.#registry;
|
|
25
27
|
}
|
|
26
28
|
get tx() {
|
|
27
|
-
return (0, utils_js_1.newProxyChain)(new index_js_1.ConstructorTxExecutor(this.client, this.#registry, this.#code));
|
|
29
|
+
return (0, utils_js_1.newProxyChain)(new index_js_1.ConstructorTxExecutor(this.client, this.#registry, this.#code, this.#options));
|
|
28
30
|
}
|
|
29
31
|
get query() {
|
|
30
|
-
return (0, utils_js_1.newProxyChain)(new ConstructorQueryExecutor_js_1.ConstructorQueryExecutor(this.client, this.#registry, this.#code));
|
|
32
|
+
return (0, utils_js_1.newProxyChain)(new ConstructorQueryExecutor_js_1.ConstructorQueryExecutor(this.client, this.#registry, this.#code, this.#options));
|
|
33
|
+
}
|
|
34
|
+
get options() {
|
|
35
|
+
return this.#options;
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
exports.ContractDeployer = ContractDeployer;
|
|
@@ -4,21 +4,17 @@ exports.ConstructorQueryExecutor = void 0;
|
|
|
4
4
|
const utils_1 = require("@dedot/utils");
|
|
5
5
|
const errors_js_1 = require("../errors.js");
|
|
6
6
|
const utils_js_1 = require("../utils.js");
|
|
7
|
-
const
|
|
8
|
-
class ConstructorQueryExecutor extends
|
|
9
|
-
code;
|
|
10
|
-
constructor(client, registry, code) {
|
|
11
|
-
super(client, registry);
|
|
12
|
-
this.code = code;
|
|
13
|
-
}
|
|
7
|
+
const index_js_1 = require("./abstract/index.js");
|
|
8
|
+
class ConstructorQueryExecutor extends index_js_1.DeployerExecutor {
|
|
14
9
|
doExecute(constructor) {
|
|
15
|
-
const meta = this
|
|
10
|
+
const meta = this.findConstructorMeta(constructor);
|
|
16
11
|
(0, utils_1.assert)(meta, `Constructor message not found: ${constructor}`);
|
|
17
12
|
const callFn = async (...params) => {
|
|
18
13
|
const { args } = meta;
|
|
19
|
-
(0, utils_1.
|
|
20
|
-
|
|
21
|
-
const
|
|
14
|
+
(0, utils_1.assertFalse)(params.length < args.length, `Expected at least ${args.length} arguments, got ${params.length}`);
|
|
15
|
+
(0, utils_1.assertFalse)(params.length > args.length + 1, `Expected at most ${args.length + 1} arguments, got ${params.length}`);
|
|
16
|
+
const callOptions = (params[args.length] || {});
|
|
17
|
+
const { caller = this.options.defaultCaller, value = 0n, gasLimit, storageDepositLimit, salt = '0x', } = callOptions;
|
|
22
18
|
(0, utils_1.assert)(caller, 'Expected a valid caller address in ConstructorCallOptions');
|
|
23
19
|
(0, utils_1.assertFalse)((0, utils_1.isNull)(salt) || (0, utils_1.isUndefined)(salt), 'Expected a salt in ConstructorCallOptions');
|
|
24
20
|
const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
|
|
@@ -46,8 +42,5 @@ class ConstructorQueryExecutor extends Executor_js_1.Executor {
|
|
|
46
42
|
callFn.meta = meta;
|
|
47
43
|
return callFn;
|
|
48
44
|
}
|
|
49
|
-
#findConstructorMeta(constructor) {
|
|
50
|
-
return this.metadata.spec.constructors.find((one) => (0, utils_js_1.normalizeLabel)(one.label) === constructor);
|
|
51
|
-
}
|
|
52
45
|
}
|
|
53
46
|
exports.ConstructorQueryExecutor = ConstructorQueryExecutor;
|
|
@@ -2,16 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConstructorTxExecutor = void 0;
|
|
4
4
|
const utils_1 = require("@dedot/utils");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
class ConstructorTxExecutor extends Executor_js_1.Executor {
|
|
8
|
-
code;
|
|
9
|
-
constructor(client, registry, code) {
|
|
10
|
-
super(client, registry);
|
|
11
|
-
this.code = code;
|
|
12
|
-
}
|
|
5
|
+
const index_js_1 = require("./abstract/index.js");
|
|
6
|
+
class ConstructorTxExecutor extends index_js_1.DeployerExecutor {
|
|
13
7
|
doExecute(constructor) {
|
|
14
|
-
const meta = this
|
|
8
|
+
const meta = this.findConstructorMeta(constructor);
|
|
15
9
|
(0, utils_1.assert)(meta, `Constructor message not found: ${constructor}`);
|
|
16
10
|
const callFn = (...params) => {
|
|
17
11
|
const { args } = meta;
|
|
@@ -33,8 +27,5 @@ class ConstructorTxExecutor extends Executor_js_1.Executor {
|
|
|
33
27
|
callFn.meta = meta;
|
|
34
28
|
return callFn;
|
|
35
29
|
}
|
|
36
|
-
#findConstructorMeta(constructor) {
|
|
37
|
-
return this.metadata.spec.constructors.find((one) => (0, utils_js_1.normalizeLabel)(one.label) === constructor);
|
|
38
|
-
}
|
|
39
30
|
}
|
|
40
31
|
exports.ConstructorTxExecutor = ConstructorTxExecutor;
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EventExecutor = void 0;
|
|
4
4
|
const api_1 = require("@dedot/api");
|
|
5
5
|
const utils_1 = require("@dedot/utils");
|
|
6
|
-
const
|
|
7
|
-
class EventExecutor extends
|
|
6
|
+
const index_js_1 = require("./abstract/index.js");
|
|
7
|
+
class EventExecutor extends index_js_1.ContractExecutor {
|
|
8
8
|
doExecute(eventName) {
|
|
9
9
|
const meta = this.#findEventMeta(eventName);
|
|
10
10
|
(0, utils_1.assert)(meta, 'Contract event metadata not found!');
|
|
@@ -37,11 +37,20 @@ class EventExecutor extends Executor_js_1.Executor {
|
|
|
37
37
|
return events.filter(is);
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
+
const watch = (callback) => {
|
|
41
|
+
return this.client.query.system.events((records) => {
|
|
42
|
+
const events = filter(records);
|
|
43
|
+
if (events.length === 0)
|
|
44
|
+
return;
|
|
45
|
+
callback(filter(records));
|
|
46
|
+
});
|
|
47
|
+
};
|
|
40
48
|
return {
|
|
41
49
|
is,
|
|
42
50
|
find,
|
|
43
51
|
filter,
|
|
44
52
|
meta,
|
|
53
|
+
watch,
|
|
45
54
|
};
|
|
46
55
|
}
|
|
47
56
|
#findEventMeta(eventName) {
|
|
@@ -4,16 +4,17 @@ exports.QueryExecutor = void 0;
|
|
|
4
4
|
const utils_1 = require("@dedot/utils");
|
|
5
5
|
const errors_js_1 = require("../errors.js");
|
|
6
6
|
const utils_js_1 = require("../utils.js");
|
|
7
|
-
const
|
|
8
|
-
class QueryExecutor extends
|
|
7
|
+
const index_js_1 = require("./abstract/index.js");
|
|
8
|
+
class QueryExecutor extends index_js_1.ContractExecutor {
|
|
9
9
|
doExecute(message) {
|
|
10
|
-
const meta = this
|
|
10
|
+
const meta = this.findMessage(message);
|
|
11
11
|
(0, utils_1.assert)(meta, `Query message not found: ${message}`);
|
|
12
12
|
const callFn = async (...params) => {
|
|
13
13
|
const { args } = meta;
|
|
14
|
-
(0, utils_1.
|
|
15
|
-
|
|
16
|
-
const
|
|
14
|
+
(0, utils_1.assertFalse)(params.length < args.length, `Expected at least ${args.length} arguments, got ${params.length}`);
|
|
15
|
+
(0, utils_1.assertFalse)(params.length > args.length + 1, `Expected at most ${args.length + 1} arguments, got ${params.length}`);
|
|
16
|
+
const callOptions = (params[args.length] || {});
|
|
17
|
+
const { caller = this.options.defaultCaller, value = 0n, gasLimit, storageDepositLimit } = callOptions;
|
|
17
18
|
(0, utils_1.assert)(caller, 'Expected a valid caller address in ContractCallOptions');
|
|
18
19
|
const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
|
|
19
20
|
const bytes = (0, utils_1.u8aToHex)((0, utils_1.concatU8a)((0, utils_1.hexToU8a)(meta.selector), ...formattedInputs));
|
|
@@ -35,8 +36,5 @@ class QueryExecutor extends Executor_js_1.Executor {
|
|
|
35
36
|
callFn.meta = meta;
|
|
36
37
|
return callFn;
|
|
37
38
|
}
|
|
38
|
-
#findMessage(message) {
|
|
39
|
-
return this.metadata.spec.messages.find((one) => (0, utils_js_1.normalizeLabel)(one.label) === message);
|
|
40
|
-
}
|
|
41
39
|
}
|
|
42
40
|
exports.QueryExecutor = QueryExecutor;
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TxExecutor = void 0;
|
|
4
4
|
const utils_1 = require("@dedot/utils");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
class TxExecutor extends Executor_js_1.Executor {
|
|
5
|
+
const index_js_1 = require("./abstract/index.js");
|
|
6
|
+
class TxExecutor extends index_js_1.ContractExecutor {
|
|
8
7
|
doExecute(message) {
|
|
9
|
-
const meta = this
|
|
8
|
+
const meta = this.findTxMessage(message);
|
|
10
9
|
(0, utils_1.assert)(meta, `Tx message not found: ${message}`);
|
|
11
10
|
const callFn = (...params) => {
|
|
12
11
|
const { args } = meta;
|
|
@@ -21,8 +20,5 @@ class TxExecutor extends Executor_js_1.Executor {
|
|
|
21
20
|
callFn.meta = meta;
|
|
22
21
|
return callFn;
|
|
23
22
|
}
|
|
24
|
-
#findTxMessage(message) {
|
|
25
|
-
return this.metadata.spec.messages.find((one) => one.mutates && (0, utils_js_1.normalizeLabel)(one.label) === message);
|
|
26
|
-
}
|
|
27
23
|
}
|
|
28
24
|
exports.TxExecutor = TxExecutor;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContractExecutor = void 0;
|
|
4
|
+
const codecs_1 = require("@dedot/codecs");
|
|
5
|
+
const utils_js_1 = require("../../utils.js");
|
|
6
|
+
const Executor_js_1 = require("./Executor.js");
|
|
7
|
+
class ContractExecutor extends Executor_js_1.Executor {
|
|
8
|
+
address;
|
|
9
|
+
constructor(client, registry, address, options) {
|
|
10
|
+
super(client, registry, options);
|
|
11
|
+
this.address = new codecs_1.AccountId32(address);
|
|
12
|
+
}
|
|
13
|
+
findMessage(message) {
|
|
14
|
+
return this.metadata.spec.messages.find((one) => (0, utils_js_1.normalizeLabel)(one.label) === message);
|
|
15
|
+
}
|
|
16
|
+
findTxMessage(message) {
|
|
17
|
+
return this.metadata.spec.messages.find((one) => one.mutates && (0, utils_js_1.normalizeLabel)(one.label) === message);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ContractExecutor = ContractExecutor;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeployerExecutor = void 0;
|
|
4
|
+
const utils_js_1 = require("../../utils.js");
|
|
5
|
+
const Executor_js_1 = require("./Executor.js");
|
|
6
|
+
class DeployerExecutor extends Executor_js_1.Executor {
|
|
7
|
+
code;
|
|
8
|
+
constructor(client, registry, code, options) {
|
|
9
|
+
super(client, registry, options);
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
findConstructorMeta(constructor) {
|
|
13
|
+
return this.metadata.spec.constructors.find((one) => (0, utils_js_1.normalizeLabel)(one.label) === constructor);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.DeployerExecutor = DeployerExecutor;
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Executor = void 0;
|
|
4
|
-
const codecs_1 = require("@dedot/codecs");
|
|
5
4
|
class Executor {
|
|
6
5
|
client;
|
|
7
6
|
registry;
|
|
8
|
-
|
|
9
|
-
constructor(client, registry,
|
|
7
|
+
options;
|
|
8
|
+
constructor(client, registry, options = {}) {
|
|
10
9
|
this.client = client;
|
|
11
10
|
this.registry = registry;
|
|
12
|
-
|
|
13
|
-
this.#address = new codecs_1.AccountId32(address);
|
|
14
|
-
}
|
|
11
|
+
this.options = options;
|
|
15
12
|
}
|
|
16
13
|
get metadata() {
|
|
17
14
|
return this.registry.metadata;
|
|
18
15
|
}
|
|
19
|
-
get address() {
|
|
20
|
-
return this.#address;
|
|
21
|
-
}
|
|
22
16
|
tryEncode(param, value) {
|
|
23
17
|
const { type } = param.type;
|
|
24
18
|
const $codec = this.registry.findCodec(type);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Executor.js"), exports);
|
|
18
|
+
__exportStar(require("./DeployerExecutor.js"), exports);
|
|
19
|
+
__exportStar(require("./ContractExecutor.js"), exports);
|
package/cjs/executor/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./abstract/index.js"), exports);
|
|
18
18
|
__exportStar(require("./TxExecutor.js"), exports);
|
|
19
19
|
__exportStar(require("./QueryExecutor.js"), exports);
|
|
20
20
|
__exportStar(require("./ConstructorTxExecutor.js"), exports);
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import { ISubstrateClient } from '@dedot/api';
|
|
2
|
-
import { Hash } from '@dedot/codecs';
|
|
3
1
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
4
|
-
import { HexString } from '@dedot/utils';
|
|
5
|
-
import { TypinkRegistry } from '../TypinkRegistry.js';
|
|
6
2
|
import { GenericConstructorQueryCall } from '../types/index.js';
|
|
7
|
-
import {
|
|
8
|
-
export declare class ConstructorQueryExecutor<ChainApi extends GenericSubstrateApi> extends
|
|
9
|
-
#private;
|
|
10
|
-
protected readonly code: Hash | Uint8Array | HexString | string;
|
|
11
|
-
constructor(client: ISubstrateClient<ChainApi>, registry: TypinkRegistry, code: Hash | Uint8Array | string);
|
|
3
|
+
import { DeployerExecutor } from './abstract/index.js';
|
|
4
|
+
export declare class ConstructorQueryExecutor<ChainApi extends GenericSubstrateApi> extends DeployerExecutor<ChainApi> {
|
|
12
5
|
doExecute(constructor: string): GenericConstructorQueryCall<ChainApi>;
|
|
13
6
|
}
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import { assert, assertFalse, concatU8a, hexToU8a, isNull, isUndefined, isWasm, u8aToHex
|
|
1
|
+
import { assert, assertFalse, concatU8a, hexToU8a, isNull, isUndefined, isWasm, u8aToHex } from '@dedot/utils';
|
|
2
2
|
import { ContractInstantiateDispatchError, ContractInstantiateLangError } from '../errors.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export class ConstructorQueryExecutor extends
|
|
6
|
-
code;
|
|
7
|
-
constructor(client, registry, code) {
|
|
8
|
-
super(client, registry);
|
|
9
|
-
this.code = code;
|
|
10
|
-
}
|
|
3
|
+
import { toReturnFlags } from '../utils.js';
|
|
4
|
+
import { DeployerExecutor } from './abstract/index.js';
|
|
5
|
+
export class ConstructorQueryExecutor extends DeployerExecutor {
|
|
11
6
|
doExecute(constructor) {
|
|
12
|
-
const meta = this
|
|
7
|
+
const meta = this.findConstructorMeta(constructor);
|
|
13
8
|
assert(meta, `Constructor message not found: ${constructor}`);
|
|
14
9
|
const callFn = async (...params) => {
|
|
15
10
|
const { args } = meta;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
11
|
+
assertFalse(params.length < args.length, `Expected at least ${args.length} arguments, got ${params.length}`);
|
|
12
|
+
assertFalse(params.length > args.length + 1, `Expected at most ${args.length + 1} arguments, got ${params.length}`);
|
|
13
|
+
const callOptions = (params[args.length] || {});
|
|
14
|
+
const { caller = this.options.defaultCaller, value = 0n, gasLimit, storageDepositLimit, salt = '0x', } = callOptions;
|
|
19
15
|
assert(caller, 'Expected a valid caller address in ConstructorCallOptions');
|
|
20
16
|
assertFalse(isNull(salt) || isUndefined(salt), 'Expected a salt in ConstructorCallOptions');
|
|
21
17
|
const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
|
|
@@ -43,7 +39,4 @@ export class ConstructorQueryExecutor extends Executor {
|
|
|
43
39
|
callFn.meta = meta;
|
|
44
40
|
return callFn;
|
|
45
41
|
}
|
|
46
|
-
#findConstructorMeta(constructor) {
|
|
47
|
-
return this.metadata.spec.constructors.find((one) => normalizeLabel(one.label) === constructor);
|
|
48
|
-
}
|
|
49
42
|
}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import { ISubstrateClient } from '@dedot/api';
|
|
2
|
-
import { Hash } from '@dedot/codecs';
|
|
3
1
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
4
|
-
import { HexString } from '@dedot/utils';
|
|
5
|
-
import { TypinkRegistry } from '../TypinkRegistry.js';
|
|
6
2
|
import { GenericConstructorTxCall } from '../types/index.js';
|
|
7
|
-
import {
|
|
8
|
-
export declare class ConstructorTxExecutor<ChainApi extends GenericSubstrateApi> extends
|
|
9
|
-
#private;
|
|
10
|
-
protected readonly code: Hash | Uint8Array | HexString | string;
|
|
11
|
-
constructor(client: ISubstrateClient<ChainApi>, registry: TypinkRegistry, code: Hash | Uint8Array | string);
|
|
3
|
+
import { DeployerExecutor } from './abstract/index.js';
|
|
4
|
+
export declare class ConstructorTxExecutor<ChainApi extends GenericSubstrateApi> extends DeployerExecutor<ChainApi> {
|
|
12
5
|
doExecute(constructor: string): GenericConstructorTxCall<ChainApi>;
|
|
13
6
|
}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { assert, assertFalse, concatU8a, hexToU8a, isNull, isUndefined, isWasm, u8aToHex
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export class ConstructorTxExecutor extends Executor {
|
|
5
|
-
code;
|
|
6
|
-
constructor(client, registry, code) {
|
|
7
|
-
super(client, registry);
|
|
8
|
-
this.code = code;
|
|
9
|
-
}
|
|
1
|
+
import { assert, assertFalse, concatU8a, hexToU8a, isNull, isUndefined, isWasm, u8aToHex } from '@dedot/utils';
|
|
2
|
+
import { DeployerExecutor } from './abstract/index.js';
|
|
3
|
+
export class ConstructorTxExecutor extends DeployerExecutor {
|
|
10
4
|
doExecute(constructor) {
|
|
11
|
-
const meta = this
|
|
5
|
+
const meta = this.findConstructorMeta(constructor);
|
|
12
6
|
assert(meta, `Constructor message not found: ${constructor}`);
|
|
13
7
|
const callFn = (...params) => {
|
|
14
8
|
const { args } = meta;
|
|
@@ -30,7 +24,4 @@ export class ConstructorTxExecutor extends Executor {
|
|
|
30
24
|
callFn.meta = meta;
|
|
31
25
|
return callFn;
|
|
32
26
|
}
|
|
33
|
-
#findConstructorMeta(constructor) {
|
|
34
|
-
return this.metadata.spec.constructors.find((one) => normalizeLabel(one.label) === constructor);
|
|
35
|
-
}
|
|
36
27
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
2
2
|
import { GenericContractEvent } from '../types/index.js';
|
|
3
|
-
import {
|
|
4
|
-
export declare class EventExecutor<ChainApi extends GenericSubstrateApi> extends
|
|
3
|
+
import { ContractExecutor } from './abstract/index.js';
|
|
4
|
+
export declare class EventExecutor<ChainApi extends GenericSubstrateApi> extends ContractExecutor<ChainApi> {
|
|
5
5
|
#private;
|
|
6
6
|
doExecute(eventName: string): GenericContractEvent;
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isEventRecord } from '@dedot/api';
|
|
2
2
|
import { assert, stringPascalCase } from '@dedot/utils';
|
|
3
|
-
import {
|
|
4
|
-
export class EventExecutor extends
|
|
3
|
+
import { ContractExecutor } from './abstract/index.js';
|
|
4
|
+
export class EventExecutor extends ContractExecutor {
|
|
5
5
|
doExecute(eventName) {
|
|
6
6
|
const meta = this.#findEventMeta(eventName);
|
|
7
7
|
assert(meta, 'Contract event metadata not found!');
|
|
@@ -34,11 +34,20 @@ export class EventExecutor extends Executor {
|
|
|
34
34
|
return events.filter(is);
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
+
const watch = (callback) => {
|
|
38
|
+
return this.client.query.system.events((records) => {
|
|
39
|
+
const events = filter(records);
|
|
40
|
+
if (events.length === 0)
|
|
41
|
+
return;
|
|
42
|
+
callback(filter(records));
|
|
43
|
+
});
|
|
44
|
+
};
|
|
37
45
|
return {
|
|
38
46
|
is,
|
|
39
47
|
find,
|
|
40
48
|
filter,
|
|
41
49
|
meta,
|
|
50
|
+
watch,
|
|
42
51
|
};
|
|
43
52
|
}
|
|
44
53
|
#findEventMeta(eventName) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
2
2
|
import { GenericContractQueryCall } from '../types/index.js';
|
|
3
|
-
import {
|
|
4
|
-
export declare class QueryExecutor<ChainApi extends GenericSubstrateApi> extends
|
|
5
|
-
#private;
|
|
3
|
+
import { ContractExecutor } from './abstract/index.js';
|
|
4
|
+
export declare class QueryExecutor<ChainApi extends GenericSubstrateApi> extends ContractExecutor<ChainApi> {
|
|
6
5
|
doExecute(message: string): GenericContractQueryCall<ChainApi>;
|
|
7
6
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { assert, concatU8a, hexToU8a, u8aToHex } from '@dedot/utils';
|
|
1
|
+
import { assert, assertFalse, concatU8a, hexToU8a, u8aToHex } from '@dedot/utils';
|
|
2
2
|
import { ContractDispatchError, ContractLangError } from '../errors.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export class QueryExecutor extends
|
|
3
|
+
import { toReturnFlags } from '../utils.js';
|
|
4
|
+
import { ContractExecutor } from './abstract/index.js';
|
|
5
|
+
export class QueryExecutor extends ContractExecutor {
|
|
6
6
|
doExecute(message) {
|
|
7
|
-
const meta = this
|
|
7
|
+
const meta = this.findMessage(message);
|
|
8
8
|
assert(meta, `Query message not found: ${message}`);
|
|
9
9
|
const callFn = async (...params) => {
|
|
10
10
|
const { args } = meta;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
11
|
+
assertFalse(params.length < args.length, `Expected at least ${args.length} arguments, got ${params.length}`);
|
|
12
|
+
assertFalse(params.length > args.length + 1, `Expected at most ${args.length + 1} arguments, got ${params.length}`);
|
|
13
|
+
const callOptions = (params[args.length] || {});
|
|
14
|
+
const { caller = this.options.defaultCaller, value = 0n, gasLimit, storageDepositLimit } = callOptions;
|
|
14
15
|
assert(caller, 'Expected a valid caller address in ContractCallOptions');
|
|
15
16
|
const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
|
|
16
17
|
const bytes = u8aToHex(concatU8a(hexToU8a(meta.selector), ...formattedInputs));
|
|
@@ -32,7 +33,4 @@ export class QueryExecutor extends Executor {
|
|
|
32
33
|
callFn.meta = meta;
|
|
33
34
|
return callFn;
|
|
34
35
|
}
|
|
35
|
-
#findMessage(message) {
|
|
36
|
-
return this.metadata.spec.messages.find((one) => normalizeLabel(one.label) === message);
|
|
37
|
-
}
|
|
38
36
|
}
|
package/executor/TxExecutor.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
2
2
|
import { GenericContractTxCall } from '../types/index.js';
|
|
3
|
-
import {
|
|
4
|
-
export declare class TxExecutor<ChainApi extends GenericSubstrateApi> extends
|
|
5
|
-
#private;
|
|
3
|
+
import { ContractExecutor } from './abstract/index.js';
|
|
4
|
+
export declare class TxExecutor<ChainApi extends GenericSubstrateApi> extends ContractExecutor<ChainApi> {
|
|
6
5
|
doExecute(message: string): GenericContractTxCall<ChainApi>;
|
|
7
6
|
}
|
package/executor/TxExecutor.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { assert, concatU8a, hexToU8a, u8aToHex } from '@dedot/utils';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export class TxExecutor extends Executor {
|
|
2
|
+
import { ContractExecutor } from './abstract/index.js';
|
|
3
|
+
export class TxExecutor extends ContractExecutor {
|
|
5
4
|
doExecute(message) {
|
|
6
|
-
const meta = this
|
|
5
|
+
const meta = this.findTxMessage(message);
|
|
7
6
|
assert(meta, `Tx message not found: ${message}`);
|
|
8
7
|
const callFn = (...params) => {
|
|
9
8
|
const { args } = meta;
|
|
@@ -18,7 +17,4 @@ export class TxExecutor extends Executor {
|
|
|
18
17
|
callFn.meta = meta;
|
|
19
18
|
return callFn;
|
|
20
19
|
}
|
|
21
|
-
#findTxMessage(message) {
|
|
22
|
-
return this.metadata.spec.messages.find((one) => one.mutates && normalizeLabel(one.label) === message);
|
|
23
|
-
}
|
|
24
20
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ISubstrateClient } from '@dedot/api';
|
|
2
|
+
import { AccountId32, AccountId32Like } from '@dedot/codecs';
|
|
3
|
+
import { GenericSubstrateApi } from '@dedot/types';
|
|
4
|
+
import { TypinkRegistry } from '../../TypinkRegistry.js';
|
|
5
|
+
import { ContractCallMessage, ExecutionOptions } from '../../types/index.js';
|
|
6
|
+
import { Executor } from './Executor.js';
|
|
7
|
+
export declare abstract class ContractExecutor<ChainApi extends GenericSubstrateApi> extends Executor<ChainApi> {
|
|
8
|
+
readonly address: AccountId32;
|
|
9
|
+
constructor(client: ISubstrateClient<ChainApi>, registry: TypinkRegistry, address: AccountId32Like, options?: ExecutionOptions);
|
|
10
|
+
protected findMessage(message: string): ContractCallMessage | undefined;
|
|
11
|
+
protected findTxMessage(message: string): ContractCallMessage | undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AccountId32 } from '@dedot/codecs';
|
|
2
|
+
import { normalizeLabel } from '../../utils.js';
|
|
3
|
+
import { Executor } from './Executor.js';
|
|
4
|
+
export class ContractExecutor extends Executor {
|
|
5
|
+
address;
|
|
6
|
+
constructor(client, registry, address, options) {
|
|
7
|
+
super(client, registry, options);
|
|
8
|
+
this.address = new AccountId32(address);
|
|
9
|
+
}
|
|
10
|
+
findMessage(message) {
|
|
11
|
+
return this.metadata.spec.messages.find((one) => normalizeLabel(one.label) === message);
|
|
12
|
+
}
|
|
13
|
+
findTxMessage(message) {
|
|
14
|
+
return this.metadata.spec.messages.find((one) => one.mutates && normalizeLabel(one.label) === message);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ISubstrateClient } from '@dedot/api';
|
|
2
|
+
import { Hash } from '@dedot/codecs';
|
|
3
|
+
import { GenericSubstrateApi } from '@dedot/types';
|
|
4
|
+
import { HexString } from '@dedot/utils';
|
|
5
|
+
import { TypinkRegistry } from '../../TypinkRegistry.js';
|
|
6
|
+
import { ContractConstructorMessage, ExecutionOptions } from '../../types/index.js';
|
|
7
|
+
import { Executor } from './Executor.js';
|
|
8
|
+
export declare abstract class DeployerExecutor<ChainApi extends GenericSubstrateApi> extends Executor<ChainApi> {
|
|
9
|
+
readonly code: Hash | Uint8Array | HexString | string;
|
|
10
|
+
constructor(client: ISubstrateClient<ChainApi>, registry: TypinkRegistry, code: Hash | Uint8Array | HexString | string, options?: ExecutionOptions);
|
|
11
|
+
protected findConstructorMeta(constructor: string): ContractConstructorMessage | undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { normalizeLabel } from '../../utils.js';
|
|
2
|
+
import { Executor } from './Executor.js';
|
|
3
|
+
export class DeployerExecutor extends Executor {
|
|
4
|
+
code;
|
|
5
|
+
constructor(client, registry, code, options) {
|
|
6
|
+
super(client, registry, options);
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
findConstructorMeta(constructor) {
|
|
10
|
+
return this.metadata.spec.constructors.find((one) => normalizeLabel(one.label) === constructor);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { ISubstrateClient } from '@dedot/api';
|
|
2
2
|
import { SubstrateApi } from '@dedot/api/chaintypes';
|
|
3
|
-
import { AccountId32, AccountId32Like } from '@dedot/codecs';
|
|
4
3
|
import { GenericSubstrateApi, RpcVersion } from '@dedot/types';
|
|
5
|
-
import { TypinkRegistry } from '
|
|
6
|
-
import { ContractMessageArg, ContractMessage } from '
|
|
7
|
-
import { ContractMetadata } from '../types/index.js';
|
|
4
|
+
import { TypinkRegistry } from '../../TypinkRegistry.js';
|
|
5
|
+
import { ContractMessageArg, ContractMessage, ExecutionOptions, ContractMetadata } from '../../types/index.js';
|
|
8
6
|
export declare abstract class Executor<ChainApi extends GenericSubstrateApi = SubstrateApi[RpcVersion]> {
|
|
9
|
-
#private;
|
|
10
7
|
readonly client: ISubstrateClient<ChainApi>;
|
|
11
8
|
readonly registry: TypinkRegistry;
|
|
12
|
-
|
|
9
|
+
readonly options: ExecutionOptions;
|
|
10
|
+
constructor(client: ISubstrateClient<ChainApi>, registry: TypinkRegistry, options?: ExecutionOptions);
|
|
13
11
|
get metadata(): ContractMetadata;
|
|
14
|
-
get address(): AccountId32 | undefined;
|
|
15
12
|
abstract doExecute(...paths: string[]): unknown;
|
|
16
13
|
tryEncode(param: ContractMessageArg, value: any): Uint8Array;
|
|
17
14
|
tryDecode(meta: ContractMessage, raw: any): unknown;
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import { AccountId32 } from '@dedot/codecs';
|
|
2
1
|
export class Executor {
|
|
3
2
|
client;
|
|
4
3
|
registry;
|
|
5
|
-
|
|
6
|
-
constructor(client, registry,
|
|
4
|
+
options;
|
|
5
|
+
constructor(client, registry, options = {}) {
|
|
7
6
|
this.client = client;
|
|
8
7
|
this.registry = registry;
|
|
9
|
-
|
|
10
|
-
this.#address = new AccountId32(address);
|
|
11
|
-
}
|
|
8
|
+
this.options = options;
|
|
12
9
|
}
|
|
13
10
|
get metadata() {
|
|
14
11
|
return this.registry.metadata;
|
|
15
12
|
}
|
|
16
|
-
get address() {
|
|
17
|
-
return this.#address;
|
|
18
|
-
}
|
|
19
13
|
tryEncode(param, value) {
|
|
20
14
|
const { type } = param.type;
|
|
21
15
|
const $codec = this.registry.findCodec(type);
|
package/executor/index.d.ts
CHANGED
package/executor/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/contracts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Delightful ink! Contract APIs",
|
|
5
5
|
"author": "Tung Vu <tung@coongcrafts.io>",
|
|
6
6
|
"homepage": "https://github.com/dedotdev/dedot/tree/main/packages/contracts",
|
|
@@ -18,17 +18,17 @@
|
|
|
18
18
|
"test": "vitest --watch=false"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dedot/api": "0.
|
|
22
|
-
"@dedot/codecs": "0.
|
|
23
|
-
"@dedot/types": "0.
|
|
24
|
-
"@dedot/utils": "0.
|
|
21
|
+
"@dedot/api": "0.6.0",
|
|
22
|
+
"@dedot/codecs": "0.6.0",
|
|
23
|
+
"@dedot/types": "0.6.0",
|
|
24
|
+
"@dedot/utils": "0.6.0"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public",
|
|
28
28
|
"directory": "dist"
|
|
29
29
|
},
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "80e64c7da483c4f5b757f6af7259aa4fdd5397fc",
|
|
32
32
|
"module": "./index.js",
|
|
33
33
|
"types": "./index.d.ts",
|
|
34
34
|
"exports": {
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SubstrateApi } from '@dedot/api/chaintypes';
|
|
2
2
|
import { AccountId32, AccountId32Like, BytesLike, Weight } from '@dedot/codecs';
|
|
3
|
-
import { AnyFunc, AsyncMethod, GenericSubstrateApi, IEventRecord, RpcVersion, VersionedGenericSubstrateApi } from '@dedot/types';
|
|
3
|
+
import { AnyFunc, AsyncMethod, GenericSubstrateApi, IEventRecord, RpcVersion, Unsub, VersionedGenericSubstrateApi } from '@dedot/types';
|
|
4
4
|
import { ContractCallMessage, ContractConstructorMessage } from './shared.js';
|
|
5
5
|
import { ContractEventV4, ContractMetadataV4 } from './v4.js';
|
|
6
6
|
import { ContractEventV5, ContractMetadataV5 } from './v5.js';
|
|
@@ -36,14 +36,14 @@ export type CallOptions = {
|
|
|
36
36
|
};
|
|
37
37
|
export type ConstructorCallOptions = CallOptions & {
|
|
38
38
|
salt?: BytesLike;
|
|
39
|
-
caller
|
|
39
|
+
caller?: AccountId32Like;
|
|
40
40
|
};
|
|
41
41
|
export type ConstructorTxOptions = CallOptions & {
|
|
42
42
|
salt?: BytesLike;
|
|
43
43
|
gasLimit: Weight;
|
|
44
44
|
};
|
|
45
45
|
export type ContractCallOptions = CallOptions & {
|
|
46
|
-
caller
|
|
46
|
+
caller?: AccountId32Like;
|
|
47
47
|
};
|
|
48
48
|
export type ContractTxOptions = CallOptions & {
|
|
49
49
|
gasLimit: Weight;
|
|
@@ -82,6 +82,7 @@ export interface GenericContractEvent<EventName extends string = string, Data ex
|
|
|
82
82
|
is: (event: IEventRecord | ContractEvent) => event is ContractEvent<EventName, Data>;
|
|
83
83
|
find: (events: IEventRecord[] | ContractEvent[]) => ContractEvent<EventName, Data> | undefined;
|
|
84
84
|
filter: (events: IEventRecord[] | ContractEvent[]) => ContractEvent<EventName, Data>[];
|
|
85
|
+
watch: (callback: (events: ContractEvent<EventName, Data>[]) => void) => Promise<Unsub>;
|
|
85
86
|
meta: ContractEventMeta;
|
|
86
87
|
}
|
|
87
88
|
export interface GenericContractEvents<_ extends GenericSubstrateApi> {
|
|
@@ -99,3 +100,6 @@ export interface GenericContractApi<Rv extends RpcVersion = RpcVersion, ChainApi
|
|
|
99
100
|
ChainApi: ChainApi[Rv];
|
|
100
101
|
};
|
|
101
102
|
}
|
|
103
|
+
export interface ExecutionOptions {
|
|
104
|
+
defaultCaller?: AccountId32Like;
|
|
105
|
+
}
|