Specific check for storageDepositLimit support (#5108)
* Specific check for storageDepositLimit support * Adjust asserts
This commit is contained in:
+1
-1
@@ -37,7 +37,7 @@
|
||||
"@babel/core": "^7.18.9",
|
||||
"@babel/register": "^7.18.9",
|
||||
"@babel/runtime": "^7.18.9",
|
||||
"@polkadot/dev": "^0.67.84",
|
||||
"@polkadot/dev": "^0.67.85",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"@types/jest": "^28.1.6",
|
||||
"copyfiles": "^2.4.1"
|
||||
|
||||
@@ -26,10 +26,10 @@ export abstract class Base<ApiType extends ApiTypes> {
|
||||
|
||||
if (!api || !api.isConnected || !api.tx) {
|
||||
throw new Error('Your API has not been initialized correctly and is not connected to a chain');
|
||||
} else if (!api.tx.contracts || !Object.keys(api.tx.contracts).length || !api.call.contractsApi) {
|
||||
throw new Error('You need to connect to a chain with a runtime that supports contracts');
|
||||
} else if (!isFunction(api.tx.contracts.instantiateWithCode)) {
|
||||
throw new Error('You need to connect to a chain with a runtime with a V3 contracts module. The runtime does not expose api.tx.contracts.instantiateWithCode');
|
||||
} else if (!api.tx.contracts || !isFunction(api.tx.contracts.instantiateWithCode) || api.tx.contracts.instantiateWithCode.meta.args.length !== 6) {
|
||||
throw new Error('The runtime does not expose api.tx.contracts.instantiateWithCode with storageDepositLimit');
|
||||
} else if (!api.call.contractsApi || !isFunction(api.call.contractsApi.call)) {
|
||||
throw new Error('Your runtime does not expose the api.call.contractsApi.call method');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,20 +57,16 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
}
|
||||
|
||||
#deploy = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, storageDepositLimit = null, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic<ApiType, BlueprintSubmittableResult<ApiType>> => {
|
||||
const hasStorageDeposit = this.api.tx.contracts.instantiate.meta.args.length === 6;
|
||||
const encParams = this.abi.findConstructor(constructorOrId).toU8a(params);
|
||||
const encSalt = encodeSalt(salt);
|
||||
const tx = hasStorageDeposit
|
||||
? this.api.tx.contracts.instantiate(value, gasLimit, storageDepositLimit, this.codeHash, encParams, encSalt)
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore old style without storage deposit
|
||||
: this.api.tx.contracts.instantiate(value, gasLimit, this.codeHash, encParams, encSalt);
|
||||
|
||||
return tx.withResultTransform((result: ISubmittableResult) =>
|
||||
new BlueprintSubmittableResult(result, applyOnEvent(result, ['Instantiated'], ([record]: EventRecord[]) =>
|
||||
new Contract<ApiType>(this.api, this.abi, record.event.data[1] as AccountId, this._decorateMethod)
|
||||
))
|
||||
);
|
||||
return this.api.tx.contracts
|
||||
.instantiate(value, gasLimit, storageDepositLimit, this.codeHash, encParams, encSalt)
|
||||
.withResultTransform((result: ISubmittableResult) =>
|
||||
new BlueprintSubmittableResult(result, applyOnEvent(result, ['Instantiated'], ([record]: EventRecord[]) =>
|
||||
new Contract<ApiType>(this.api, this.abi, record.event.data[1] as AccountId, this._decorateMethod)
|
||||
))
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -64,27 +64,23 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
}
|
||||
|
||||
#instantiate = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, storageDepositLimit = null, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
|
||||
const hasStorageDeposit = this.api.tx.contracts.instantiateWithCode.meta.args.length === 6;
|
||||
const encCode = compactAddLength(this.code);
|
||||
const encParams = this.abi.findConstructor(constructorOrId).toU8a(params);
|
||||
const encSalt = encodeSalt(salt);
|
||||
const tx = hasStorageDeposit
|
||||
? this.api.tx.contracts.instantiateWithCode(value, gasLimit, storageDepositLimit, encCode, encParams, encSalt)
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore old style without storage deposit
|
||||
: this.api.tx.contracts.instantiateWithCode(value, gasLimit, encCode, encParams, encSalt);
|
||||
|
||||
return tx.withResultTransform((result: ISubmittableResult) =>
|
||||
new CodeSubmittableResult(result, ...(applyOnEvent(result, ['CodeStored', 'Instantiated'], (records: EventRecord[]) =>
|
||||
records.reduce<[Blueprint<ApiType>?, Contract<ApiType>?]>(([blueprint, contract], { event }) =>
|
||||
this.api.events.contracts.Instantiated.is(event)
|
||||
? [blueprint, new Contract<ApiType>(this.api, this.abi, (event as unknown as { data: [Codec, AccountId] }).data[1], this._decorateMethod)]
|
||||
: this.api.events.contracts.CodeStored.is(event)
|
||||
? [new Blueprint<ApiType>(this.api, this.abi, (event as unknown as { data: [AccountId] }).data[0], this._decorateMethod), contract]
|
||||
: [blueprint, contract],
|
||||
[])
|
||||
) || []))
|
||||
);
|
||||
return this.api.tx.contracts
|
||||
.instantiateWithCode(value, gasLimit, storageDepositLimit, encCode, encParams, encSalt)
|
||||
.withResultTransform((result: ISubmittableResult) =>
|
||||
new CodeSubmittableResult(result, ...(applyOnEvent(result, ['CodeStored', 'Instantiated'], (records: EventRecord[]) =>
|
||||
records.reduce<[Blueprint<ApiType>?, Contract<ApiType>?]>(([blueprint, contract], { event }) =>
|
||||
this.api.events.contracts.Instantiated.is(event)
|
||||
? [blueprint, new Contract<ApiType>(this.api, this.abi, (event as unknown as { data: [Codec, AccountId] }).data[1], this._decorateMethod)]
|
||||
: this.api.events.contracts.CodeStored.is(event)
|
||||
? [new Blueprint<ApiType>(this.api, this.abi, (event as unknown as { data: [AccountId] }).data[0], this._decorateMethod), contract]
|
||||
: [blueprint, contract],
|
||||
[])
|
||||
) || []))
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,12 @@ import { TypeRegistry } from '@polkadot/types';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
const instantiateWithCode = (): never => {
|
||||
throw new Error('mock');
|
||||
};
|
||||
|
||||
instantiateWithCode.meta = { args: new Array(6) };
|
||||
|
||||
export const mockApi = {
|
||||
call: {
|
||||
contractsApi: {
|
||||
@@ -18,9 +24,7 @@ export const mockApi = {
|
||||
registry,
|
||||
tx: {
|
||||
contracts: {
|
||||
instantiateWithCode: (): never => {
|
||||
throw new Error('mock');
|
||||
}
|
||||
instantiateWithCode
|
||||
}
|
||||
}
|
||||
} as unknown as ApiBase<'promise'>;
|
||||
|
||||
@@ -2044,9 +2044,9 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/dev@npm:^0.67.84":
|
||||
version: 0.67.84
|
||||
resolution: "@polkadot/dev@npm:0.67.84"
|
||||
"@polkadot/dev@npm:^0.67.85":
|
||||
version: 0.67.85
|
||||
resolution: "@polkadot/dev@npm:0.67.85"
|
||||
dependencies:
|
||||
"@babel/cli": ^7.18.9
|
||||
"@babel/core": ^7.18.9
|
||||
@@ -2071,8 +2071,8 @@ __metadata:
|
||||
"@rollup/plugin-json": ^4.1.0
|
||||
"@rollup/plugin-node-resolve": ^13.3.0
|
||||
"@rushstack/eslint-patch": ^1.1.4
|
||||
"@typescript-eslint/eslint-plugin": 5.30.7
|
||||
"@typescript-eslint/parser": 5.30.7
|
||||
"@typescript-eslint/eslint-plugin": 5.31.0
|
||||
"@typescript-eslint/parser": 5.31.0
|
||||
"@vue/component-compiler-utils": ^3.3.0
|
||||
babel-jest: ^28.1.3
|
||||
babel-plugin-module-extension-resolver: ^1.0.0-rc.2
|
||||
@@ -2135,7 +2135,7 @@ __metadata:
|
||||
polkadot-exec-rollup: scripts/polkadot-exec-rollup.mjs
|
||||
polkadot-exec-tsc: scripts/polkadot-exec-tsc.mjs
|
||||
polkadot-exec-webpack: scripts/polkadot-exec-webpack.mjs
|
||||
checksum: 2ea615e378da2f8f86aeaaf8c6c4d2dda244c59a9d5a393f9b1e75fc41f23a2a1c4a9b136ea0facb8038a454d5ca0d86cb11f633435d7ad3ac56828add90052d
|
||||
checksum: b800ce26d995d3479c1205570ac9973cf2e067f8529ebe4649dac9209b448cfe3e24c99c5b252b0d014b3566bd65be514cef2f0e2d1b926d0e6fa64fbf9c3d3d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2911,13 +2911,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@typescript-eslint/eslint-plugin@npm:5.30.7":
|
||||
version: 5.30.7
|
||||
resolution: "@typescript-eslint/eslint-plugin@npm:5.30.7"
|
||||
"@typescript-eslint/eslint-plugin@npm:5.31.0":
|
||||
version: 5.31.0
|
||||
resolution: "@typescript-eslint/eslint-plugin@npm:5.31.0"
|
||||
dependencies:
|
||||
"@typescript-eslint/scope-manager": 5.30.7
|
||||
"@typescript-eslint/type-utils": 5.30.7
|
||||
"@typescript-eslint/utils": 5.30.7
|
||||
"@typescript-eslint/scope-manager": 5.31.0
|
||||
"@typescript-eslint/type-utils": 5.31.0
|
||||
"@typescript-eslint/utils": 5.31.0
|
||||
debug: ^4.3.4
|
||||
functional-red-black-tree: ^1.0.1
|
||||
ignore: ^5.2.0
|
||||
@@ -2930,42 +2930,42 @@ __metadata:
|
||||
peerDependenciesMeta:
|
||||
typescript:
|
||||
optional: true
|
||||
checksum: d42af514f5817732646b5601030699687b4ef619ba7983754a4173bf908f6c6030324038e3733b88342ec6ace07af61aa946d677da6a6266931275bd2afc9fc2
|
||||
checksum: a6d007e6cc6c7204b9ce09dd6670a5a29f8b75417a84c8238d1dd7fc3bfa4a7294beb961a0ba76e610b695a0c80edd4186803429e3605a21562c23e47b8efa37
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@typescript-eslint/parser@npm:5.30.7":
|
||||
version: 5.30.7
|
||||
resolution: "@typescript-eslint/parser@npm:5.30.7"
|
||||
"@typescript-eslint/parser@npm:5.31.0":
|
||||
version: 5.31.0
|
||||
resolution: "@typescript-eslint/parser@npm:5.31.0"
|
||||
dependencies:
|
||||
"@typescript-eslint/scope-manager": 5.30.7
|
||||
"@typescript-eslint/types": 5.30.7
|
||||
"@typescript-eslint/typescript-estree": 5.30.7
|
||||
"@typescript-eslint/scope-manager": 5.31.0
|
||||
"@typescript-eslint/types": 5.31.0
|
||||
"@typescript-eslint/typescript-estree": 5.31.0
|
||||
debug: ^4.3.4
|
||||
peerDependencies:
|
||||
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
|
||||
peerDependenciesMeta:
|
||||
typescript:
|
||||
optional: true
|
||||
checksum: f0b2da3cfd047d241f0bd3065a36afe008214aa9e8cd05e9f92d8b0e4b9ec19d3651d0e4a3995b8cb34b553cccb4b0d02d18c0cfbe11f53acd85923dd68366d5
|
||||
checksum: ae842105ff0e5811d54c9c020ee0568170c13f401de293eb4caa2106f3060558773b496b5647f2b80b2969a2890135c054f50e2443a13c3705d5965aa12896c0
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@typescript-eslint/scope-manager@npm:5.30.7":
|
||||
version: 5.30.7
|
||||
resolution: "@typescript-eslint/scope-manager@npm:5.30.7"
|
||||
"@typescript-eslint/scope-manager@npm:5.31.0":
|
||||
version: 5.31.0
|
||||
resolution: "@typescript-eslint/scope-manager@npm:5.31.0"
|
||||
dependencies:
|
||||
"@typescript-eslint/types": 5.30.7
|
||||
"@typescript-eslint/visitor-keys": 5.30.7
|
||||
checksum: 434ce7a13a8f3bffae2af2b7fe19bab6e490c78114584212519f50cd1b91fbdcddc8ad93bdb3cacdc8cecca5a8c5d2eb606557e66bd3fcd9d3040846846c22ff
|
||||
"@typescript-eslint/types": 5.31.0
|
||||
"@typescript-eslint/visitor-keys": 5.31.0
|
||||
checksum: f771adf54a7cf6387bb201a0d4bef598425818c38832cabbf33c369b3fb650932cbb81a28f198727f3ffae5e21445dde710c41c624bd10b3b7283249333b625b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@typescript-eslint/type-utils@npm:5.30.7":
|
||||
version: 5.30.7
|
||||
resolution: "@typescript-eslint/type-utils@npm:5.30.7"
|
||||
"@typescript-eslint/type-utils@npm:5.31.0":
|
||||
version: 5.31.0
|
||||
resolution: "@typescript-eslint/type-utils@npm:5.31.0"
|
||||
dependencies:
|
||||
"@typescript-eslint/utils": 5.30.7
|
||||
"@typescript-eslint/utils": 5.31.0
|
||||
debug: ^4.3.4
|
||||
tsutils: ^3.21.0
|
||||
peerDependencies:
|
||||
@@ -2973,7 +2973,7 @@ __metadata:
|
||||
peerDependenciesMeta:
|
||||
typescript:
|
||||
optional: true
|
||||
checksum: e7a8d4ec973355c0fe5bad4c317a55940e41d24b1c33b0bf40e8bb268d784f6584a8048fc84ebdb7287849a2c70e2b36365067cba7815de849cd41a1d7653167
|
||||
checksum: 1e98a6952207cf7d19cdac375a69bcfed953a29746fa1f2b3c7a8c9376c6984c0bb52506539b76d6a9bebc33966c825f032a27859e545447890562dd3c05ef31
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2984,19 +2984,19 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@typescript-eslint/types@npm:5.30.7":
|
||||
version: 5.30.7
|
||||
resolution: "@typescript-eslint/types@npm:5.30.7"
|
||||
checksum: 2f6345bf0e2e9f392c1f62a5f96c630d4565574230a000508d923444229e51c1a05e07cef042935ca30f4f35755dbf3871b8b9da808911f578d63e6a4b897b79
|
||||
"@typescript-eslint/types@npm:5.31.0":
|
||||
version: 5.31.0
|
||||
resolution: "@typescript-eslint/types@npm:5.31.0"
|
||||
checksum: 1c4223a7dcbeb2fb52dc723ac366e2cc75549b21d71f5de8515e86e48d13324e4e136e75804e0f71aff56c9936ef494fa4d1e3eb2f189ed60cf8e2c7401ce372
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@typescript-eslint/typescript-estree@npm:5.30.7":
|
||||
version: 5.30.7
|
||||
resolution: "@typescript-eslint/typescript-estree@npm:5.30.7"
|
||||
"@typescript-eslint/typescript-estree@npm:5.31.0":
|
||||
version: 5.31.0
|
||||
resolution: "@typescript-eslint/typescript-estree@npm:5.31.0"
|
||||
dependencies:
|
||||
"@typescript-eslint/types": 5.30.7
|
||||
"@typescript-eslint/visitor-keys": 5.30.7
|
||||
"@typescript-eslint/types": 5.31.0
|
||||
"@typescript-eslint/visitor-keys": 5.31.0
|
||||
debug: ^4.3.4
|
||||
globby: ^11.1.0
|
||||
is-glob: ^4.0.3
|
||||
@@ -3005,7 +3005,7 @@ __metadata:
|
||||
peerDependenciesMeta:
|
||||
typescript:
|
||||
optional: true
|
||||
checksum: 7cff83a9b9c91a89bcbb677d539b7122b2a423a66f575364858b4635d7e53a25b9329cd20a5adfb732758a41d1c6801d4bfa3eb798a192f351aafb11eedc58b6
|
||||
checksum: 921c502ac4c93df9342d29636b384e154c3ac714e2be0308a4c9d3337d24d8b4721b76cbe700f70c7ceef06b50dfc404e4d4d734e446fe319bac030cb653d7b4
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -3027,19 +3027,19 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@typescript-eslint/utils@npm:5.30.7":
|
||||
version: 5.30.7
|
||||
resolution: "@typescript-eslint/utils@npm:5.30.7"
|
||||
"@typescript-eslint/utils@npm:5.31.0":
|
||||
version: 5.31.0
|
||||
resolution: "@typescript-eslint/utils@npm:5.31.0"
|
||||
dependencies:
|
||||
"@types/json-schema": ^7.0.9
|
||||
"@typescript-eslint/scope-manager": 5.30.7
|
||||
"@typescript-eslint/types": 5.30.7
|
||||
"@typescript-eslint/typescript-estree": 5.30.7
|
||||
"@typescript-eslint/scope-manager": 5.31.0
|
||||
"@typescript-eslint/types": 5.31.0
|
||||
"@typescript-eslint/typescript-estree": 5.31.0
|
||||
eslint-scope: ^5.1.1
|
||||
eslint-utils: ^3.0.0
|
||||
peerDependencies:
|
||||
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
|
||||
checksum: 77b0baf069f70290214294d74fdf7c46a7ddeab322ef53f65766b0c8e59f0e6f8074beb19233be34faca5beb390ac1b932dd1c983337355674c4437b4b1e2b44
|
||||
checksum: 2a4200fd8812f7d7dfbe381d856e97da3606f0c59de78829edd297cc76b4851316bf8362b65e66c7db399e9ea31ec71943626ec12022a552bcb7bb591259ec49
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -3053,13 +3053,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@typescript-eslint/visitor-keys@npm:5.30.7":
|
||||
version: 5.30.7
|
||||
resolution: "@typescript-eslint/visitor-keys@npm:5.30.7"
|
||||
"@typescript-eslint/visitor-keys@npm:5.31.0":
|
||||
version: 5.31.0
|
||||
resolution: "@typescript-eslint/visitor-keys@npm:5.31.0"
|
||||
dependencies:
|
||||
"@typescript-eslint/types": 5.30.7
|
||||
"@typescript-eslint/types": 5.31.0
|
||||
eslint-visitor-keys: ^3.3.0
|
||||
checksum: f322972aeda3143d4c24826436357937131f7fbad102d48cfa6dfca70ac245f93b20cf7beb5f1809bda4fe8f454676a6cabf8f73e39af6724076f2b2c213ee80
|
||||
checksum: 24ff3b9037b8fafe4f240b1c8a91981d658cd12a019f7961c9fe2f1d4dc84cf64e4071d865073191181b46652f4bd8f8cfc8e053ed8737ba1b9aede3e3252b3d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -9232,7 +9232,7 @@ resolve@^2.0.0-next.3:
|
||||
"@babel/core": ^7.18.9
|
||||
"@babel/register": ^7.18.9
|
||||
"@babel/runtime": ^7.18.9
|
||||
"@polkadot/dev": ^0.67.84
|
||||
"@polkadot/dev": ^0.67.85
|
||||
"@polkadot/typegen": "workspace:packages/typegen"
|
||||
"@types/jest": ^28.1.6
|
||||
copyfiles: ^2.4.1
|
||||
|
||||
Reference in New Issue
Block a user