@dedot/contracts 0.17.0 → 0.17.1-next.db98ff20.1
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 +5 -4
- package/Contract.js +42 -15
- package/ContractDeployer.d.ts +5 -4
- package/ContractDeployer.js +27 -10
- package/SolRegistry.d.ts +22 -0
- package/SolRegistry.js +64 -0
- package/TypinkRegistry.d.ts +2 -1
- package/TypinkRegistry.js +3 -1
- package/cjs/Contract.js +43 -16
- package/cjs/ContractDeployer.js +25 -8
- package/cjs/SolRegistry.js +68 -0
- package/cjs/TypinkRegistry.js +2 -0
- package/cjs/errors.js +75 -1
- package/cjs/executor/index.js +2 -5
- package/cjs/executor/{ConstructorQueryExecutor.js → ink/ConstructorQueryExecutor.js} +3 -2
- package/cjs/executor/{ConstructorTxExecutor.js → ink/ConstructorTxExecutor.js} +4 -3
- package/cjs/executor/{QueryExecutor.js → ink/QueryExecutor.js} +4 -3
- package/cjs/executor/{TxExecutor.js → ink/TxExecutor.js} +1 -1
- package/cjs/executor/{abstract → ink/abstract}/ContractExecutor.js +1 -1
- package/cjs/executor/{abstract → ink/abstract}/DeployerExecutor.js +1 -1
- package/cjs/executor/ink/index.js +22 -0
- package/cjs/executor/sol/SolConstructorQueryExecutor.js +81 -0
- package/cjs/executor/sol/SolConstructorTxExecutor.js +123 -0
- package/cjs/executor/sol/SolEventExecutor.js +57 -0
- package/cjs/executor/sol/SolQueryExecutor.js +83 -0
- package/cjs/executor/sol/SolTxExecutor.js +62 -0
- package/cjs/executor/sol/abstract/SolContractExecutor.js +12 -0
- package/cjs/executor/sol/abstract/SolDeployerExecutor.js +12 -0
- package/cjs/executor/sol/abstract/SolExecutor.js +17 -0
- package/cjs/executor/sol/abstract/index.js +19 -0
- package/cjs/executor/sol/index.js +22 -0
- package/cjs/types/index.js +2 -3
- package/cjs/types/ink/index.js +20 -0
- package/cjs/types/ink/v6.js +2 -0
- package/cjs/types/sol/abi.js +2 -0
- package/cjs/types/sol/index.js +17 -0
- package/cjs/utils/address.js +2 -2
- package/cjs/utils/ensure.js +40 -23
- package/cjs/utils/types.js +21 -1
- package/errors.d.ts +64 -5
- package/errors.js +70 -0
- package/executor/index.d.ts +2 -5
- package/executor/index.js +2 -5
- package/executor/{ConstructorQueryExecutor.d.ts → ink/ConstructorQueryExecutor.d.ts} +1 -2
- package/executor/{ConstructorQueryExecutor.js → ink/ConstructorQueryExecutor.js} +3 -2
- package/executor/{ConstructorTxExecutor.d.ts → ink/ConstructorTxExecutor.d.ts} +1 -2
- package/executor/{ConstructorTxExecutor.js → ink/ConstructorTxExecutor.js} +4 -3
- package/executor/{EventExecutor.d.ts → ink/EventExecutor.d.ts} +2 -2
- package/executor/{QueryExecutor.d.ts → ink/QueryExecutor.d.ts} +1 -2
- package/executor/{QueryExecutor.js → ink/QueryExecutor.js} +4 -3
- package/executor/{TxExecutor.d.ts → ink/TxExecutor.d.ts} +1 -2
- package/executor/{TxExecutor.js → ink/TxExecutor.js} +1 -1
- package/executor/{abstract → ink/abstract}/ContractExecutor.d.ts +2 -2
- package/executor/{abstract → ink/abstract}/ContractExecutor.js +1 -1
- package/executor/{abstract → ink/abstract}/DeployerExecutor.d.ts +2 -2
- package/executor/{abstract → ink/abstract}/DeployerExecutor.js +1 -1
- package/executor/{abstract → ink/abstract}/Executor.d.ts +2 -2
- package/executor/ink/index.d.ts +6 -0
- package/executor/ink/index.js +6 -0
- package/executor/sol/SolConstructorQueryExecutor.d.ts +5 -0
- package/executor/sol/SolConstructorQueryExecutor.js +77 -0
- package/executor/sol/SolConstructorTxExecutor.d.ts +5 -0
- package/executor/sol/SolConstructorTxExecutor.js +119 -0
- package/executor/sol/SolEventExecutor.d.ts +6 -0
- package/executor/sol/SolEventExecutor.js +53 -0
- package/executor/sol/SolQueryExecutor.d.ts +5 -0
- package/executor/sol/SolQueryExecutor.js +79 -0
- package/executor/sol/SolTxExecutor.d.ts +5 -0
- package/executor/sol/SolTxExecutor.js +58 -0
- package/executor/sol/abstract/SolContractExecutor.d.ts +9 -0
- package/executor/sol/abstract/SolContractExecutor.js +8 -0
- package/executor/sol/abstract/SolDeployerExecutor.d.ts +11 -0
- package/executor/sol/abstract/SolDeployerExecutor.js +8 -0
- package/executor/sol/abstract/SolExecutor.d.ts +13 -0
- package/executor/sol/abstract/SolExecutor.js +13 -0
- package/executor/sol/abstract/index.d.ts +3 -0
- package/executor/sol/abstract/index.js +3 -0
- package/executor/sol/index.d.ts +6 -0
- package/executor/sol/index.js +6 -0
- package/package.json +7 -7
- package/storage/BaseLazyObject.d.ts +1 -1
- package/types/index.d.ts +44 -121
- package/types/index.js +2 -3
- package/types/ink/index.d.ts +9 -0
- package/types/ink/index.js +4 -0
- package/types/ink/shared.d.ts +100 -0
- package/types/ink/v6.js +1 -0
- package/types/shared.d.ts +80 -99
- package/types/sol/abi.d.ts +45 -0
- package/types/sol/abi.js +1 -0
- package/types/sol/index.d.ts +1 -0
- package/types/sol/index.js +1 -0
- package/utils/address.js +2 -2
- package/utils/ensure.d.ts +8 -7
- package/utils/ensure.js +38 -22
- package/utils/types.d.ts +20 -2
- package/utils/types.js +18 -0
- /package/cjs/executor/{EventExecutor.js → ink/EventExecutor.js} +0 -0
- /package/cjs/executor/{abstract → ink/abstract}/Executor.js +0 -0
- /package/cjs/executor/{abstract → ink/abstract}/index.js +0 -0
- /package/cjs/types/{v4.js → ink/shared.js} +0 -0
- /package/cjs/types/{v5.js → ink/v4.js} +0 -0
- /package/cjs/types/{v6.js → ink/v5.js} +0 -0
- /package/executor/{EventExecutor.js → ink/EventExecutor.js} +0 -0
- /package/executor/{abstract → ink/abstract}/Executor.js +0 -0
- /package/executor/{abstract → ink/abstract}/index.d.ts +0 -0
- /package/executor/{abstract → ink/abstract}/index.js +0 -0
- /package/types/{v4.js → ink/shared.js} +0 -0
- /package/types/{v4.d.ts → ink/v4.d.ts} +0 -0
- /package/types/{v5.js → ink/v4.js} +0 -0
- /package/types/{v5.d.ts → ink/v5.d.ts} +0 -0
- /package/types/{v6.js → ink/v5.js} +0 -0
- /package/types/{v6.d.ts → ink/v6.d.ts} +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolExecutor = void 0;
|
|
4
|
+
class SolExecutor {
|
|
5
|
+
client;
|
|
6
|
+
registry;
|
|
7
|
+
options;
|
|
8
|
+
constructor(client, registry, options = {}) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
this.registry = registry;
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
get abi() {
|
|
14
|
+
return this.registry.abi;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.SolExecutor = SolExecutor;
|
|
@@ -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("./SolExecutor.js"), exports);
|
|
18
|
+
__exportStar(require("./SolDeployerExecutor.js"), exports);
|
|
19
|
+
__exportStar(require("./SolContractExecutor.js"), exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
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("./SolTxExecutor.js"), exports);
|
|
18
|
+
__exportStar(require("./SolQueryExecutor.js"), exports);
|
|
19
|
+
__exportStar(require("./SolConstructorTxExecutor.js"), exports);
|
|
20
|
+
__exportStar(require("./SolConstructorQueryExecutor.js"), exports);
|
|
21
|
+
__exportStar(require("./SolEventExecutor.js"), exports);
|
|
22
|
+
__exportStar(require("./abstract/index.js"), exports);
|
package/cjs/types/index.js
CHANGED
|
@@ -14,7 +14,6 @@ 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("./ink/index.js"), exports);
|
|
18
|
+
__exportStar(require("./sol/index.js"), exports);
|
|
17
19
|
__exportStar(require("./shared.js"), exports);
|
|
18
|
-
__exportStar(require("./v4.js"), exports);
|
|
19
|
-
__exportStar(require("./v5.js"), exports);
|
|
20
|
-
__exportStar(require("./v6.js"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./shared.js"), exports);
|
|
18
|
+
__exportStar(require("./v4.js"), exports);
|
|
19
|
+
__exportStar(require("./v5.js"), exports);
|
|
20
|
+
__exportStar(require("./v6.js"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./abi.js"), exports);
|
package/cjs/utils/address.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toEvmAddress = exports.CREATE2 = exports.CREATE1 = void 0;
|
|
4
4
|
const codecs_1 = require("@dedot/codecs");
|
|
5
5
|
const utils_1 = require("@dedot/utils");
|
|
6
|
-
const
|
|
6
|
+
const utils_2 = require("viem/utils");
|
|
7
7
|
/**
|
|
8
8
|
* Calculate new contract's address is based on the deployer's address and a nonce
|
|
9
9
|
*
|
|
@@ -13,7 +13,7 @@ const rlp_1 = require("@ethereumjs/rlp");
|
|
|
13
13
|
* @param nonce
|
|
14
14
|
*/
|
|
15
15
|
function CREATE1(deployer, nonce) {
|
|
16
|
-
const encodedData =
|
|
16
|
+
const encodedData = (0, utils_2.toRlp)([new codecs_1.AccountId20(deployer).raw, (0, utils_1.toHex)(nonce)]);
|
|
17
17
|
const hash = (0, utils_1.keccakAsU8a)(encodedData);
|
|
18
18
|
return (0, utils_1.u8aToHex)(hash.subarray(12));
|
|
19
19
|
}
|
package/cjs/utils/ensure.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ensureParamsLength = exports.ensureSupportedContractMetadataVersion = exports.ensureValidCodeHashOrCode = exports.ensureValidContractAddress = exports.ensureContractPresence = exports.ensurePalletPresence = exports.ensureStorageApiSupports = void 0;
|
|
3
|
+
exports.ensureParamsLength = exports.ensureSupportedContractMetadataVersion = exports.ensureValidCodeHashOrCode = exports.ensureValidAccountId32Address = exports.ensureValidContractAddress = exports.ensureContractPresence = exports.ensurePalletPresence = exports.ensureStorageApiSupports = void 0;
|
|
4
4
|
const codecs_1 = require("@dedot/codecs");
|
|
5
5
|
const utils_1 = require("@dedot/utils");
|
|
6
6
|
const ensureStorageApiSupports = (version) => {
|
|
@@ -8,28 +8,36 @@ const ensureStorageApiSupports = (version) => {
|
|
|
8
8
|
(0, utils_1.assert)(numberedVersion >= 5, `Contract Storage Api Only Available for metadata version >= 5, current version: ${version}`);
|
|
9
9
|
};
|
|
10
10
|
exports.ensureStorageApiSupports = ensureStorageApiSupports;
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
!!client.call.reviveApi.call.meta && !!client.tx.revive.call.meta;
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
throw new utils_1.DedotError('Pallet Revive is not available');
|
|
18
|
-
}
|
|
11
|
+
function ensurePalletRevive(client) {
|
|
12
|
+
try {
|
|
13
|
+
!!client.call.reviveApi.call.meta && !!client.tx.revive.call.meta;
|
|
19
14
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
!!client.call.contractsApi.call.meta && !!client.tx.contracts.call.meta;
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
throw new utils_1.DedotError('Pallet Contracts is not available');
|
|
26
|
-
}
|
|
15
|
+
catch {
|
|
16
|
+
throw new utils_1.DedotError('Pallet Revive is not available');
|
|
27
17
|
}
|
|
28
18
|
}
|
|
19
|
+
function ensurePalletContracts(client) {
|
|
20
|
+
try {
|
|
21
|
+
!!client.call.contractsApi.call.meta && !!client.tx.contracts.call.meta;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new utils_1.DedotError('Pallet Contracts is not available');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function ensurePalletPresence(client, isRevive) {
|
|
28
|
+
isRevive ? ensurePalletRevive(client) : ensurePalletContracts(client);
|
|
29
|
+
}
|
|
29
30
|
exports.ensurePalletPresence = ensurePalletPresence;
|
|
30
|
-
async function ensureContractPresence(client,
|
|
31
|
+
async function ensureContractPresence(client, isRevive, address, cache) {
|
|
32
|
+
// Check cache first if available
|
|
33
|
+
if (cache) {
|
|
34
|
+
const cached = cache.get(`${isRevive}::${address}`);
|
|
35
|
+
if (cached) {
|
|
36
|
+
return; // Contract presence was already verified
|
|
37
|
+
}
|
|
38
|
+
}
|
|
31
39
|
const contractInfo = await (async () => {
|
|
32
|
-
if (
|
|
40
|
+
if (isRevive) {
|
|
33
41
|
const accountInfo = await client.query.revive.accountInfoOf(address);
|
|
34
42
|
if (accountInfo?.accountType && accountInfo?.accountType?.type === 'Contract') {
|
|
35
43
|
return accountInfo.accountType.value;
|
|
@@ -40,19 +48,28 @@ async function ensureContractPresence(client, registry, address) {
|
|
|
40
48
|
}
|
|
41
49
|
})();
|
|
42
50
|
(0, utils_1.ensurePresence)(contractInfo, `Contract with address ${address} does not exist on chain!`);
|
|
51
|
+
// Cache successful presence check
|
|
52
|
+
if (cache) {
|
|
53
|
+
cache.set(`${isRevive}::${address}`, true);
|
|
54
|
+
}
|
|
43
55
|
}
|
|
44
56
|
exports.ensureContractPresence = ensureContractPresence;
|
|
45
|
-
function ensureValidContractAddress(address,
|
|
46
|
-
if (
|
|
57
|
+
function ensureValidContractAddress(address, isRevive) {
|
|
58
|
+
if (isRevive) {
|
|
47
59
|
(0, utils_1.assert)((0, utils_1.isEvmAddress)(address), `Invalid contract address: ${address}. Expected an EVM 20-byte address as a hex string or a Uint8Array`);
|
|
48
60
|
}
|
|
49
61
|
else {
|
|
50
|
-
(
|
|
62
|
+
ensureValidAccountId32Address(address, `Invalid contract address: ${address}. Expected a Substrate 32-byte address as a hex string or a Uint8Array`);
|
|
51
63
|
}
|
|
52
64
|
}
|
|
53
65
|
exports.ensureValidContractAddress = ensureValidContractAddress;
|
|
54
|
-
function
|
|
55
|
-
(0, utils_1.assert)((0, utils_1.
|
|
66
|
+
function ensureValidAccountId32Address(address, customErrorMessage) {
|
|
67
|
+
(0, utils_1.assert)((0, utils_1.hexToU8a)((0, codecs_1.accountId32ToHex)(address)).length === 32, customErrorMessage ||
|
|
68
|
+
`Invalid AccountId32 address: ${address}. Expected a Substrate 32-byte address as a hex string or a Uint8Array`);
|
|
69
|
+
}
|
|
70
|
+
exports.ensureValidAccountId32Address = ensureValidAccountId32Address;
|
|
71
|
+
function ensureValidCodeHashOrCode(codeHashOrCode, isRevive) {
|
|
72
|
+
(0, utils_1.assert)((0, utils_1.toU8a)(codeHashOrCode).length === 32 || (isRevive ? (0, utils_1.isPvm)(codeHashOrCode) : (0, utils_1.isWasm)(codeHashOrCode)), 'Invalid code hash or code: expected a hash of 32-byte or a valid PVM/WASM code as a hex string or a Uint8Array');
|
|
56
73
|
}
|
|
57
74
|
exports.ensureValidCodeHashOrCode = ensureValidCodeHashOrCode;
|
|
58
75
|
const UNSUPPORTED_VERSIONS = ['V3', 'V2', 'V1'];
|
package/cjs/utils/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isLazyType = exports.KnownLazyType = exports.toReturnFlags = exports.normalizeLabel = exports.normalizeContractTypeDef = exports.extractContractTypes = void 0;
|
|
3
|
+
exports.isSolAbi = exports.isInkAbi = exports.isLazyType = exports.KnownLazyType = exports.toReturnFlags = exports.normalizeLabel = exports.normalizeContractTypeDef = exports.extractContractTypes = void 0;
|
|
4
4
|
const utils_1 = require("@dedot/utils");
|
|
5
5
|
const extractContractTypes = (contractMetadata) => {
|
|
6
6
|
const { types } = contractMetadata;
|
|
@@ -125,3 +125,23 @@ function isLazyType(typePath) {
|
|
|
125
125
|
return KnownLazyType.STORAGE_VEC;
|
|
126
126
|
}
|
|
127
127
|
exports.isLazyType = isLazyType;
|
|
128
|
+
// https://use.ink/docs/v6/basics/metadata/ink/
|
|
129
|
+
function isInkAbi(metadata) {
|
|
130
|
+
return (metadata !== null && // --
|
|
131
|
+
'source' in metadata &&
|
|
132
|
+
'contract' in metadata &&
|
|
133
|
+
'spec' in metadata);
|
|
134
|
+
}
|
|
135
|
+
exports.isInkAbi = isInkAbi;
|
|
136
|
+
// https://docs.soliditylang.org/en/latest/abi-spec.html#json
|
|
137
|
+
function isSolAbi(metadata) {
|
|
138
|
+
return (Array.isArray(metadata) &&
|
|
139
|
+
metadata.length > 0 &&
|
|
140
|
+
metadata.some((item) => item.type === 'function' ||
|
|
141
|
+
item.type === 'constructor' ||
|
|
142
|
+
item.type === 'event' ||
|
|
143
|
+
item.type === 'error' ||
|
|
144
|
+
item.type === 'fallback' ||
|
|
145
|
+
item.type === 'receive'));
|
|
146
|
+
}
|
|
147
|
+
exports.isSolAbi = isSolAbi;
|
package/errors.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DispatchError, PalletErrorMetadataLatest } from '@dedot/codecs';
|
|
2
2
|
import { DedotError } from '@dedot/utils';
|
|
3
|
-
import { ContractCallResult, ContractInstantiateResult, GenericContractApi, ReturnFlags } from './types/index.js';
|
|
3
|
+
import { ContractCallResult, ContractInstantiateResult, GenericContractApi, InkGenericContractApi, ReturnFlags, SolAbiError, SolGenericContractApi } from './types/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* Represents an error that occurred during the instantiation of a smart contract.
|
|
6
6
|
* This class extends the base `DedotError` and includes a `raw` property of type `ContractInstantiateResult`.
|
|
@@ -59,7 +59,7 @@ export declare class ContractInstantiateDispatchError<ContractApi extends Generi
|
|
|
59
59
|
*
|
|
60
60
|
* @extends ContractInstantiateError
|
|
61
61
|
*/
|
|
62
|
-
export declare class ContractInstantiateLangError<ContractApi extends
|
|
62
|
+
export declare class ContractInstantiateLangError<ContractApi extends InkGenericContractApi = InkGenericContractApi> extends ContractInstantiateError<ContractApi> {
|
|
63
63
|
name: string;
|
|
64
64
|
/**
|
|
65
65
|
* The language-specific error that occurred during the instantiation.
|
|
@@ -135,7 +135,7 @@ export declare class ContractDispatchError<ContractApi extends GenericContractAp
|
|
|
135
135
|
*
|
|
136
136
|
* @extends ContractExecutionError
|
|
137
137
|
*/
|
|
138
|
-
export declare class ContractLangError<ContractApi extends
|
|
138
|
+
export declare class ContractLangError<ContractApi extends InkGenericContractApi = InkGenericContractApi> extends ContractExecutionError<ContractApi> {
|
|
139
139
|
name: string;
|
|
140
140
|
/**
|
|
141
141
|
* The language-specific error that occurred during the execution.
|
|
@@ -153,6 +153,43 @@ export declare class ContractLangError<ContractApi extends GenericContractApi =
|
|
|
153
153
|
*/
|
|
154
154
|
constructor(err: ContractApi['types']['LangError'], raw: ContractCallResult<ContractApi['types']['ChainApi']>);
|
|
155
155
|
}
|
|
156
|
+
export type SolErrorResult = {
|
|
157
|
+
abiItem: SolAbiError;
|
|
158
|
+
args: readonly unknown[] | undefined;
|
|
159
|
+
errorName: string;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Represents a custom error that occurred during the instantiation of a solidity smart contract.
|
|
163
|
+
* This class extends `ContractInstantiateError` and includes properties for the error name and description.
|
|
164
|
+
*
|
|
165
|
+
* @template ContractApi - The type of the contract API. Defaults to `SolGenericContractApi`.
|
|
166
|
+
*
|
|
167
|
+
* @extends ContractInstantiateError
|
|
168
|
+
*/
|
|
169
|
+
export declare class SolContractInstantiateError<ContractApi extends SolGenericContractApi = SolGenericContractApi> extends ContractInstantiateError {
|
|
170
|
+
name: string;
|
|
171
|
+
details?: SolErrorResult;
|
|
172
|
+
constructor(raw: ContractInstantiateResult<ContractApi['types']['ChainApi']>, { details, message }: {
|
|
173
|
+
details?: SolErrorResult;
|
|
174
|
+
message?: string;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Represents a custom error that occurred during the execution of a smart contract call.
|
|
179
|
+
* This class extends `ContractExecutionError` and includes properties for the error name and description.
|
|
180
|
+
*
|
|
181
|
+
* @template ContractApi - The type of the contract API. Defaults to `SolGenericContractApi`.
|
|
182
|
+
*
|
|
183
|
+
* @extends ContractExecutionError
|
|
184
|
+
*/
|
|
185
|
+
export declare class SolContractExecutionError<ContractApi extends SolGenericContractApi = SolGenericContractApi> extends ContractExecutionError {
|
|
186
|
+
name: string;
|
|
187
|
+
details?: SolErrorResult;
|
|
188
|
+
constructor(raw: ContractCallResult<ContractApi['types']['ChainApi']>, { details, message }: {
|
|
189
|
+
details?: SolErrorResult;
|
|
190
|
+
message?: string;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
156
193
|
/**
|
|
157
194
|
* Checks if the provided error is an instance of `ContractExecutionError`.
|
|
158
195
|
*
|
|
@@ -190,7 +227,7 @@ export declare function isContractDispatchError<ContractApi extends GenericContr
|
|
|
190
227
|
* @returns `true` if the error is an instance of `ContractLangError`, `false` otherwise.
|
|
191
228
|
* This function returns a boolean value indicating whether the provided error is of type `ContractLangError`.
|
|
192
229
|
*/
|
|
193
|
-
export declare function isContractLangError<ContractApi extends
|
|
230
|
+
export declare function isContractLangError<ContractApi extends InkGenericContractApi = InkGenericContractApi>(e: Error): e is ContractLangError<ContractApi>;
|
|
194
231
|
/**
|
|
195
232
|
* Checks if the provided error is an instance of `ContractInstantiateError`.
|
|
196
233
|
*
|
|
@@ -229,4 +266,26 @@ export declare function isContractInstantiateDispatchError<ContractApi extends G
|
|
|
229
266
|
* @returns `true` if the error is an instance of `ContractInstantiateLangError`, `false` otherwise.
|
|
230
267
|
* This function returns a boolean value indicating whether the provided error is of type `ContractInstantiateLangError`.
|
|
231
268
|
*/
|
|
232
|
-
export declare function isContractInstantiateLangError<ContractApi extends
|
|
269
|
+
export declare function isContractInstantiateLangError<ContractApi extends InkGenericContractApi = InkGenericContractApi>(e: Error): e is ContractInstantiateLangError<ContractApi>;
|
|
270
|
+
/**
|
|
271
|
+
* Checks if the provided error is an instance of `isSolContractExecutionError`.
|
|
272
|
+
* This function is used to determine if a given error is a custom error specific to a smart contract.
|
|
273
|
+
*
|
|
274
|
+
* @template ContractApi - The type of the contract API. Defaults to `SolGenericContractApi`.
|
|
275
|
+
*
|
|
276
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
277
|
+
*
|
|
278
|
+
* @returns `true` if the error is an instance of `isSolContractExecutionError`, `false` otherwise.
|
|
279
|
+
*/
|
|
280
|
+
export declare function isSolContractExecutionError<ContractApi extends SolGenericContractApi = SolGenericContractApi>(e: Error): e is SolContractExecutionError<ContractApi>;
|
|
281
|
+
/**
|
|
282
|
+
* Checks if the provided error is an instance of `SolContractInstantiateError`.
|
|
283
|
+
* This function is used to determine if a given error is a custom error specific to the instantiation of a smart contract.
|
|
284
|
+
*
|
|
285
|
+
* @template ContractApi - The type of the contract API. Defaults to `SolGenericContractApi`.
|
|
286
|
+
*
|
|
287
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
288
|
+
*
|
|
289
|
+
* @returns `true` if the error is an instance of `SolContractInstantiateError`, `false` otherwise.
|
|
290
|
+
*/
|
|
291
|
+
export declare function isSolContractInstantiateError<ContractApi extends SolGenericContractApi = SolGenericContractApi>(e: Error): e is SolContractInstantiateError<ContractApi>;
|
package/errors.js
CHANGED
|
@@ -193,6 +193,50 @@ export class ContractLangError extends ContractExecutionError {
|
|
|
193
193
|
this.message = `Lang error: ${JSON.stringify(err)}`;
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Represents a custom error that occurred during the instantiation of a solidity smart contract.
|
|
198
|
+
* This class extends `ContractInstantiateError` and includes properties for the error name and description.
|
|
199
|
+
*
|
|
200
|
+
* @template ContractApi - The type of the contract API. Defaults to `SolGenericContractApi`.
|
|
201
|
+
*
|
|
202
|
+
* @extends ContractInstantiateError
|
|
203
|
+
*/
|
|
204
|
+
export class SolContractInstantiateError extends ContractInstantiateError {
|
|
205
|
+
name = 'SolContractInstantiateError';
|
|
206
|
+
details;
|
|
207
|
+
constructor(raw, { details, message }) {
|
|
208
|
+
super(raw);
|
|
209
|
+
this.details = details;
|
|
210
|
+
if (message) {
|
|
211
|
+
this.message = message;
|
|
212
|
+
}
|
|
213
|
+
else if (details) {
|
|
214
|
+
this.message = `Error: ${details.errorName}`;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Represents a custom error that occurred during the execution of a smart contract call.
|
|
220
|
+
* This class extends `ContractExecutionError` and includes properties for the error name and description.
|
|
221
|
+
*
|
|
222
|
+
* @template ContractApi - The type of the contract API. Defaults to `SolGenericContractApi`.
|
|
223
|
+
*
|
|
224
|
+
* @extends ContractExecutionError
|
|
225
|
+
*/
|
|
226
|
+
export class SolContractExecutionError extends ContractExecutionError {
|
|
227
|
+
name = 'SolContractExecutionError';
|
|
228
|
+
details;
|
|
229
|
+
constructor(raw, { details, message }) {
|
|
230
|
+
super(raw);
|
|
231
|
+
this.details = details;
|
|
232
|
+
if (message) {
|
|
233
|
+
this.message = message;
|
|
234
|
+
}
|
|
235
|
+
else if (details) {
|
|
236
|
+
this.message = `Error: ${details.errorName}`;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
196
240
|
/**
|
|
197
241
|
* Checks if the provided error is an instance of `ContractExecutionError`.
|
|
198
242
|
*
|
|
@@ -282,3 +326,29 @@ export function isContractInstantiateDispatchError(e) {
|
|
|
282
326
|
export function isContractInstantiateLangError(e) {
|
|
283
327
|
return e instanceof ContractInstantiateLangError;
|
|
284
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* Checks if the provided error is an instance of `isSolContractExecutionError`.
|
|
331
|
+
* This function is used to determine if a given error is a custom error specific to a smart contract.
|
|
332
|
+
*
|
|
333
|
+
* @template ContractApi - The type of the contract API. Defaults to `SolGenericContractApi`.
|
|
334
|
+
*
|
|
335
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
336
|
+
*
|
|
337
|
+
* @returns `true` if the error is an instance of `isSolContractExecutionError`, `false` otherwise.
|
|
338
|
+
*/
|
|
339
|
+
export function isSolContractExecutionError(e) {
|
|
340
|
+
return e instanceof SolContractExecutionError;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Checks if the provided error is an instance of `SolContractInstantiateError`.
|
|
344
|
+
* This function is used to determine if a given error is a custom error specific to the instantiation of a smart contract.
|
|
345
|
+
*
|
|
346
|
+
* @template ContractApi - The type of the contract API. Defaults to `SolGenericContractApi`.
|
|
347
|
+
*
|
|
348
|
+
* @param e - The error to be checked. This should be an instance of `Error`.
|
|
349
|
+
*
|
|
350
|
+
* @returns `true` if the error is an instance of `SolContractInstantiateError`, `false` otherwise.
|
|
351
|
+
*/
|
|
352
|
+
export function isSolContractInstantiateError(e) {
|
|
353
|
+
return e instanceof SolContractInstantiateError;
|
|
354
|
+
}
|
package/executor/index.d.ts
CHANGED
package/executor/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
2
|
-
import { GenericConstructorQueryCall } from '../types/index.js';
|
|
3
2
|
import { DeployerExecutor } from './abstract/index.js';
|
|
4
3
|
export declare class ConstructorQueryExecutor<ChainApi extends GenericSubstrateApi> extends DeployerExecutor<ChainApi> {
|
|
5
|
-
doExecute(constructor: string):
|
|
4
|
+
doExecute(constructor: string): any;
|
|
6
5
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assert, concatU8a, hexToU8a, isPvm, isUndefined, isWasm, toHex, toU8a, u8aToHex } from '@dedot/utils';
|
|
2
|
-
import { ContractInstantiateDispatchError, ContractInstantiateLangError } from '
|
|
3
|
-
import { ensureParamsLength, toReturnFlags } from '
|
|
2
|
+
import { ContractInstantiateDispatchError, ContractInstantiateLangError } from '../../errors.js';
|
|
3
|
+
import { ensureParamsLength, ensureValidAccountId32Address, toReturnFlags } from '../../utils/index.js';
|
|
4
4
|
import { DeployerExecutor } from './abstract/index.js';
|
|
5
5
|
export class ConstructorQueryExecutor extends DeployerExecutor {
|
|
6
6
|
doExecute(constructor) {
|
|
@@ -13,6 +13,7 @@ export class ConstructorQueryExecutor extends DeployerExecutor {
|
|
|
13
13
|
const { caller = this.options.defaultCaller, // --
|
|
14
14
|
value = 0n, gasLimit, storageDepositLimit, salt, } = callOptions;
|
|
15
15
|
assert(caller, 'Expected a valid caller address in ConstructorCallOptions');
|
|
16
|
+
ensureValidAccountId32Address(caller);
|
|
16
17
|
const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
|
|
17
18
|
const bytes = u8aToHex(concatU8a(hexToU8a(meta.selector), ...formattedInputs));
|
|
18
19
|
const isUpload = isPvm(this.code) || isWasm(this.code);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
2
|
-
import { GenericConstructorTxCall } from '../types/index.js';
|
|
3
2
|
import { DeployerExecutor } from './abstract/index.js';
|
|
4
3
|
export declare class ConstructorTxExecutor<ChainApi extends GenericSubstrateApi> extends DeployerExecutor<ChainApi> {
|
|
5
|
-
doExecute(constructor: string):
|
|
4
|
+
doExecute(constructor: string): any;
|
|
6
5
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assert, concatU8a, hexToU8a, isPvm, isUndefined, isWasm, toHex, toU8a, u8aToHex } from '@dedot/utils';
|
|
2
|
-
import { Contract } from '
|
|
3
|
-
import { CREATE1, CREATE2, ensureContractPresence, ensureParamsLength, toEvmAddress } from '
|
|
2
|
+
import { Contract } from '../../Contract.js';
|
|
3
|
+
import { CREATE1, CREATE2, ensureContractPresence, ensureParamsLength, toEvmAddress } from '../../utils/index.js';
|
|
4
4
|
import { ConstructorQueryExecutor } from './ConstructorQueryExecutor.js';
|
|
5
5
|
import { DeployerExecutor } from './abstract/index.js';
|
|
6
6
|
export class ConstructorTxExecutor extends DeployerExecutor {
|
|
@@ -105,8 +105,9 @@ export class ConstructorTxExecutor extends DeployerExecutor {
|
|
|
105
105
|
const contract = async (overrideOptions) => {
|
|
106
106
|
const address = await contractAddress();
|
|
107
107
|
// Check if the contract is existed on chain or not!
|
|
108
|
-
await ensureContractPresence(client, this.registry, address);
|
|
108
|
+
await ensureContractPresence(client, this.registry.isRevive(), address);
|
|
109
109
|
return new Contract(client, // --
|
|
110
|
+
// @ts-ignore
|
|
110
111
|
this.metadata, address, {
|
|
111
112
|
defaultCaller: deployerAddress,
|
|
112
113
|
...this.options,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
2
|
-
import { GenericContractEvent } from '
|
|
2
|
+
import { GenericContractEvent } from '../../types/index.js';
|
|
3
3
|
import { ContractExecutor } from './abstract/index.js';
|
|
4
4
|
export declare class EventExecutor<ChainApi extends GenericSubstrateApi> extends ContractExecutor<ChainApi> {
|
|
5
5
|
#private;
|
|
6
|
-
doExecute(eventName: string): GenericContractEvent
|
|
6
|
+
doExecute(eventName: string): GenericContractEvent<string, any, 'ink'>;
|
|
7
7
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
2
|
-
import { GenericContractQueryCall } from '../types/index.js';
|
|
3
2
|
import { ContractExecutor } from './abstract/index.js';
|
|
4
3
|
export declare class QueryExecutor<ChainApi extends GenericSubstrateApi> extends ContractExecutor<ChainApi> {
|
|
5
|
-
doExecute(message: string):
|
|
4
|
+
doExecute(message: string): any;
|
|
6
5
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assert, concatU8a, hexToU8a, u8aToHex } from '@dedot/utils';
|
|
2
|
-
import { ContractDispatchError, ContractLangError } from '
|
|
3
|
-
import { ensureContractPresence, ensureParamsLength, toReturnFlags } from '
|
|
2
|
+
import { ContractDispatchError, ContractLangError } from '../../errors.js';
|
|
3
|
+
import { ensureContractPresence, ensureParamsLength, ensureValidAccountId32Address, toReturnFlags, } from '../../utils/index.js';
|
|
4
4
|
import { ContractExecutor } from './abstract/index.js';
|
|
5
5
|
export class QueryExecutor extends ContractExecutor {
|
|
6
6
|
doExecute(message) {
|
|
@@ -12,10 +12,11 @@ export class QueryExecutor extends ContractExecutor {
|
|
|
12
12
|
const callOptions = (params[args.length] || {});
|
|
13
13
|
const { caller = this.options.defaultCaller, value = 0n, gasLimit, storageDepositLimit } = callOptions;
|
|
14
14
|
assert(caller, 'Expected a valid caller address in ContractCallOptions');
|
|
15
|
+
ensureValidAccountId32Address(caller);
|
|
15
16
|
const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
|
|
16
17
|
const bytes = u8aToHex(concatU8a(hexToU8a(meta.selector), ...formattedInputs));
|
|
17
18
|
const client = this.client;
|
|
18
|
-
await ensureContractPresence(client, this.registry, this.address);
|
|
19
|
+
await ensureContractPresence(client, this.registry.isRevive(), this.address, this.registry.cache);
|
|
19
20
|
const raw = await (async () => {
|
|
20
21
|
if (this.registry.isRevive()) {
|
|
21
22
|
const raw = await client.call.reviveApi.call(caller, // --
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
2
|
-
import { GenericContractTxCall } from '../types/index.js';
|
|
3
2
|
import { ContractExecutor } from './abstract/index.js';
|
|
4
3
|
export declare class TxExecutor<ChainApi extends GenericSubstrateApi> extends ContractExecutor<ChainApi> {
|
|
5
|
-
doExecute(message: string):
|
|
4
|
+
doExecute(message: string): any;
|
|
6
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert, concatU8a, hexToU8a, u8aToHex } from '@dedot/utils';
|
|
2
|
-
import { ensureParamsLength } from '
|
|
2
|
+
import { ensureParamsLength } from '../../utils/index.js';
|
|
3
3
|
import { QueryExecutor } from './QueryExecutor.js';
|
|
4
4
|
import { ContractExecutor } from './abstract/index.js';
|
|
5
5
|
export class TxExecutor extends ContractExecutor {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ISubstrateClient } from '@dedot/api';
|
|
2
2
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
3
|
-
import { TypinkRegistry } from '
|
|
4
|
-
import { ContractAddress, ContractCallMessage, ExecutionOptions } from '
|
|
3
|
+
import { TypinkRegistry } from '../../../TypinkRegistry.js';
|
|
4
|
+
import { ContractAddress, ContractCallMessage, ExecutionOptions } from '../../../types/index.js';
|
|
5
5
|
import { Executor } from './Executor.js';
|
|
6
6
|
export declare abstract class ContractExecutor<ChainApi extends GenericSubstrateApi> extends Executor<ChainApi> {
|
|
7
7
|
readonly address: ContractAddress;
|
|
@@ -2,8 +2,8 @@ import { ISubstrateClient } from '@dedot/api';
|
|
|
2
2
|
import { Hash } from '@dedot/codecs';
|
|
3
3
|
import { GenericSubstrateApi } from '@dedot/types';
|
|
4
4
|
import { HexString } from '@dedot/utils';
|
|
5
|
-
import { TypinkRegistry } from '
|
|
6
|
-
import { ContractConstructorMessage, ExecutionOptions } from '
|
|
5
|
+
import { TypinkRegistry } from '../../../TypinkRegistry.js';
|
|
6
|
+
import { ContractConstructorMessage, ExecutionOptions } from '../../../types/index.js';
|
|
7
7
|
import { Executor } from './Executor.js';
|
|
8
8
|
export declare abstract class DeployerExecutor<ChainApi extends GenericSubstrateApi> extends Executor<ChainApi> {
|
|
9
9
|
readonly code: Hash | Uint8Array | HexString | string;
|