diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fc8e00d2c..b1d68d589a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Changes: - Add missing historic `Heartbeat: HeartbeatTo244` mapping to Westend +- Contract reads will now expose an additional `gasRequired` ## 4.17.1 Jul 5, 2021 diff --git a/packages/api-contract/src/base/Contract.ts b/packages/api-contract/src/base/Contract.ts index a9c4832b69..d888bcd195 100644 --- a/packages/api-contract/src/base/Contract.ts +++ b/packages/api-contract/src/base/Contract.ts @@ -145,9 +145,12 @@ export class Contract extends Base { value }) .pipe( - map(({ debugMessage, gasConsumed, result }): ContractCallOutcome => ({ + map(({ debugMessage, gasConsumed, gasRequired, result }): ContractCallOutcome => ({ debugMessage, gasConsumed, + gasRequired: gasRequired && !gasRequired.isZero() + ? gasRequired + : gasConsumed, output: result.isOk && message.returnType ? createTypeUnsafe(this.registry, message.returnType.type, [result.asOk.data.toU8a(true)], { isPedantic: true }) : null, diff --git a/packages/api-contract/src/types.ts b/packages/api-contract/src/types.ts index 8350c7db4f..711d4c80f7 100644 --- a/packages/api-contract/src/types.ts +++ b/packages/api-contract/src/types.ts @@ -55,6 +55,7 @@ export interface InterfaceContractCalls { export interface ContractCallOutcome { debugMessage: Text; gasConsumed: u64; + gasRequired: u64; output: Codec | null; result: ContractExecResultResult; } diff --git a/packages/types/src/augment/registry.ts b/packages/types/src/augment/registry.ts index b921cc1e9b..e5e09a7fc4 100644 --- a/packages/types/src/augment/registry.ts +++ b/packages/types/src/augment/registry.ts @@ -16,7 +16,7 @@ import type { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate'; import type { EthereumAddress, StatementKind } from '@polkadot/types/interfaces/claims'; import type { CollectiveOrigin, MemberCount, ProposalIndex, Votes, VotesTo230 } from '@polkadot/types/interfaces/collective'; import type { AuthorityId, RawVRFOutput } from '@polkadot/types/interfaces/consensus'; -import type { AliveContractInfo, CodeHash, ContractCallRequest, ContractExecResult, ContractExecResultErr, ContractExecResultErrModule, ContractExecResultOk, ContractExecResultResult, ContractExecResultSuccessTo255, ContractExecResultSuccessTo260, ContractExecResultTo255, ContractExecResultTo260, ContractInfo, ContractInstantiateResult, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateReturnValue, InstructionWeights, Limits, LimitsTo264, PrefabWasmModule, RentProjection, Schedule, ScheduleTo212, ScheduleTo258, ScheduleTo264, SeedOf, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts'; +import type { AliveContractInfo, CodeHash, ContractCallRequest, ContractExecResult, ContractExecResultErr, ContractExecResultErrModule, ContractExecResultOk, ContractExecResultResult, ContractExecResultSuccessTo255, ContractExecResultSuccessTo260, ContractExecResultTo255, ContractExecResultTo260, ContractExecResultTo267, ContractInfo, ContractInstantiateResult, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateReturnValue, InstructionWeights, Limits, LimitsTo264, PrefabWasmModule, RentProjection, Schedule, ScheduleTo212, ScheduleTo258, ScheduleTo264, SeedOf, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts'; import type { ContractConstructorSpec, ContractContractSpec, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEventParamSpec, ContractEventSpec, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpec, ContractMessageSpec, ContractProject, ContractProjectContract, ContractProjectSource, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi'; import type { FundIndex, FundInfo, LastContribution, TrieIndex } from '@polkadot/types/interfaces/crowdloan'; import type { ConfigData, MessageId, OverweightIndex, PageCounter, PageIndexData } from '@polkadot/types/interfaces/cumulus'; @@ -315,6 +315,7 @@ declare module '@polkadot/types/types/registry' { 'Option': Option; 'Option': Option; 'Option': Option; + 'Option': Option; 'Option': Option; 'Option': Option; 'Option': Option; @@ -1195,6 +1196,7 @@ declare module '@polkadot/types/types/registry' { 'Vec': Vec; 'Vec': Vec; 'Vec': Vec; + 'Vec': Vec; 'Vec': Vec; 'Vec': Vec; 'Vec': Vec; @@ -2075,6 +2077,7 @@ declare module '@polkadot/types/types/registry' { ContractExecResultSuccessTo260: ContractExecResultSuccessTo260; ContractExecResultTo255: ContractExecResultTo255; ContractExecResultTo260: ContractExecResultTo260; + ContractExecResultTo267: ContractExecResultTo267; ContractInfo: ContractInfo; ContractInstantiateResult: ContractInstantiateResult; ContractLayoutArray: ContractLayoutArray; diff --git a/packages/types/src/interfaces/contracts/definitions.ts b/packages/types/src/interfaces/contracts/definitions.ts index 23513969e5..1f67124667 100644 --- a/packages/types/src/interfaces/contracts/definitions.ts +++ b/packages/types/src/interfaces/contracts/definitions.ts @@ -141,8 +141,14 @@ export default { Err: 'ContractExecResultErr' } }, + ContractExecResultTo267: { + gasConsumed: 'u64', + debugMessage: 'Text', + result: 'ContractExecResultResult' + }, ContractExecResult: { gasConsumed: 'u64', + gasRequired: 'u64', debugMessage: 'Text', result: 'ContractExecResultResult' }, diff --git a/packages/types/src/interfaces/contracts/types.ts b/packages/types/src/interfaces/contracts/types.ts index 6f8b080887..01bedece8a 100644 --- a/packages/types/src/interfaces/contracts/types.ts +++ b/packages/types/src/interfaces/contracts/types.ts @@ -32,6 +32,7 @@ export interface ContractCallRequest extends Struct { /** @name ContractExecResult */ export interface ContractExecResult extends Struct { readonly gasConsumed: u64; + readonly gasRequired: u64; readonly debugMessage: Text; readonly result: ContractExecResultResult; } @@ -94,6 +95,13 @@ export interface ContractExecResultTo260 extends Enum { readonly isError: boolean; } +/** @name ContractExecResultTo267 */ +export interface ContractExecResultTo267 extends Struct { + readonly gasConsumed: u64; + readonly debugMessage: Text; + readonly result: ContractExecResultResult; +} + /** @name ContractInfo */ export interface ContractInfo extends Enum { readonly isAlive: boolean;