Use BN_* constants in contract default params (#3507)
This commit is contained in:
@@ -22,8 +22,8 @@
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/api": "4.9.3-5",
|
||||
"@polkadot/types": "4.9.3-5",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/x-rxjs": "^6.3.1",
|
||||
"@polkadot/util": "^6.3.2-6",
|
||||
"@polkadot/x-rxjs": "^6.3.2-6",
|
||||
"bn.js": "^4.11.9"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { MapConstructorExec } from './types';
|
||||
|
||||
import { SubmittableResult } from '@polkadot/api';
|
||||
import { ApiBase } from '@polkadot/api/base';
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
import { BN_ZERO, isUndefined } from '@polkadot/util';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { applyOnEvent } from '../util';
|
||||
@@ -52,7 +52,7 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
return this.#tx;
|
||||
}
|
||||
|
||||
#deploy = (constructorOrId: AbiConstructor | string | number, { gasLimit = 0, salt, value = 0 }: BlueprintOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType, BlueprintSubmittableResult<ApiType>> => {
|
||||
#deploy = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, value = BN_ZERO }: BlueprintOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType, BlueprintSubmittableResult<ApiType>> => {
|
||||
const encodedSalt = encodeSalt(salt);
|
||||
const withSalt = this.api.tx.contracts.instantiate.meta.args.length === 5;
|
||||
const encoded = this.abi.findConstructor(constructorOrId).toU8a(params, withSalt ? EMPTY_SALT : encodedSalt);
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { MapConstructorExec } from './types';
|
||||
|
||||
import { SubmittableResult } from '@polkadot/api';
|
||||
import { ApiBase } from '@polkadot/api/base';
|
||||
import { assert, compactAddLength, isFunction, isUndefined, isWasm, u8aToU8a } from '@polkadot/util';
|
||||
import { assert, BN_ZERO, compactAddLength, isFunction, isUndefined, isWasm, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
@@ -63,13 +63,13 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
: this.#instantiatePrev(constructorOrId, options, params);
|
||||
}
|
||||
|
||||
#instantiateCurrent = (constructorOrId: AbiConstructor | string | number, { gasLimit = 0, salt, value = 0 }: BlueprintOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
|
||||
#instantiateCurrent = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, value = BN_ZERO }: BlueprintOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
|
||||
return this.api.tx.contracts
|
||||
.instantiateWithCode(value, gasLimit, compactAddLength(this.code), this.abi.findConstructor(constructorOrId).toU8a(params), encodeSalt(salt))
|
||||
.withResultTransform(this.#transformEvents);
|
||||
}
|
||||
|
||||
#instantiatePrev = (constructorOrId: AbiConstructor | string | number, { gasLimit = 0, salt, value = 0 }: BlueprintOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
|
||||
#instantiatePrev = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, value = BN_ZERO }: BlueprintOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
|
||||
assert(isFunction(this.api.tx.utility?.batch), 'Your chain does not include the utility pallet, for contracts v2 deployment, this is required');
|
||||
|
||||
const encodedSalt = encodeSalt(salt);
|
||||
|
||||
@@ -13,7 +13,7 @@ import BN from 'bn.js';
|
||||
|
||||
import { SubmittableResult } from '@polkadot/api';
|
||||
import { ApiBase } from '@polkadot/api/base';
|
||||
import { assert, bnToBn, isFunction, isUndefined, logger } from '@polkadot/util';
|
||||
import { assert, BN_HUNDRED, BN_ONE, BN_ZERO, bnToBn, isFunction, isUndefined, logger } from '@polkadot/util';
|
||||
import { map } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
@@ -21,7 +21,7 @@ import { applyOnEvent, extractOptions, formatData, isOptions } from '../util';
|
||||
import { Base } from './Base';
|
||||
|
||||
// As per Rust, 5 * GAS_PER_SEC
|
||||
const MAX_CALL_GAS = new BN(5_000_000_000_000).subn(1);
|
||||
const MAX_CALL_GAS = new BN(5_000_000_000_000).isub(BN_ONE);
|
||||
const ERROR_NO_CALL = 'Your node does not expose the contracts.call RPC. This is most probably due to a runtime configuration.';
|
||||
|
||||
const l = logger('Contract');
|
||||
@@ -120,17 +120,17 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
#getGas = (_gasLimit: BigInt | BN | string | number, isCall = false): BN => {
|
||||
const gasLimit = bnToBn(_gasLimit);
|
||||
|
||||
return gasLimit.lten(0)
|
||||
return gasLimit.lte(BN_ZERO)
|
||||
? isCall
|
||||
? MAX_CALL_GAS
|
||||
: (this.api.consts.system.blockWeights
|
||||
? this.api.consts.system.blockWeights.maxBlock
|
||||
: this.api.consts.system.maximumBlockWeight as Weight
|
||||
).muln(64).divn(100)
|
||||
).muln(64).div(BN_HUNDRED)
|
||||
: gasLimit;
|
||||
}
|
||||
|
||||
#exec = (messageOrId: AbiMessage | string | number, { gasLimit = 0, value = 0 }: ContractOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType> => {
|
||||
#exec = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, value = BN_ZERO }: ContractOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType> => {
|
||||
return this.api.tx.contracts
|
||||
.call(this.address, value, this.#getGas(gasLimit), this.abi.findMessage(messageOrId).toU8a(params))
|
||||
.withResultTransform((result: ISubmittableResult) =>
|
||||
@@ -151,7 +151,7 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
);
|
||||
}
|
||||
|
||||
#read = (messageOrId: AbiMessage | string | number, { gasLimit = 0, value = 0 }: ContractOptions, params: CodecArg[]): ContractCallSend<ApiType> => {
|
||||
#read = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, value = BN_ZERO }: ContractOptions, params: CodecArg[]): ContractCallSend<ApiType> => {
|
||||
assert(this.hasRpcContractsCall, ERROR_NO_CALL);
|
||||
|
||||
const message = this.abi.findMessage(messageOrId);
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
"@polkadot/api": "4.9.3-5",
|
||||
"@polkadot/rpc-core": "4.9.3-5",
|
||||
"@polkadot/types": "4.9.3-5",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/util-crypto": "^6.3.1",
|
||||
"@polkadot/x-rxjs": "^6.3.1",
|
||||
"@polkadot/util": "^6.3.2-6",
|
||||
"@polkadot/util-crypto": "^6.3.2-6",
|
||||
"@polkadot/x-rxjs": "^6.3.2-6",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^6.3.1",
|
||||
"@polkadot/keyring": "^6.3.2-6",
|
||||
"@polkadot/rpc-provider": "4.9.3-5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/api-derive": "4.9.3-5",
|
||||
"@polkadot/keyring": "^6.3.1",
|
||||
"@polkadot/keyring": "^6.3.2-6",
|
||||
"@polkadot/metadata": "4.9.3-5",
|
||||
"@polkadot/rpc-core": "4.9.3-5",
|
||||
"@polkadot/rpc-provider": "4.9.3-5",
|
||||
"@polkadot/types": "4.9.3-5",
|
||||
"@polkadot/types-known": "4.9.3-5",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/util-crypto": "^6.3.1",
|
||||
"@polkadot/x-rxjs": "^6.3.1",
|
||||
"@polkadot/util": "^6.3.2-6",
|
||||
"@polkadot/util-crypto": "^6.3.2-6",
|
||||
"@polkadot/x-rxjs": "^6.3.2-6",
|
||||
"bn.js": "^4.11.9",
|
||||
"eventemitter3": "^4.0.7"
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/types": "4.9.3-5",
|
||||
"@polkadot/types-known": "4.9.3-5",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/util-crypto": "^6.3.1",
|
||||
"@polkadot/util": "^6.3.2-6",
|
||||
"@polkadot/util-crypto": "^6.3.2-6",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^6.3.1"
|
||||
"@polkadot/keyring": "^6.3.2-6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
"@polkadot/metadata": "4.9.3-5",
|
||||
"@polkadot/rpc-provider": "4.9.3-5",
|
||||
"@polkadot/types": "4.9.3-5",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/x-rxjs": "^6.3.1"
|
||||
"@polkadot/util": "^6.3.2-6",
|
||||
"@polkadot/x-rxjs": "^6.3.2-6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^6.3.1"
|
||||
"@polkadot/keyring": "^6.3.2-6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,16 +21,16 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/types": "4.9.3-5",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/util-crypto": "^6.3.1",
|
||||
"@polkadot/x-fetch": "^6.3.1",
|
||||
"@polkadot/x-global": "^6.3.1",
|
||||
"@polkadot/x-ws": "^6.3.1",
|
||||
"@polkadot/util": "^6.3.2-6",
|
||||
"@polkadot/util-crypto": "^6.3.2-6",
|
||||
"@polkadot/x-fetch": "^6.3.2-6",
|
||||
"@polkadot/x-global": "^6.3.2-6",
|
||||
"@polkadot/x-ws": "^6.3.2-6",
|
||||
"bn.js": "^4.11.9",
|
||||
"eventemitter3": "^4.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^6.3.1",
|
||||
"@polkadot/keyring": "^6.3.2-6",
|
||||
"@polkadot/metadata": "4.9.3-5",
|
||||
"mock-socket": "^9.0.3",
|
||||
"nock": "^13.0.11"
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"@polkadot/metadata": "4.9.3-5",
|
||||
"@polkadot/rpc-provider": "4.9.3-5",
|
||||
"@polkadot/types": "4.9.3-5",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/util": "^6.3.2-6",
|
||||
"handlebars": "^4.7.7",
|
||||
"websocket": "^1.0.34",
|
||||
"yargs": "^17.0.1"
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/networks": "^6.3.1",
|
||||
"@polkadot/networks": "^6.3.2-6",
|
||||
"@polkadot/types": "4.9.3-5",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/util": "^6.3.2-6",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/metadata": "4.9.3-5",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/util-crypto": "^6.3.1",
|
||||
"@polkadot/x-rxjs": "^6.3.1",
|
||||
"@polkadot/util": "^6.3.2-6",
|
||||
"@polkadot/util-crypto": "^6.3.2-6",
|
||||
"@polkadot/x-rxjs": "^6.3.2-6",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^6.3.1"
|
||||
"@polkadot/keyring": "^6.3.2-6"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user