@dedot/contracts 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/errors.js +251 -0
- package/cjs/executor/ConstructorQueryExecutor.js +15 -2
- package/cjs/executor/QueryExecutor.js +12 -11
- package/cjs/index.js +1 -0
- package/errors.d.ts +208 -0
- package/errors.js +236 -0
- package/executor/ConstructorQueryExecutor.js +15 -2
- package/executor/Executor.d.ts +2 -2
- package/executor/QueryExecutor.js +12 -11
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +6 -6
- package/types/index.d.ts +13 -8
package/cjs/errors.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isContractInstantiateLangError = exports.isContractInstantiateDispatchError = exports.isContractInstantiateError = exports.isContractLangError = exports.isContractDispatchError = exports.isContractExecutionError = exports.ContractLangError = exports.ContractDispatchError = exports.ContractExecutionError = exports.ContractInstantiateLangError = exports.ContractInstantiateDispatchError = exports.ContractInstantiateError = void 0;
|
|
4
|
+
const utils_1 = require("@dedot/utils");
|
|
5
|
+
/**
|
|
6
|
+
* Represents an error that occurred during the instantiation of a smart contract.
|
|
7
|
+
* This class extends the base `DedotError` and includes a `raw` property of type `ContractInstantiateResult`.
|
|
8
|
+
*
|
|
9
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
10
|
+
*
|
|
11
|
+
* @extends DedotError
|
|
12
|
+
*/
|
|
13
|
+
class ContractInstantiateError extends utils_1.DedotError {
|
|
14
|
+
/**
|
|
15
|
+
* The raw result of the contract instantiation.
|
|
16
|
+
*/
|
|
17
|
+
raw;
|
|
18
|
+
/**
|
|
19
|
+
* Constructs a new `ContractInstantiateError` instance.
|
|
20
|
+
*
|
|
21
|
+
* @param raw - The raw result of the contract instantiation.
|
|
22
|
+
*/
|
|
23
|
+
constructor(raw) {
|
|
24
|
+
super();
|
|
25
|
+
this.raw = raw;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ContractInstantiateError = ContractInstantiateError;
|
|
29
|
+
/**
|
|
30
|
+
* Represents an error that occurred during the dispatch phase of contract instantiation.
|
|
31
|
+
* This class extends `ContractInstantiateError` and includes a `DispatchError` property.
|
|
32
|
+
*
|
|
33
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
34
|
+
*
|
|
35
|
+
* @extends ContractInstantiateError
|
|
36
|
+
*/
|
|
37
|
+
class ContractInstantiateDispatchError extends ContractInstantiateError {
|
|
38
|
+
/**
|
|
39
|
+
* The error that occurred during the dispatch phase.
|
|
40
|
+
*/
|
|
41
|
+
dispatchError;
|
|
42
|
+
/**
|
|
43
|
+
* Constructs a new `ContractInstantiateDispatchError` instance.
|
|
44
|
+
*
|
|
45
|
+
* @param err - The `DispatchError` that occurred during the dispatch phase.
|
|
46
|
+
* @param raw - The raw result of the contract instantiation.
|
|
47
|
+
*/
|
|
48
|
+
constructor(err, raw) {
|
|
49
|
+
super(raw);
|
|
50
|
+
this.dispatchError = err;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.ContractInstantiateDispatchError = ContractInstantiateDispatchError;
|
|
54
|
+
/**
|
|
55
|
+
* Represents an error that occurred during the instantiation of a smart contract due to a language-specific error.
|
|
56
|
+
* This class extends `ContractInstantiateError` and includes a `LangError` property.
|
|
57
|
+
*
|
|
58
|
+
* Ref: https://use.ink/faq/migrating-from-ink-3-to-4#:~:text=Add%20support%20for,equivalent%20LangError.
|
|
59
|
+
*
|
|
60
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
61
|
+
*
|
|
62
|
+
* @extends ContractInstantiateError
|
|
63
|
+
*/
|
|
64
|
+
class ContractInstantiateLangError extends ContractInstantiateError {
|
|
65
|
+
/**
|
|
66
|
+
* The language-specific error that occurred during the instantiation.
|
|
67
|
+
*/
|
|
68
|
+
langError;
|
|
69
|
+
/**
|
|
70
|
+
* Constructs a new `ContractInstantiateLangError` instance.
|
|
71
|
+
*
|
|
72
|
+
* @param err - The `LangError` that occurred during the instantiation phase.
|
|
73
|
+
* @param raw - The raw result of the contract instantiation.
|
|
74
|
+
*/
|
|
75
|
+
constructor(err, raw) {
|
|
76
|
+
super(raw);
|
|
77
|
+
this.langError = err;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.ContractInstantiateLangError = ContractInstantiateLangError;
|
|
81
|
+
/**
|
|
82
|
+
* Represents an error that occurred during the execution of a smart contract call.
|
|
83
|
+
* This class extends the base `DedotError` and includes a `raw` property of type `ContractCallResult`.
|
|
84
|
+
*
|
|
85
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
86
|
+
*
|
|
87
|
+
* @extends DedotError
|
|
88
|
+
*/
|
|
89
|
+
class ContractExecutionError extends utils_1.DedotError {
|
|
90
|
+
/**
|
|
91
|
+
* The raw result of the contract call.
|
|
92
|
+
*/
|
|
93
|
+
raw;
|
|
94
|
+
/**
|
|
95
|
+
* Constructs a new `ContractExecutionError` instance.
|
|
96
|
+
*
|
|
97
|
+
* @param raw - The raw result of the contract call.
|
|
98
|
+
*/
|
|
99
|
+
constructor(raw) {
|
|
100
|
+
super();
|
|
101
|
+
this.raw = raw;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.ContractExecutionError = ContractExecutionError;
|
|
105
|
+
/**
|
|
106
|
+
* Represents an error that occurred during the execution of a smart contract call due to a dispatch error.
|
|
107
|
+
* This class extends `ContractExecutionError` and includes a `DispatchError` property.
|
|
108
|
+
*
|
|
109
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
110
|
+
*
|
|
111
|
+
* @extends ContractExecutionError
|
|
112
|
+
*/
|
|
113
|
+
class ContractDispatchError extends ContractExecutionError {
|
|
114
|
+
/**
|
|
115
|
+
* The error that occurred during the dispatch phase.
|
|
116
|
+
*/
|
|
117
|
+
dispatchError;
|
|
118
|
+
/**
|
|
119
|
+
* Constructs a new `ContractDispatchError` instance.
|
|
120
|
+
*
|
|
121
|
+
* @param err - The `DispatchError` that occurred during the dispatch phase.
|
|
122
|
+
* @param raw - The raw result of the contract call.
|
|
123
|
+
*/
|
|
124
|
+
constructor(err, raw) {
|
|
125
|
+
super(raw);
|
|
126
|
+
this.dispatchError = err;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.ContractDispatchError = ContractDispatchError;
|
|
130
|
+
/**
|
|
131
|
+
* Represents an error that occurred during the execution of a smart contract call due to a language-specific error.
|
|
132
|
+
* This class extends `ContractExecutionError` and includes a `LangError` property.
|
|
133
|
+
*
|
|
134
|
+
* Ref: https://use.ink/faq/migrating-from-ink-3-to-4#:~:text=Add%20support%20for,equivalent%20LangError.
|
|
135
|
+
*
|
|
136
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
137
|
+
*
|
|
138
|
+
* @extends ContractExecutionError
|
|
139
|
+
*/
|
|
140
|
+
class ContractLangError extends ContractExecutionError {
|
|
141
|
+
/**
|
|
142
|
+
* The language-specific error that occurred during the execution.
|
|
143
|
+
*/
|
|
144
|
+
langError;
|
|
145
|
+
/**
|
|
146
|
+
* Constructs a new `ContractLangError` instance.
|
|
147
|
+
*
|
|
148
|
+
* @param err - The `LangError` that occurred during the execution phase.
|
|
149
|
+
* @param raw - The raw result of the contract call.
|
|
150
|
+
*/
|
|
151
|
+
constructor(err, raw) {
|
|
152
|
+
super(raw);
|
|
153
|
+
this.langError = err;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.ContractLangError = ContractLangError;
|
|
157
|
+
/**
|
|
158
|
+
* Checks if the provided error is an instance of `ContractExecutionError`.
|
|
159
|
+
*
|
|
160
|
+
* This function is used to determine if a given error is a result of an execution error during a smart contract call.
|
|
161
|
+
*
|
|
162
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
163
|
+
*
|
|
164
|
+
* @param e - The error to be checked.
|
|
165
|
+
*
|
|
166
|
+
* @returns `true` if the error is an instance of `ContractExecutionError`, `false` otherwise.
|
|
167
|
+
*/
|
|
168
|
+
function isContractExecutionError(e) {
|
|
169
|
+
return e instanceof ContractExecutionError;
|
|
170
|
+
}
|
|
171
|
+
exports.isContractExecutionError = isContractExecutionError;
|
|
172
|
+
/**
|
|
173
|
+
* Checks if the provided error is an instance of `ContractDispatchError`.
|
|
174
|
+
*
|
|
175
|
+
* This function is used to determine if a given error is a result of a dispatch error during a smart contract call.
|
|
176
|
+
*
|
|
177
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
178
|
+
*
|
|
179
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
180
|
+
*
|
|
181
|
+
* @returns `true` if the error is an instance of `ContractDispatchError`, `false` otherwise.
|
|
182
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractDispatchError`.
|
|
183
|
+
*/
|
|
184
|
+
function isContractDispatchError(e) {
|
|
185
|
+
return e instanceof ContractDispatchError;
|
|
186
|
+
}
|
|
187
|
+
exports.isContractDispatchError = isContractDispatchError;
|
|
188
|
+
/**
|
|
189
|
+
* Checks if the provided error is an instance of `ContractLangError`.
|
|
190
|
+
*
|
|
191
|
+
* This function is used to determine if a given error is a result of a language-specific error during a smart contract call.
|
|
192
|
+
*
|
|
193
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
194
|
+
*
|
|
195
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
196
|
+
*
|
|
197
|
+
* @returns `true` if the error is an instance of `ContractLangError`, `false` otherwise.
|
|
198
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractLangError`.
|
|
199
|
+
*/
|
|
200
|
+
function isContractLangError(e) {
|
|
201
|
+
return e instanceof ContractLangError;
|
|
202
|
+
}
|
|
203
|
+
exports.isContractLangError = isContractLangError;
|
|
204
|
+
/**
|
|
205
|
+
* Checks if the provided error is an instance of `ContractInstantiateError`.
|
|
206
|
+
*
|
|
207
|
+
* This function is used to determine if a given error is a result of an execution error during the instantiation of a smart contract.
|
|
208
|
+
*
|
|
209
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
210
|
+
*
|
|
211
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
212
|
+
*
|
|
213
|
+
* @returns `true` if the error is an instance of `ContractInstantiateError`, `false` otherwise.
|
|
214
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractInstantiateError`.
|
|
215
|
+
*/
|
|
216
|
+
function isContractInstantiateError(e) {
|
|
217
|
+
return e instanceof ContractInstantiateError;
|
|
218
|
+
}
|
|
219
|
+
exports.isContractInstantiateError = isContractInstantiateError;
|
|
220
|
+
/**
|
|
221
|
+
* Checks if the provided error is an instance of `ContractInstantiateDispatchError`.
|
|
222
|
+
*
|
|
223
|
+
* This function is used to determine if a given error is a result of a dispatch error during the instantiation of a smart contract.
|
|
224
|
+
*
|
|
225
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
226
|
+
*
|
|
227
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
228
|
+
*
|
|
229
|
+
* @returns `true` if the error is an instance of `ContractInstantiateDispatchError`, `false` otherwise.
|
|
230
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractInstantiateDispatchError`.
|
|
231
|
+
*/
|
|
232
|
+
function isContractInstantiateDispatchError(e) {
|
|
233
|
+
return e instanceof ContractInstantiateDispatchError;
|
|
234
|
+
}
|
|
235
|
+
exports.isContractInstantiateDispatchError = isContractInstantiateDispatchError;
|
|
236
|
+
/**
|
|
237
|
+
* Checks if the provided error is an instance of `ContractInstantiateLangError`.
|
|
238
|
+
*
|
|
239
|
+
* This function is used to determine if a given error is a result of a language-specific error during the instantiation of a smart contract.
|
|
240
|
+
*
|
|
241
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
242
|
+
*
|
|
243
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
244
|
+
*
|
|
245
|
+
* @returns `true` if the error is an instance of `ContractInstantiateLangError`, `false` otherwise.
|
|
246
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractInstantiateLangError`.
|
|
247
|
+
*/
|
|
248
|
+
function isContractInstantiateLangError(e) {
|
|
249
|
+
return e instanceof ContractInstantiateLangError;
|
|
250
|
+
}
|
|
251
|
+
exports.isContractInstantiateLangError = isContractInstantiateLangError;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConstructorQueryExecutor = void 0;
|
|
4
4
|
const utils_1 = require("@dedot/utils");
|
|
5
|
+
const errors_js_1 = require("../errors.js");
|
|
5
6
|
const utils_js_1 = require("../utils.js");
|
|
6
7
|
const Executor_js_1 = require("./Executor.js");
|
|
7
8
|
class ConstructorQueryExecutor extends Executor_js_1.Executor {
|
|
@@ -13,7 +14,7 @@ class ConstructorQueryExecutor extends Executor_js_1.Executor {
|
|
|
13
14
|
doExecute(constructor) {
|
|
14
15
|
const meta = this.#findConstructorMeta(constructor);
|
|
15
16
|
(0, utils_1.assert)(meta, `Constructor message not found: ${constructor}`);
|
|
16
|
-
const callFn = (...params) => {
|
|
17
|
+
const callFn = async (...params) => {
|
|
17
18
|
const { args } = meta;
|
|
18
19
|
(0, utils_1.assert)(params.length === args.length + 1, `Expected ${args.length + 1} arguments, got ${params.length}`);
|
|
19
20
|
const callOptions = params[args.length];
|
|
@@ -26,7 +27,19 @@ class ConstructorQueryExecutor extends Executor_js_1.Executor {
|
|
|
26
27
|
type: (0, utils_1.isWasm)(this.code) ? 'Upload' : 'Existing',
|
|
27
28
|
value: this.code,
|
|
28
29
|
};
|
|
29
|
-
|
|
30
|
+
const raw = await this.api.call.contractsApi.instantiate(caller, value, gasLimit, storageDepositLimit, code, bytes, salt);
|
|
31
|
+
if (raw.result.isErr) {
|
|
32
|
+
throw new errors_js_1.ContractInstantiateDispatchError(raw.result.err, raw);
|
|
33
|
+
}
|
|
34
|
+
const data = this.tryDecode(meta, raw.result.value.result.data);
|
|
35
|
+
if (data.isErr) {
|
|
36
|
+
throw new errors_js_1.ContractInstantiateLangError(data.err, raw);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
raw,
|
|
40
|
+
data: data.value,
|
|
41
|
+
address: raw.result.value.accountId,
|
|
42
|
+
};
|
|
30
43
|
};
|
|
31
44
|
callFn.meta = meta;
|
|
32
45
|
return callFn;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QueryExecutor = void 0;
|
|
4
4
|
const utils_1 = require("@dedot/utils");
|
|
5
|
+
const errors_js_1 = require("../errors.js");
|
|
5
6
|
const utils_js_1 = require("../utils.js");
|
|
6
7
|
const Executor_js_1 = require("./Executor.js");
|
|
7
8
|
class QueryExecutor extends Executor_js_1.Executor {
|
|
@@ -17,17 +18,17 @@ class QueryExecutor extends Executor_js_1.Executor {
|
|
|
17
18
|
const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
|
|
18
19
|
const bytes = (0, utils_1.u8aToHex)((0, utils_1.concatU8a)((0, utils_1.hexToU8a)(meta.selector), ...formattedInputs));
|
|
19
20
|
const raw = await this.api.call.contractsApi.call(caller, this.address, value, gasLimit, storageDepositLimit, bytes);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
if (raw.result.isErr) {
|
|
22
|
+
throw new errors_js_1.ContractDispatchError(raw.result.err, raw);
|
|
23
|
+
}
|
|
24
|
+
const data = this.tryDecode(meta, raw.result.value.data);
|
|
25
|
+
if (data.isErr) {
|
|
26
|
+
throw new errors_js_1.ContractLangError(data.err, raw);
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
data: data.value,
|
|
30
|
+
raw,
|
|
31
|
+
};
|
|
31
32
|
};
|
|
32
33
|
callFn.meta = meta;
|
|
33
34
|
return callFn;
|
package/cjs/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./utils.js"), exports);
|
|
18
|
+
__exportStar(require("./errors.js"), exports);
|
|
18
19
|
__exportStar(require("./executor/index.js"), exports);
|
|
19
20
|
__exportStar(require("./types/index.js"), exports);
|
|
20
21
|
__exportStar(require("./TypinkRegistry.js"), exports);
|
package/errors.d.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { DispatchError } from '@dedot/codecs';
|
|
2
|
+
import { DedotError } from '@dedot/utils';
|
|
3
|
+
import { ContractCallResult, ContractInstantiateResult, GenericContractApi } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Represents an error that occurred during the instantiation of a smart contract.
|
|
6
|
+
* This class extends the base `DedotError` and includes a `raw` property of type `ContractInstantiateResult`.
|
|
7
|
+
*
|
|
8
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
9
|
+
*
|
|
10
|
+
* @extends DedotError
|
|
11
|
+
*/
|
|
12
|
+
export declare class ContractInstantiateError<ContractApi extends GenericContractApi = GenericContractApi> extends DedotError {
|
|
13
|
+
/**
|
|
14
|
+
* The raw result of the contract instantiation.
|
|
15
|
+
*/
|
|
16
|
+
raw: ContractInstantiateResult<ContractApi['types']['ChainApi']>;
|
|
17
|
+
/**
|
|
18
|
+
* Constructs a new `ContractInstantiateError` instance.
|
|
19
|
+
*
|
|
20
|
+
* @param raw - The raw result of the contract instantiation.
|
|
21
|
+
*/
|
|
22
|
+
constructor(raw: ContractInstantiateResult<ContractApi['types']['ChainApi']>);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Represents an error that occurred during the dispatch phase of contract instantiation.
|
|
26
|
+
* This class extends `ContractInstantiateError` and includes a `DispatchError` property.
|
|
27
|
+
*
|
|
28
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
29
|
+
*
|
|
30
|
+
* @extends ContractInstantiateError
|
|
31
|
+
*/
|
|
32
|
+
export declare class ContractInstantiateDispatchError<ContractApi extends GenericContractApi = GenericContractApi> extends ContractInstantiateError<ContractApi> {
|
|
33
|
+
/**
|
|
34
|
+
* The error that occurred during the dispatch phase.
|
|
35
|
+
*/
|
|
36
|
+
dispatchError: DispatchError;
|
|
37
|
+
/**
|
|
38
|
+
* Constructs a new `ContractInstantiateDispatchError` instance.
|
|
39
|
+
*
|
|
40
|
+
* @param err - The `DispatchError` that occurred during the dispatch phase.
|
|
41
|
+
* @param raw - The raw result of the contract instantiation.
|
|
42
|
+
*/
|
|
43
|
+
constructor(err: DispatchError, raw: ContractInstantiateResult<ContractApi['types']['ChainApi']>);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Represents an error that occurred during the instantiation of a smart contract due to a language-specific error.
|
|
47
|
+
* This class extends `ContractInstantiateError` and includes a `LangError` property.
|
|
48
|
+
*
|
|
49
|
+
* Ref: https://use.ink/faq/migrating-from-ink-3-to-4#:~:text=Add%20support%20for,equivalent%20LangError.
|
|
50
|
+
*
|
|
51
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
52
|
+
*
|
|
53
|
+
* @extends ContractInstantiateError
|
|
54
|
+
*/
|
|
55
|
+
export declare class ContractInstantiateLangError<ContractApi extends GenericContractApi = GenericContractApi> extends ContractInstantiateError<ContractApi> {
|
|
56
|
+
/**
|
|
57
|
+
* The language-specific error that occurred during the instantiation.
|
|
58
|
+
*/
|
|
59
|
+
langError: ContractApi['types']['LangError'];
|
|
60
|
+
/**
|
|
61
|
+
* Constructs a new `ContractInstantiateLangError` instance.
|
|
62
|
+
*
|
|
63
|
+
* @param err - The `LangError` that occurred during the instantiation phase.
|
|
64
|
+
* @param raw - The raw result of the contract instantiation.
|
|
65
|
+
*/
|
|
66
|
+
constructor(err: ContractApi['types']['LangError'], raw: ContractInstantiateResult<ContractApi['types']['ChainApi']>);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Represents an error that occurred during the execution of a smart contract call.
|
|
70
|
+
* This class extends the base `DedotError` and includes a `raw` property of type `ContractCallResult`.
|
|
71
|
+
*
|
|
72
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
73
|
+
*
|
|
74
|
+
* @extends DedotError
|
|
75
|
+
*/
|
|
76
|
+
export declare class ContractExecutionError<ContractApi extends GenericContractApi = GenericContractApi> extends DedotError {
|
|
77
|
+
/**
|
|
78
|
+
* The raw result of the contract call.
|
|
79
|
+
*/
|
|
80
|
+
raw: ContractCallResult<ContractApi['types']['ChainApi']>;
|
|
81
|
+
/**
|
|
82
|
+
* Constructs a new `ContractExecutionError` instance.
|
|
83
|
+
*
|
|
84
|
+
* @param raw - The raw result of the contract call.
|
|
85
|
+
*/
|
|
86
|
+
constructor(raw: ContractCallResult<ContractApi['types']['ChainApi']>);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Represents an error that occurred during the execution of a smart contract call due to a dispatch error.
|
|
90
|
+
* This class extends `ContractExecutionError` and includes a `DispatchError` property.
|
|
91
|
+
*
|
|
92
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
93
|
+
*
|
|
94
|
+
* @extends ContractExecutionError
|
|
95
|
+
*/
|
|
96
|
+
export declare class ContractDispatchError<ContractApi extends GenericContractApi = GenericContractApi> extends ContractExecutionError<ContractApi> {
|
|
97
|
+
/**
|
|
98
|
+
* The error that occurred during the dispatch phase.
|
|
99
|
+
*/
|
|
100
|
+
dispatchError: DispatchError;
|
|
101
|
+
/**
|
|
102
|
+
* Constructs a new `ContractDispatchError` instance.
|
|
103
|
+
*
|
|
104
|
+
* @param err - The `DispatchError` that occurred during the dispatch phase.
|
|
105
|
+
* @param raw - The raw result of the contract call.
|
|
106
|
+
*/
|
|
107
|
+
constructor(err: DispatchError, raw: ContractCallResult<ContractApi['types']['ChainApi']>);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Represents an error that occurred during the execution of a smart contract call due to a language-specific error.
|
|
111
|
+
* This class extends `ContractExecutionError` and includes a `LangError` property.
|
|
112
|
+
*
|
|
113
|
+
* Ref: https://use.ink/faq/migrating-from-ink-3-to-4#:~:text=Add%20support%20for,equivalent%20LangError.
|
|
114
|
+
*
|
|
115
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
116
|
+
*
|
|
117
|
+
* @extends ContractExecutionError
|
|
118
|
+
*/
|
|
119
|
+
export declare class ContractLangError<ContractApi extends GenericContractApi = GenericContractApi> extends ContractExecutionError<ContractApi> {
|
|
120
|
+
/**
|
|
121
|
+
* The language-specific error that occurred during the execution.
|
|
122
|
+
*/
|
|
123
|
+
langError: ContractApi['types']['LangError'];
|
|
124
|
+
/**
|
|
125
|
+
* Constructs a new `ContractLangError` instance.
|
|
126
|
+
*
|
|
127
|
+
* @param err - The `LangError` that occurred during the execution phase.
|
|
128
|
+
* @param raw - The raw result of the contract call.
|
|
129
|
+
*/
|
|
130
|
+
constructor(err: ContractApi['types']['LangError'], raw: ContractCallResult<ContractApi['types']['ChainApi']>);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Checks if the provided error is an instance of `ContractExecutionError`.
|
|
134
|
+
*
|
|
135
|
+
* This function is used to determine if a given error is a result of an execution error during a smart contract call.
|
|
136
|
+
*
|
|
137
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
138
|
+
*
|
|
139
|
+
* @param e - The error to be checked.
|
|
140
|
+
*
|
|
141
|
+
* @returns `true` if the error is an instance of `ContractExecutionError`, `false` otherwise.
|
|
142
|
+
*/
|
|
143
|
+
export declare function isContractExecutionError<ContractApi extends GenericContractApi = GenericContractApi>(e: Error): e is ContractExecutionError<ContractApi>;
|
|
144
|
+
/**
|
|
145
|
+
* Checks if the provided error is an instance of `ContractDispatchError`.
|
|
146
|
+
*
|
|
147
|
+
* This function is used to determine if a given error is a result of a dispatch error during a smart contract call.
|
|
148
|
+
*
|
|
149
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
150
|
+
*
|
|
151
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
152
|
+
*
|
|
153
|
+
* @returns `true` if the error is an instance of `ContractDispatchError`, `false` otherwise.
|
|
154
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractDispatchError`.
|
|
155
|
+
*/
|
|
156
|
+
export declare function isContractDispatchError<ContractApi extends GenericContractApi = GenericContractApi>(e: Error): e is ContractDispatchError<ContractApi>;
|
|
157
|
+
/**
|
|
158
|
+
* Checks if the provided error is an instance of `ContractLangError`.
|
|
159
|
+
*
|
|
160
|
+
* This function is used to determine if a given error is a result of a language-specific error during a smart contract call.
|
|
161
|
+
*
|
|
162
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
163
|
+
*
|
|
164
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
165
|
+
*
|
|
166
|
+
* @returns `true` if the error is an instance of `ContractLangError`, `false` otherwise.
|
|
167
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractLangError`.
|
|
168
|
+
*/
|
|
169
|
+
export declare function isContractLangError<ContractApi extends GenericContractApi = GenericContractApi>(e: Error): e is ContractLangError<ContractApi>;
|
|
170
|
+
/**
|
|
171
|
+
* Checks if the provided error is an instance of `ContractInstantiateError`.
|
|
172
|
+
*
|
|
173
|
+
* This function is used to determine if a given error is a result of an execution error during the instantiation of a smart contract.
|
|
174
|
+
*
|
|
175
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
176
|
+
*
|
|
177
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
178
|
+
*
|
|
179
|
+
* @returns `true` if the error is an instance of `ContractInstantiateError`, `false` otherwise.
|
|
180
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractInstantiateError`.
|
|
181
|
+
*/
|
|
182
|
+
export declare function isContractInstantiateError<ContractApi extends GenericContractApi = GenericContractApi>(e: Error): e is ContractInstantiateError<ContractApi>;
|
|
183
|
+
/**
|
|
184
|
+
* Checks if the provided error is an instance of `ContractInstantiateDispatchError`.
|
|
185
|
+
*
|
|
186
|
+
* This function is used to determine if a given error is a result of a dispatch error during the instantiation of a smart contract.
|
|
187
|
+
*
|
|
188
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
189
|
+
*
|
|
190
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
191
|
+
*
|
|
192
|
+
* @returns `true` if the error is an instance of `ContractInstantiateDispatchError`, `false` otherwise.
|
|
193
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractInstantiateDispatchError`.
|
|
194
|
+
*/
|
|
195
|
+
export declare function isContractInstantiateDispatchError<ContractApi extends GenericContractApi = GenericContractApi>(e: Error): e is ContractInstantiateDispatchError<ContractApi>;
|
|
196
|
+
/**
|
|
197
|
+
* Checks if the provided error is an instance of `ContractInstantiateLangError`.
|
|
198
|
+
*
|
|
199
|
+
* This function is used to determine if a given error is a result of a language-specific error during the instantiation of a smart contract.
|
|
200
|
+
*
|
|
201
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
202
|
+
*
|
|
203
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
204
|
+
*
|
|
205
|
+
* @returns `true` if the error is an instance of `ContractInstantiateLangError`, `false` otherwise.
|
|
206
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractInstantiateLangError`.
|
|
207
|
+
*/
|
|
208
|
+
export declare function isContractInstantiateLangError<ContractApi extends GenericContractApi = GenericContractApi>(e: Error): e is ContractInstantiateLangError<ContractApi>;
|
package/errors.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { DedotError } from '@dedot/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Represents an error that occurred during the instantiation of a smart contract.
|
|
4
|
+
* This class extends the base `DedotError` and includes a `raw` property of type `ContractInstantiateResult`.
|
|
5
|
+
*
|
|
6
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
7
|
+
*
|
|
8
|
+
* @extends DedotError
|
|
9
|
+
*/
|
|
10
|
+
export class ContractInstantiateError extends DedotError {
|
|
11
|
+
/**
|
|
12
|
+
* The raw result of the contract instantiation.
|
|
13
|
+
*/
|
|
14
|
+
raw;
|
|
15
|
+
/**
|
|
16
|
+
* Constructs a new `ContractInstantiateError` instance.
|
|
17
|
+
*
|
|
18
|
+
* @param raw - The raw result of the contract instantiation.
|
|
19
|
+
*/
|
|
20
|
+
constructor(raw) {
|
|
21
|
+
super();
|
|
22
|
+
this.raw = raw;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Represents an error that occurred during the dispatch phase of contract instantiation.
|
|
27
|
+
* This class extends `ContractInstantiateError` and includes a `DispatchError` property.
|
|
28
|
+
*
|
|
29
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
30
|
+
*
|
|
31
|
+
* @extends ContractInstantiateError
|
|
32
|
+
*/
|
|
33
|
+
export class ContractInstantiateDispatchError extends ContractInstantiateError {
|
|
34
|
+
/**
|
|
35
|
+
* The error that occurred during the dispatch phase.
|
|
36
|
+
*/
|
|
37
|
+
dispatchError;
|
|
38
|
+
/**
|
|
39
|
+
* Constructs a new `ContractInstantiateDispatchError` instance.
|
|
40
|
+
*
|
|
41
|
+
* @param err - The `DispatchError` that occurred during the dispatch phase.
|
|
42
|
+
* @param raw - The raw result of the contract instantiation.
|
|
43
|
+
*/
|
|
44
|
+
constructor(err, raw) {
|
|
45
|
+
super(raw);
|
|
46
|
+
this.dispatchError = err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Represents an error that occurred during the instantiation of a smart contract due to a language-specific error.
|
|
51
|
+
* This class extends `ContractInstantiateError` and includes a `LangError` property.
|
|
52
|
+
*
|
|
53
|
+
* Ref: https://use.ink/faq/migrating-from-ink-3-to-4#:~:text=Add%20support%20for,equivalent%20LangError.
|
|
54
|
+
*
|
|
55
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
56
|
+
*
|
|
57
|
+
* @extends ContractInstantiateError
|
|
58
|
+
*/
|
|
59
|
+
export class ContractInstantiateLangError extends ContractInstantiateError {
|
|
60
|
+
/**
|
|
61
|
+
* The language-specific error that occurred during the instantiation.
|
|
62
|
+
*/
|
|
63
|
+
langError;
|
|
64
|
+
/**
|
|
65
|
+
* Constructs a new `ContractInstantiateLangError` instance.
|
|
66
|
+
*
|
|
67
|
+
* @param err - The `LangError` that occurred during the instantiation phase.
|
|
68
|
+
* @param raw - The raw result of the contract instantiation.
|
|
69
|
+
*/
|
|
70
|
+
constructor(err, raw) {
|
|
71
|
+
super(raw);
|
|
72
|
+
this.langError = err;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Represents an error that occurred during the execution of a smart contract call.
|
|
77
|
+
* This class extends the base `DedotError` and includes a `raw` property of type `ContractCallResult`.
|
|
78
|
+
*
|
|
79
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
80
|
+
*
|
|
81
|
+
* @extends DedotError
|
|
82
|
+
*/
|
|
83
|
+
export class ContractExecutionError extends DedotError {
|
|
84
|
+
/**
|
|
85
|
+
* The raw result of the contract call.
|
|
86
|
+
*/
|
|
87
|
+
raw;
|
|
88
|
+
/**
|
|
89
|
+
* Constructs a new `ContractExecutionError` instance.
|
|
90
|
+
*
|
|
91
|
+
* @param raw - The raw result of the contract call.
|
|
92
|
+
*/
|
|
93
|
+
constructor(raw) {
|
|
94
|
+
super();
|
|
95
|
+
this.raw = raw;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Represents an error that occurred during the execution of a smart contract call due to a dispatch error.
|
|
100
|
+
* This class extends `ContractExecutionError` and includes a `DispatchError` property.
|
|
101
|
+
*
|
|
102
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
103
|
+
*
|
|
104
|
+
* @extends ContractExecutionError
|
|
105
|
+
*/
|
|
106
|
+
export class ContractDispatchError extends ContractExecutionError {
|
|
107
|
+
/**
|
|
108
|
+
* The error that occurred during the dispatch phase.
|
|
109
|
+
*/
|
|
110
|
+
dispatchError;
|
|
111
|
+
/**
|
|
112
|
+
* Constructs a new `ContractDispatchError` instance.
|
|
113
|
+
*
|
|
114
|
+
* @param err - The `DispatchError` that occurred during the dispatch phase.
|
|
115
|
+
* @param raw - The raw result of the contract call.
|
|
116
|
+
*/
|
|
117
|
+
constructor(err, raw) {
|
|
118
|
+
super(raw);
|
|
119
|
+
this.dispatchError = err;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Represents an error that occurred during the execution of a smart contract call due to a language-specific error.
|
|
124
|
+
* This class extends `ContractExecutionError` and includes a `LangError` property.
|
|
125
|
+
*
|
|
126
|
+
* Ref: https://use.ink/faq/migrating-from-ink-3-to-4#:~:text=Add%20support%20for,equivalent%20LangError.
|
|
127
|
+
*
|
|
128
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
129
|
+
*
|
|
130
|
+
* @extends ContractExecutionError
|
|
131
|
+
*/
|
|
132
|
+
export class ContractLangError extends ContractExecutionError {
|
|
133
|
+
/**
|
|
134
|
+
* The language-specific error that occurred during the execution.
|
|
135
|
+
*/
|
|
136
|
+
langError;
|
|
137
|
+
/**
|
|
138
|
+
* Constructs a new `ContractLangError` instance.
|
|
139
|
+
*
|
|
140
|
+
* @param err - The `LangError` that occurred during the execution phase.
|
|
141
|
+
* @param raw - The raw result of the contract call.
|
|
142
|
+
*/
|
|
143
|
+
constructor(err, raw) {
|
|
144
|
+
super(raw);
|
|
145
|
+
this.langError = err;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Checks if the provided error is an instance of `ContractExecutionError`.
|
|
150
|
+
*
|
|
151
|
+
* This function is used to determine if a given error is a result of an execution error during a smart contract call.
|
|
152
|
+
*
|
|
153
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
154
|
+
*
|
|
155
|
+
* @param e - The error to be checked.
|
|
156
|
+
*
|
|
157
|
+
* @returns `true` if the error is an instance of `ContractExecutionError`, `false` otherwise.
|
|
158
|
+
*/
|
|
159
|
+
export function isContractExecutionError(e) {
|
|
160
|
+
return e instanceof ContractExecutionError;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Checks if the provided error is an instance of `ContractDispatchError`.
|
|
164
|
+
*
|
|
165
|
+
* This function is used to determine if a given error is a result of a dispatch error during a smart contract call.
|
|
166
|
+
*
|
|
167
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
168
|
+
*
|
|
169
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
170
|
+
*
|
|
171
|
+
* @returns `true` if the error is an instance of `ContractDispatchError`, `false` otherwise.
|
|
172
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractDispatchError`.
|
|
173
|
+
*/
|
|
174
|
+
export function isContractDispatchError(e) {
|
|
175
|
+
return e instanceof ContractDispatchError;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Checks if the provided error is an instance of `ContractLangError`.
|
|
179
|
+
*
|
|
180
|
+
* This function is used to determine if a given error is a result of a language-specific error during a smart contract call.
|
|
181
|
+
*
|
|
182
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
183
|
+
*
|
|
184
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
185
|
+
*
|
|
186
|
+
* @returns `true` if the error is an instance of `ContractLangError`, `false` otherwise.
|
|
187
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractLangError`.
|
|
188
|
+
*/
|
|
189
|
+
export function isContractLangError(e) {
|
|
190
|
+
return e instanceof ContractLangError;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Checks if the provided error is an instance of `ContractInstantiateError`.
|
|
194
|
+
*
|
|
195
|
+
* This function is used to determine if a given error is a result of an execution error during the instantiation of a smart contract.
|
|
196
|
+
*
|
|
197
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
198
|
+
*
|
|
199
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
200
|
+
*
|
|
201
|
+
* @returns `true` if the error is an instance of `ContractInstantiateError`, `false` otherwise.
|
|
202
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractInstantiateError`.
|
|
203
|
+
*/
|
|
204
|
+
export function isContractInstantiateError(e) {
|
|
205
|
+
return e instanceof ContractInstantiateError;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Checks if the provided error is an instance of `ContractInstantiateDispatchError`.
|
|
209
|
+
*
|
|
210
|
+
* This function is used to determine if a given error is a result of a dispatch error during the instantiation of a smart contract.
|
|
211
|
+
*
|
|
212
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
213
|
+
*
|
|
214
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
215
|
+
*
|
|
216
|
+
* @returns `true` if the error is an instance of `ContractInstantiateDispatchError`, `false` otherwise.
|
|
217
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractInstantiateDispatchError`.
|
|
218
|
+
*/
|
|
219
|
+
export function isContractInstantiateDispatchError(e) {
|
|
220
|
+
return e instanceof ContractInstantiateDispatchError;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Checks if the provided error is an instance of `ContractInstantiateLangError`.
|
|
224
|
+
*
|
|
225
|
+
* This function is used to determine if a given error is a result of a language-specific error during the instantiation of a smart contract.
|
|
226
|
+
*
|
|
227
|
+
* @template ContractApi - The type of the contract API. Defaults to `GenericContractApi`.
|
|
228
|
+
*
|
|
229
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
230
|
+
*
|
|
231
|
+
* @returns `true` if the error is an instance of `ContractInstantiateLangError`, `false` otherwise.
|
|
232
|
+
* This function returns a boolean value indicating whether the provided error is of type `ContractInstantiateLangError`.
|
|
233
|
+
*/
|
|
234
|
+
export function isContractInstantiateLangError(e) {
|
|
235
|
+
return e instanceof ContractInstantiateLangError;
|
|
236
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assert, concatU8a, hexToU8a, isWasm, u8aToHex } from '@dedot/utils';
|
|
2
|
+
import { ContractInstantiateDispatchError, ContractInstantiateLangError } from '../errors.js';
|
|
2
3
|
import { normalizeLabel } from '../utils.js';
|
|
3
4
|
import { Executor } from './Executor.js';
|
|
4
5
|
export class ConstructorQueryExecutor extends Executor {
|
|
@@ -10,7 +11,7 @@ export class ConstructorQueryExecutor extends Executor {
|
|
|
10
11
|
doExecute(constructor) {
|
|
11
12
|
const meta = this.#findConstructorMeta(constructor);
|
|
12
13
|
assert(meta, `Constructor message not found: ${constructor}`);
|
|
13
|
-
const callFn = (...params) => {
|
|
14
|
+
const callFn = async (...params) => {
|
|
14
15
|
const { args } = meta;
|
|
15
16
|
assert(params.length === args.length + 1, `Expected ${args.length + 1} arguments, got ${params.length}`);
|
|
16
17
|
const callOptions = params[args.length];
|
|
@@ -23,7 +24,19 @@ export class ConstructorQueryExecutor extends Executor {
|
|
|
23
24
|
type: isWasm(this.code) ? 'Upload' : 'Existing',
|
|
24
25
|
value: this.code,
|
|
25
26
|
};
|
|
26
|
-
|
|
27
|
+
const raw = await this.api.call.contractsApi.instantiate(caller, value, gasLimit, storageDepositLimit, code, bytes, salt);
|
|
28
|
+
if (raw.result.isErr) {
|
|
29
|
+
throw new ContractInstantiateDispatchError(raw.result.err, raw);
|
|
30
|
+
}
|
|
31
|
+
const data = this.tryDecode(meta, raw.result.value.result.data);
|
|
32
|
+
if (data.isErr) {
|
|
33
|
+
throw new ContractInstantiateLangError(data.err, raw);
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
raw,
|
|
37
|
+
data: data.value,
|
|
38
|
+
address: raw.result.value.accountId,
|
|
39
|
+
};
|
|
27
40
|
};
|
|
28
41
|
callFn.meta = meta;
|
|
29
42
|
return callFn;
|
package/executor/Executor.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { SubstrateApi } from '@dedot/api/chaintypes';
|
|
|
3
3
|
import { AccountId32 } from '@dedot/codecs';
|
|
4
4
|
import { GenericSubstrateApi, RpcVersion } from '@dedot/types';
|
|
5
5
|
import { TypinkRegistry } from '../TypinkRegistry.js';
|
|
6
|
-
import { ContractMessageArg,
|
|
6
|
+
import { ContractMessageArg, ContractMessage } from '../types/index.js';
|
|
7
7
|
import { ContractMetadata } from '../types/index.js';
|
|
8
8
|
export declare abstract class Executor<ChainApi extends GenericSubstrateApi = SubstrateApi[RpcVersion]> {
|
|
9
9
|
#private;
|
|
@@ -14,5 +14,5 @@ export declare abstract class Executor<ChainApi extends GenericSubstrateApi = Su
|
|
|
14
14
|
get registry(): TypinkRegistry;
|
|
15
15
|
abstract doExecute(...paths: string[]): unknown;
|
|
16
16
|
tryEncode(param: ContractMessageArg, value: any): Uint8Array;
|
|
17
|
-
tryDecode(meta:
|
|
17
|
+
tryDecode(meta: ContractMessage, raw: any): unknown;
|
|
18
18
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assert, concatU8a, hexToU8a, u8aToHex } from '@dedot/utils';
|
|
2
|
+
import { ContractDispatchError, ContractLangError } from '../errors.js';
|
|
2
3
|
import { normalizeLabel } from '../utils.js';
|
|
3
4
|
import { Executor } from './Executor.js';
|
|
4
5
|
export class QueryExecutor extends Executor {
|
|
@@ -14,17 +15,17 @@ export class QueryExecutor extends Executor {
|
|
|
14
15
|
const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
|
|
15
16
|
const bytes = u8aToHex(concatU8a(hexToU8a(meta.selector), ...formattedInputs));
|
|
16
17
|
const raw = await this.api.call.contractsApi.call(caller, this.address, value, gasLimit, storageDepositLimit, bytes);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
if (raw.result.isErr) {
|
|
19
|
+
throw new ContractDispatchError(raw.result.err, raw);
|
|
20
|
+
}
|
|
21
|
+
const data = this.tryDecode(meta, raw.result.value.data);
|
|
22
|
+
if (data.isErr) {
|
|
23
|
+
throw new ContractLangError(data.err, raw);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
data: data.value,
|
|
27
|
+
raw,
|
|
28
|
+
};
|
|
28
29
|
};
|
|
29
30
|
callFn.meta = meta;
|
|
30
31
|
return callFn;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/contracts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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.2.0",
|
|
22
|
+
"@dedot/codecs": "0.2.0",
|
|
23
|
+
"@dedot/types": "0.2.0",
|
|
24
|
+
"@dedot/utils": "0.2.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": "f29e8784997251518df1e33ef782f1d87207b126",
|
|
32
32
|
"module": "./index.js",
|
|
33
33
|
"types": "./index.d.ts",
|
|
34
34
|
"exports": {
|
package/types/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { SubstrateApi } from '@dedot/api/chaintypes';
|
|
2
|
-
import { AccountId32Like, BytesLike,
|
|
2
|
+
import { AccountId32, AccountId32Like, BytesLike, Weight } from '@dedot/codecs';
|
|
3
3
|
import { AnyFunc, AsyncMethod, GenericSubstrateApi, RpcVersion, 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';
|
|
7
7
|
export * from './shared.js';
|
|
8
8
|
export type ContractEventMeta = ContractEventV4 | ContractEventV5;
|
|
9
|
-
export type GenericContractCallResult<DecodedData, ContractResult> =
|
|
10
|
-
isOk: true;
|
|
9
|
+
export type GenericContractCallResult<DecodedData = any, ContractResult = any> = {
|
|
11
10
|
data: DecodedData;
|
|
12
|
-
} | {
|
|
13
|
-
isOk: false;
|
|
14
|
-
err: DispatchError;
|
|
15
|
-
}) & {
|
|
16
11
|
raw: ContractResult;
|
|
17
12
|
};
|
|
13
|
+
export type GenericConstructorCallResult<DecodedData = any, ContractResult = any> = {
|
|
14
|
+
data: DecodedData;
|
|
15
|
+
raw: ContractResult;
|
|
16
|
+
address: AccountId32;
|
|
17
|
+
};
|
|
18
18
|
export type ContractCallResult<ChainApi extends GenericSubstrateApi> = Awaited<ReturnType<ChainApi['call']['contractsApi']['call']>>;
|
|
19
19
|
export type ContractInstantiateResult<ChainApi extends GenericSubstrateApi> = Awaited<ReturnType<ChainApi['call']['contractsApi']['instantiate']>>;
|
|
20
20
|
export type ContractSubmittableExtrinsic<ChainApi extends GenericSubstrateApi> = ReturnType<ChainApi['tx']['contracts']['call']>;
|
|
@@ -47,7 +47,7 @@ export type GenericContractQueryCall<ChainApi extends GenericSubstrateApi, F ext
|
|
|
47
47
|
export type GenericContractTxCall<ChainApi extends GenericSubstrateApi, F extends AnyFunc = (...args: any[]) => ContractSubmittableExtrinsic<ChainApi>> = F & {
|
|
48
48
|
meta: ContractCallMessage;
|
|
49
49
|
};
|
|
50
|
-
export type GenericConstructorQueryCall<ChainApi extends GenericSubstrateApi, F extends AsyncMethod = (...args: any[]) => Promise<ContractInstantiateResult<ChainApi
|
|
50
|
+
export type GenericConstructorQueryCall<ChainApi extends GenericSubstrateApi, F extends AsyncMethod = (...args: any[]) => Promise<GenericConstructorCallResult<any, ContractInstantiateResult<ChainApi>>>> = F & {
|
|
51
51
|
meta: ContractConstructorMessage;
|
|
52
52
|
};
|
|
53
53
|
export type GenericConstructorTxCall<ChainApi extends GenericSubstrateApi, F extends AnyFunc = (...args: any[]) => GenericInstantiateSubmittableExtrinsic<ChainApi>> = F & {
|
|
@@ -79,10 +79,15 @@ export interface GenericContractEvent<EventName extends string = string, Data ex
|
|
|
79
79
|
export interface GenericContractEvents<_ extends GenericSubstrateApi> {
|
|
80
80
|
[event: string]: GenericContractEvent;
|
|
81
81
|
}
|
|
82
|
+
export type GenericInkLangError = 'CouldNotReadInput' | any;
|
|
82
83
|
export interface GenericContractApi<Rv extends RpcVersion = RpcVersion, ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> {
|
|
83
84
|
query: GenericContractQuery<ChainApi[Rv]>;
|
|
84
85
|
tx: GenericContractTx<ChainApi[Rv]>;
|
|
85
86
|
constructorQuery: GenericConstructorQuery<ChainApi[Rv]>;
|
|
86
87
|
constructorTx: GenericConstructorTx<ChainApi[Rv]>;
|
|
87
88
|
events: GenericContractEvents<ChainApi[Rv]>;
|
|
89
|
+
types: {
|
|
90
|
+
LangError: GenericInkLangError;
|
|
91
|
+
ChainApi: ChainApi[Rv];
|
|
92
|
+
};
|
|
88
93
|
}
|