Contract deployment salt (#4030)
This commit is contained in:
parent
ec68caafea
commit
aab2c26342
@ -12,11 +12,11 @@
|
||||
"packages/*"
|
||||
],
|
||||
"resolutions": {
|
||||
"@polkadot/api": "^2.6.2-15",
|
||||
"@polkadot/api-contract": "^2.6.2-15",
|
||||
"@polkadot/api": "^2.6.2-16",
|
||||
"@polkadot/api-contract": "^2.6.2-16",
|
||||
"@polkadot/keyring": "^4.1.1",
|
||||
"@polkadot/networks": "^4.1.1",
|
||||
"@polkadot/types": "^2.6.2-15",
|
||||
"@polkadot/types": "^2.6.2-16",
|
||||
"@polkadot/util": "^4.1.1",
|
||||
"@polkadot/util-crypto": "^4.1.1",
|
||||
"@polkadot/wasm-crypto": "^2.0.1",
|
||||
|
||||
@ -10,6 +10,6 @@
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/api-contract": "^2.6.2-15"
|
||||
"@polkadot/api-contract": "^2.6.2-16"
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ function Call ({ className = '', contract, messageIndex, onCallResult, onChangeM
|
||||
useEffect((): void => {
|
||||
value && message.isMutating && setExecTx((): SubmittableExtrinsic<'promise'> | null => {
|
||||
try {
|
||||
return contract.exec(message, message.isPayable ? value : 0, weight.weight, ...params);
|
||||
return contract.exec(message, { gasLimit: weight.weight, value: message.isPayable ? value : 0 }, ...params);
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
@ -64,7 +64,7 @@ function Call ({ className = '', contract, messageIndex, onCallResult, onChangeM
|
||||
if (!accountId || !message || !dbParams || !dbValue) return;
|
||||
|
||||
contract
|
||||
.read(message, message.isPayable ? dbValue : 0, -1, ...dbParams)
|
||||
.read(message, { gasLimit: -1, value: message.isPayable ? dbValue : 0 }, ...dbParams)
|
||||
.send(accountId)
|
||||
.then(({ gasConsumed, result }) => setEstimatedWeight(
|
||||
result.isOk
|
||||
@ -79,7 +79,7 @@ function Call ({ className = '', contract, messageIndex, onCallResult, onChangeM
|
||||
if (!accountId || !message || !value || !weight) return;
|
||||
|
||||
contract
|
||||
.read(message, message.isPayable ? value : 0, weight.isEmpty ? -1 : weight.weight, ...params)
|
||||
.read(message, { gasLimit: weight.isEmpty ? -1 : weight.weight, value: message.isPayable ? value : 0 }, ...params)
|
||||
.send(accountId)
|
||||
.then((result): void => {
|
||||
setOutcomes([{
|
||||
|
||||
@ -8,10 +8,12 @@ import { StringOrNull } from '@polkadot/react-components/types';
|
||||
import BN from 'bn.js';
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { BlueprintPromise } from '@polkadot/api-contract';
|
||||
import { Dropdown, InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components';
|
||||
import { Dropdown, Input, InputAddress, InputBalance, Modal, Toggle, TxButton } from '@polkadot/react-components';
|
||||
import { useFormField, useNonEmptyString, useNonZeroBn, useApi } from '@polkadot/react-hooks';
|
||||
import { Available } from '@polkadot/react-query';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import { isHex } from '@polkadot/util';
|
||||
import { randomAsHex } from '@polkadot/util-crypto';
|
||||
|
||||
import { ABI, InputMegaGas, InputName, MessageSignature, Params } from './shared';
|
||||
import store from './store';
|
||||
@ -35,6 +37,8 @@ function Deploy ({ codeHash, constructorIndex = 0, onClose, setConstructorIndex
|
||||
const [params, setParams] = useState<any[]>([]);
|
||||
const [accountId, isAccountIdValid, setAccountId] = useFormField<StringOrNull>(null);
|
||||
const [endowment, isEndowmentValid, setEndowment] = useNonZeroBn(new BN(ENDOWMENT));
|
||||
const [salt, setSalt] = useState(randomAsHex());
|
||||
const [withSalt, setWithSalt] = useState(false);
|
||||
|
||||
useEffect((): void => {
|
||||
setParams([]);
|
||||
@ -75,7 +79,7 @@ function Deploy ({ codeHash, constructorIndex = 0, onClose, setConstructorIndex
|
||||
endowment && setInitTx((): SubmittableExtrinsic<'promise'> | null => {
|
||||
if (blueprint) {
|
||||
try {
|
||||
return blueprint.createContract(constructorIndex, endowment, weight.weight, ...params);
|
||||
return blueprint.createContract(constructorIndex, { gasLimit: weight.weight, salt: withSalt ? salt : null, value: endowment }, ...params);
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
@ -83,7 +87,7 @@ function Deploy ({ codeHash, constructorIndex = 0, onClose, setConstructorIndex
|
||||
|
||||
return null;
|
||||
});
|
||||
}, [blueprint, constructorIndex, endowment, params, weight]);
|
||||
}, [blueprint, constructorIndex, endowment, params, salt, weight, withSalt]);
|
||||
|
||||
const _onSuccess = useCallback(
|
||||
(result: BlueprintSubmittableResult): void => {
|
||||
@ -103,7 +107,8 @@ function Deploy ({ codeHash, constructorIndex = 0, onClose, setConstructorIndex
|
||||
[api, name, onClose]
|
||||
);
|
||||
|
||||
const isValid = isNameValid && isEndowmentValid && weight.isValid && isAccountIdValid;
|
||||
const isSaltValid = !withSalt || (salt && (!salt.startsWith('0x') || isHex(salt)));
|
||||
const isValid = isNameValid && isEndowmentValid && weight.isValid && isAccountIdValid && isSaltValid;
|
||||
|
||||
return (
|
||||
<Modal header={t('Deploy a contract')}>
|
||||
@ -163,6 +168,21 @@ function Deploy ({ codeHash, constructorIndex = 0, onClose, setConstructorIndex
|
||||
onChange={setEndowment}
|
||||
value={endowment}
|
||||
/>
|
||||
<Input
|
||||
help={t<string>('A hex or string value that acts as a salt for this deployment.')}
|
||||
isDisabled={!withSalt}
|
||||
label={t<string>('unique deployment salt')}
|
||||
onChange={setSalt}
|
||||
placeholder={t<string>('0x prefixed hex, e.g. 0x1234 or ascii data')}
|
||||
value={withSalt ? salt : t<string>('<none>')}
|
||||
>
|
||||
<Toggle
|
||||
isOverlay
|
||||
label={t<string>('use deployment salt')}
|
||||
onChange={setWithSalt}
|
||||
value={withSalt}
|
||||
/>
|
||||
</Input>
|
||||
<InputMegaGas
|
||||
help={t<string>('The maximum amount of gas that can be used by this deployment, if the code requires more, the deployment will fail.')}
|
||||
weight={weight}
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
"homepage": "https://github.com/polkadot-js/apps/tree/master/packages/react-api#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/api": "^2.6.2-15",
|
||||
"@polkadot/api": "^2.6.2-16",
|
||||
"@polkadot/extension-dapp": "^0.35.0-beta.48",
|
||||
"rxjs-compat": "^6.6.3"
|
||||
}
|
||||
|
||||
106
yarn.lock
106
yarn.lock
@ -1980,55 +1980,55 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/api-contract@npm:^2.6.2-15":
|
||||
version: 2.6.2-15
|
||||
resolution: "@polkadot/api-contract@npm:2.6.2-15"
|
||||
"@polkadot/api-contract@npm:^2.6.2-16":
|
||||
version: 2.6.2-16
|
||||
resolution: "@polkadot/api-contract@npm:2.6.2-16"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.12.5
|
||||
"@polkadot/api": 2.6.2-15
|
||||
"@polkadot/types": 2.6.2-15
|
||||
"@polkadot/api": 2.6.2-16
|
||||
"@polkadot/types": 2.6.2-16
|
||||
"@polkadot/util": ^4.1.1
|
||||
bn.js: ^5.1.3
|
||||
rxjs: ^6.6.3
|
||||
checksum: ff468c76c9c2c11fd3551a8b0149f13c676419adc3dc91fc39018158f3fb22725de31850f0e2f14801f38884cc077d7165033ff17b8c78f22a19944adff5c263
|
||||
checksum: d0ec9efae7fdb9525924590d22598299ac3441a3c916cc1d402075798665c0127ac39f7adae2b9f62003a2b8ac74ec2b7aa54fddda376ce9b636e98223333104
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/api-derive@npm:2.6.2-15":
|
||||
version: 2.6.2-15
|
||||
resolution: "@polkadot/api-derive@npm:2.6.2-15"
|
||||
"@polkadot/api-derive@npm:2.6.2-16":
|
||||
version: 2.6.2-16
|
||||
resolution: "@polkadot/api-derive@npm:2.6.2-16"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.12.5
|
||||
"@polkadot/api": 2.6.2-15
|
||||
"@polkadot/rpc-core": 2.6.2-15
|
||||
"@polkadot/types": 2.6.2-15
|
||||
"@polkadot/api": 2.6.2-16
|
||||
"@polkadot/rpc-core": 2.6.2-16
|
||||
"@polkadot/types": 2.6.2-16
|
||||
"@polkadot/util": ^4.1.1
|
||||
"@polkadot/util-crypto": ^4.1.1
|
||||
bn.js: ^5.1.3
|
||||
memoizee: ^0.4.14
|
||||
rxjs: ^6.6.3
|
||||
checksum: b265719be1f7967bddbc52441f1004a13df465f79306c831ab8c9a538e9bcad6d3bdd8432051f546de857412f45c7fe25b5c849cfbcca36b2a3fc9f6fde1e4a7
|
||||
checksum: f11cefdab255695e5acc6c829808643fc857b77359bf9dec9c19bb88e379aac4a1ea2b7819f1312690d177c28e440f891d54aeb112c6406a1e46d272b118e6ee
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/api@npm:^2.6.2-15":
|
||||
version: 2.6.2-15
|
||||
resolution: "@polkadot/api@npm:2.6.2-15"
|
||||
"@polkadot/api@npm:^2.6.2-16":
|
||||
version: 2.6.2-16
|
||||
resolution: "@polkadot/api@npm:2.6.2-16"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.12.5
|
||||
"@polkadot/api-derive": 2.6.2-15
|
||||
"@polkadot/api-derive": 2.6.2-16
|
||||
"@polkadot/keyring": ^4.1.1
|
||||
"@polkadot/metadata": 2.6.2-15
|
||||
"@polkadot/rpc-core": 2.6.2-15
|
||||
"@polkadot/rpc-provider": 2.6.2-15
|
||||
"@polkadot/types": 2.6.2-15
|
||||
"@polkadot/types-known": 2.6.2-15
|
||||
"@polkadot/metadata": 2.6.2-16
|
||||
"@polkadot/rpc-core": 2.6.2-16
|
||||
"@polkadot/rpc-provider": 2.6.2-16
|
||||
"@polkadot/types": 2.6.2-16
|
||||
"@polkadot/types-known": 2.6.2-16
|
||||
"@polkadot/util": ^4.1.1
|
||||
"@polkadot/util-crypto": ^4.1.1
|
||||
bn.js: ^5.1.3
|
||||
eventemitter3: ^4.0.7
|
||||
rxjs: ^6.6.3
|
||||
checksum: 27b87954deef3e8196c7ec141ad94a2b774f93a2a7f6010f8711da0e23cad07a432abdfb21ccddd7842ad2f23281bc91a8df2dee99bcaef8ef09cb01c2404af2
|
||||
checksum: 4a8ad2acb06ef1837847800a96b2dbd713c9cee5fb246b536f7d3acb65ed35de37c4475a37bc33ad1d94566f74a659f3a6a63a928786157f3a51deb56a102196
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -2084,7 +2084,7 @@ __metadata:
|
||||
resolution: "@polkadot/app-contracts@workspace:packages/page-contracts"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.12.5
|
||||
"@polkadot/api-contract": ^2.6.2-15
|
||||
"@polkadot/api-contract": ^2.6.2-16
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@ -2494,17 +2494,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/metadata@npm:2.6.2-15":
|
||||
version: 2.6.2-15
|
||||
resolution: "@polkadot/metadata@npm:2.6.2-15"
|
||||
"@polkadot/metadata@npm:2.6.2-16":
|
||||
version: 2.6.2-16
|
||||
resolution: "@polkadot/metadata@npm:2.6.2-16"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.12.5
|
||||
"@polkadot/types": 2.6.2-15
|
||||
"@polkadot/types-known": 2.6.2-15
|
||||
"@polkadot/types": 2.6.2-16
|
||||
"@polkadot/types-known": 2.6.2-16
|
||||
"@polkadot/util": ^4.1.1
|
||||
"@polkadot/util-crypto": ^4.1.1
|
||||
bn.js: ^5.1.3
|
||||
checksum: ca4c784d4758460fb2dbb3a0bc65a525ca59fb94c8b78702747389fd7eeb2f112217c62cc8adec41e648cdf1bde6f09e2eb534150cb541d0002e2ab7624f76a6
|
||||
checksum: afcb49f5158817bc24ae76313e4d11739a41bc1a8f33fc8d6fb55858f55a04dfb740b551796173046df7197b66d1d504c234ec55e928ccc19f13b6983f0c3dbc
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -2522,7 +2522,7 @@ __metadata:
|
||||
resolution: "@polkadot/react-api@workspace:packages/react-api"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.12.5
|
||||
"@polkadot/api": ^2.6.2-15
|
||||
"@polkadot/api": ^2.6.2-16
|
||||
"@polkadot/extension-dapp": ^0.35.0-beta.48
|
||||
rxjs-compat: ^6.6.3
|
||||
languageName: unknown
|
||||
@ -2654,34 +2654,34 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/rpc-core@npm:2.6.2-15":
|
||||
version: 2.6.2-15
|
||||
resolution: "@polkadot/rpc-core@npm:2.6.2-15"
|
||||
"@polkadot/rpc-core@npm:2.6.2-16":
|
||||
version: 2.6.2-16
|
||||
resolution: "@polkadot/rpc-core@npm:2.6.2-16"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.12.5
|
||||
"@polkadot/metadata": 2.6.2-15
|
||||
"@polkadot/rpc-provider": 2.6.2-15
|
||||
"@polkadot/types": 2.6.2-15
|
||||
"@polkadot/metadata": 2.6.2-16
|
||||
"@polkadot/rpc-provider": 2.6.2-16
|
||||
"@polkadot/types": 2.6.2-16
|
||||
"@polkadot/util": ^4.1.1
|
||||
memoizee: ^0.4.14
|
||||
rxjs: ^6.6.3
|
||||
checksum: e8277aa4a7a3ecb842c1af8fed19eda31923fc1085b4269cf52cedae3546ca7d940a63837684309a62304a47d38fd621868070c65a15aaf07ac049a2cbadccc8
|
||||
checksum: e7acb97456aa5b4e53b76017a6c2eaa4e865dae4d123840ff31b8210998d32eb569cefbee918f56bf7b5179406b723929c02f4af3e1ed86a896b7532e98f8629
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/rpc-provider@npm:2.6.2-15":
|
||||
version: 2.6.2-15
|
||||
resolution: "@polkadot/rpc-provider@npm:2.6.2-15"
|
||||
"@polkadot/rpc-provider@npm:2.6.2-16":
|
||||
version: 2.6.2-16
|
||||
resolution: "@polkadot/rpc-provider@npm:2.6.2-16"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.12.5
|
||||
"@polkadot/types": 2.6.2-15
|
||||
"@polkadot/types": 2.6.2-16
|
||||
"@polkadot/util": ^4.1.1
|
||||
"@polkadot/util-crypto": ^4.1.1
|
||||
"@polkadot/x-fetch": ^4.1.1
|
||||
"@polkadot/x-ws": ^4.1.1
|
||||
bn.js: ^5.1.3
|
||||
eventemitter3: ^4.0.7
|
||||
checksum: acebb3a7eb909ab7bfea718dc9dce70db0b68a3c1a3cd1d2fa92530c0acfd84d901616bae332b546156cfaea024acce513e205f89c007291487ace43478f93d9
|
||||
checksum: 94d7154bf744dcc372d0f9c3a65104f60d24624f4ef14b3f61c1b832652302c9d4968a892043781e0f512e6a416f9e199bf42e288e5992595dacd0876834355d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -2694,31 +2694,31 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/types-known@npm:2.6.2-15":
|
||||
version: 2.6.2-15
|
||||
resolution: "@polkadot/types-known@npm:2.6.2-15"
|
||||
"@polkadot/types-known@npm:2.6.2-16":
|
||||
version: 2.6.2-16
|
||||
resolution: "@polkadot/types-known@npm:2.6.2-16"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.12.5
|
||||
"@polkadot/types": 2.6.2-15
|
||||
"@polkadot/types": 2.6.2-16
|
||||
"@polkadot/util": ^4.1.1
|
||||
bn.js: ^5.1.3
|
||||
checksum: db7201217ed4f0698987a269f919c91cce5cf8d9e9d0f2dfa96e09341f10b37fefeab7987a69846c3de964b4c8ec17677f334b262a6c4bdeb7004c9e2e752815
|
||||
checksum: 6ef25c42a3b421ad54b59682dae700e75f2c884c286be1c562b2add7fc3442c026308ac39e7bca13c0a8243040114bc959844610728d62351779d4f3fb2a0270
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/types@npm:^2.6.2-15":
|
||||
version: 2.6.2-15
|
||||
resolution: "@polkadot/types@npm:2.6.2-15"
|
||||
"@polkadot/types@npm:^2.6.2-16":
|
||||
version: 2.6.2-16
|
||||
resolution: "@polkadot/types@npm:2.6.2-16"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.12.5
|
||||
"@polkadot/metadata": 2.6.2-15
|
||||
"@polkadot/metadata": 2.6.2-16
|
||||
"@polkadot/util": ^4.1.1
|
||||
"@polkadot/util-crypto": ^4.1.1
|
||||
"@types/bn.js": ^4.11.6
|
||||
bn.js: ^5.1.3
|
||||
memoizee: ^0.4.14
|
||||
rxjs: ^6.6.3
|
||||
checksum: 37778d77ff0da3c13e81dc69c164b741e76b7a64e8998fde5b77910ec431c2280b8c31cb1ac8af43a4c9de5ed4de285123d26a2707245a56444e49b1f972d0d4
|
||||
checksum: 68ae0b71fa9e18d2633c1539fc0b1cd4ff6ef89a618fa107974206ff5f048f01ea76cd41c24384de1e04fc9f162dd168ef36816f7bf1a337c263cff13244b9e0
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user