@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
package/utils/ensure.js
CHANGED
|
@@ -4,27 +4,35 @@ export const ensureStorageApiSupports = (version) => {
|
|
|
4
4
|
const numberedVersion = typeof version === 'number' ? version : parseInt(version);
|
|
5
5
|
assert(numberedVersion >= 5, `Contract Storage Api Only Available for metadata version >= 5, current version: ${version}`);
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
!!client.call.reviveApi.call.meta && !!client.tx.revive.call.meta;
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
throw new DedotError('Pallet Revive is not available');
|
|
14
|
-
}
|
|
7
|
+
function ensurePalletRevive(client) {
|
|
8
|
+
try {
|
|
9
|
+
!!client.call.reviveApi.call.meta && !!client.tx.revive.call.meta;
|
|
15
10
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
!!client.call.contractsApi.call.meta && !!client.tx.contracts.call.meta;
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
throw new DedotError('Pallet Contracts is not available');
|
|
22
|
-
}
|
|
11
|
+
catch {
|
|
12
|
+
throw new DedotError('Pallet Revive is not available');
|
|
23
13
|
}
|
|
24
14
|
}
|
|
25
|
-
|
|
15
|
+
function ensurePalletContracts(client) {
|
|
16
|
+
try {
|
|
17
|
+
!!client.call.contractsApi.call.meta && !!client.tx.contracts.call.meta;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw new DedotError('Pallet Contracts is not available');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function ensurePalletPresence(client, isRevive) {
|
|
24
|
+
isRevive ? ensurePalletRevive(client) : ensurePalletContracts(client);
|
|
25
|
+
}
|
|
26
|
+
export async function ensureContractPresence(client, isRevive, address, cache) {
|
|
27
|
+
// Check cache first if available
|
|
28
|
+
if (cache) {
|
|
29
|
+
const cached = cache.get(`${isRevive}::${address}`);
|
|
30
|
+
if (cached) {
|
|
31
|
+
return; // Contract presence was already verified
|
|
32
|
+
}
|
|
33
|
+
}
|
|
26
34
|
const contractInfo = await (async () => {
|
|
27
|
-
if (
|
|
35
|
+
if (isRevive) {
|
|
28
36
|
const accountInfo = await client.query.revive.accountInfoOf(address);
|
|
29
37
|
if (accountInfo?.accountType && accountInfo?.accountType?.type === 'Contract') {
|
|
30
38
|
return accountInfo.accountType.value;
|
|
@@ -35,17 +43,25 @@ export async function ensureContractPresence(client, registry, address) {
|
|
|
35
43
|
}
|
|
36
44
|
})();
|
|
37
45
|
ensurePresence(contractInfo, `Contract with address ${address} does not exist on chain!`);
|
|
46
|
+
// Cache successful presence check
|
|
47
|
+
if (cache) {
|
|
48
|
+
cache.set(`${isRevive}::${address}`, true);
|
|
49
|
+
}
|
|
38
50
|
}
|
|
39
|
-
export function ensureValidContractAddress(address,
|
|
40
|
-
if (
|
|
51
|
+
export function ensureValidContractAddress(address, isRevive) {
|
|
52
|
+
if (isRevive) {
|
|
41
53
|
assert(isEvmAddress(address), `Invalid contract address: ${address}. Expected an EVM 20-byte address as a hex string or a Uint8Array`);
|
|
42
54
|
}
|
|
43
55
|
else {
|
|
44
|
-
|
|
56
|
+
ensureValidAccountId32Address(address, `Invalid contract address: ${address}. Expected a Substrate 32-byte address as a hex string or a Uint8Array`);
|
|
45
57
|
}
|
|
46
58
|
}
|
|
47
|
-
export function
|
|
48
|
-
assert(
|
|
59
|
+
export function ensureValidAccountId32Address(address, customErrorMessage) {
|
|
60
|
+
assert(hexToU8a(accountId32ToHex(address)).length === 32, customErrorMessage ||
|
|
61
|
+
`Invalid AccountId32 address: ${address}. Expected a Substrate 32-byte address as a hex string or a Uint8Array`);
|
|
62
|
+
}
|
|
63
|
+
export function ensureValidCodeHashOrCode(codeHashOrCode, isRevive) {
|
|
64
|
+
assert(toU8a(codeHashOrCode).length === 32 || (isRevive ? isPvm(codeHashOrCode) : 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');
|
|
49
65
|
}
|
|
50
66
|
const UNSUPPORTED_VERSIONS = ['V3', 'V2', 'V1'];
|
|
51
67
|
const SUPPORTED_VERSIONS = [6, 5, '4'];
|
package/utils/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { PortableType, TypeDef } from '@dedot/codecs';
|
|
2
|
-
import {
|
|
1
|
+
import { AccountId32, Bytes, H160, H256, PortableType, TypeDef } from '@dedot/codecs';
|
|
2
|
+
import { IRuntimeEvent } from '@dedot/codecs/types';
|
|
3
|
+
import { ContractMetadata, ContractTypeDef, ReturnFlags } from '../types/index.js';
|
|
3
4
|
export declare const extractContractTypes: (contractMetadata: ContractMetadata) => PortableType[];
|
|
4
5
|
export declare const normalizeContractTypeDef: (def: ContractTypeDef) => TypeDef;
|
|
5
6
|
export declare function normalizeLabel(label?: string): string;
|
|
@@ -15,3 +16,20 @@ export declare enum KnownLazyType {
|
|
|
15
16
|
* @param typePath
|
|
16
17
|
*/
|
|
17
18
|
export declare function isLazyType(typePath?: string | string[] | undefined): KnownLazyType | undefined;
|
|
19
|
+
export type KnownPallets = 'Contracts' | 'Revive';
|
|
20
|
+
export interface ContractEmittedEvent<Pallet extends KnownPallets = 'Contracts'> extends IRuntimeEvent {
|
|
21
|
+
pallet: Pallet;
|
|
22
|
+
palletEvent: {
|
|
23
|
+
name: 'ContractEmitted';
|
|
24
|
+
data: Pallet extends 'Contracts' ? {
|
|
25
|
+
contract: AccountId32;
|
|
26
|
+
data: Bytes;
|
|
27
|
+
} : {
|
|
28
|
+
contract: H160;
|
|
29
|
+
data: Bytes;
|
|
30
|
+
topics: Array<H256>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export declare function isInkAbi(metadata: any): boolean;
|
|
35
|
+
export declare function isSolAbi(metadata: any): boolean;
|
package/utils/types.js
CHANGED
|
@@ -117,3 +117,21 @@ export function isLazyType(typePath) {
|
|
|
117
117
|
if (typePath === KNOWN_LAZY_TYPES.STORAGE_VEC)
|
|
118
118
|
return KnownLazyType.STORAGE_VEC;
|
|
119
119
|
}
|
|
120
|
+
// https://use.ink/docs/v6/basics/metadata/ink/
|
|
121
|
+
export function isInkAbi(metadata) {
|
|
122
|
+
return (metadata !== null && // --
|
|
123
|
+
'source' in metadata &&
|
|
124
|
+
'contract' in metadata &&
|
|
125
|
+
'spec' in metadata);
|
|
126
|
+
}
|
|
127
|
+
// https://docs.soliditylang.org/en/latest/abi-spec.html#json
|
|
128
|
+
export function isSolAbi(metadata) {
|
|
129
|
+
return (Array.isArray(metadata) &&
|
|
130
|
+
metadata.length > 0 &&
|
|
131
|
+
metadata.some((item) => item.type === 'function' ||
|
|
132
|
+
item.type === 'constructor' ||
|
|
133
|
+
item.type === 'event' ||
|
|
134
|
+
item.type === 'error' ||
|
|
135
|
+
item.type === 'fallback' ||
|
|
136
|
+
item.type === 'receive'));
|
|
137
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|