Support for contracts metadata V2 (#4289)

* Support for contracts metadata V2

* Add & use latest

* Build interfaces

* conversion of V1 -> Latest

* spreads

* Use V2 in creation, aka s/name/label/

* Extract -> latest conversion

* Flatten

* Add V2 test contracts (tests are failing)

* V2, V1 & V1 catered for in Abi.spec.ts

* Explicit v0/v1 -> Latest conversions

* Adjust V2/V1/V0 check order

* Cleanup type assertions

* Save

* Remove eslint unsafe

* Flatten test exports

* Entries... last non-critical, OCD-driven change...

* tsc check fixes

* Conversion tests

* v1ToLatest renames

* Text[]

* Split conversion (ease of future change)

* V2 in V2 conversion

* Dedupe?

* Additional cleanups

* Adjust

* Flatten types

* Adjust

* filter versions adjustments

* additional, get it done.
This commit is contained in:
Jaco
2021-12-08 19:14:51 +02:00
committed by GitHub
parent 610f03d006
commit a30329b47d
37 changed files with 1556 additions and 350 deletions
+19 -7
View File
@@ -18,7 +18,7 @@ declare module '@polkadot/types/types/registry' {
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, ContractExecResultTo267, ContractInfo, ContractInstantiateResult, ContractInstantiateResultTo267, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateReturnValue, InstantiateReturnValueTo267, 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, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi';
import type { ContractConstructorSpecLatest, ContractConstructorSpecV0, ContractConstructorSpecV2, ContractContractSpecV0, ContractContractSpecV2, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEventParamSpecLatest, ContractEventParamSpecV0, ContractEventParamSpecV2, ContractEventSpecLatest, ContractEventSpecV0, ContractEventSpecV2, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpecLatest, ContractMessageParamSpecV0, ContractMessageParamSpecV2, ContractMessageSpecLatest, ContractMessageSpecV0, ContractMessageSpecV2, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractMetadataV2, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, 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';
import type { AccountVote, AccountVoteSplit, AccountVoteStandard, Conviction, Delegations, PreimageStatus, PreimageStatusAvailable, PriorLock, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, ReferendumStatus, Tally, Voting, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces/democracy';
@@ -212,13 +212,20 @@ declare module '@polkadot/types/types/registry' {
ConsensusEngineId: ConsensusEngineId;
ConsumedWeight: ConsumedWeight;
ContractCallRequest: ContractCallRequest;
ContractConstructorSpec: ContractConstructorSpec;
ContractContractSpec: ContractContractSpec;
ContractConstructorSpecLatest: ContractConstructorSpecLatest;
ContractConstructorSpecV0: ContractConstructorSpecV0;
ContractConstructorSpecV2: ContractConstructorSpecV2;
ContractContractSpecV0: ContractContractSpecV0;
ContractContractSpecV2: ContractContractSpecV2;
ContractCryptoHasher: ContractCryptoHasher;
ContractDiscriminant: ContractDiscriminant;
ContractDisplayName: ContractDisplayName;
ContractEventParamSpec: ContractEventParamSpec;
ContractEventSpec: ContractEventSpec;
ContractEventParamSpecLatest: ContractEventParamSpecLatest;
ContractEventParamSpecV0: ContractEventParamSpecV0;
ContractEventParamSpecV2: ContractEventParamSpecV2;
ContractEventSpecLatest: ContractEventSpecLatest;
ContractEventSpecV0: ContractEventSpecV0;
ContractEventSpecV2: ContractEventSpecV2;
ContractExecResult: ContractExecResult;
ContractExecResultErr: ContractExecResultErr;
ContractExecResultErrModule: ContractExecResultErrModule;
@@ -240,12 +247,17 @@ declare module '@polkadot/types/types/registry' {
ContractLayoutKey: ContractLayoutKey;
ContractLayoutStruct: ContractLayoutStruct;
ContractLayoutStructField: ContractLayoutStructField;
ContractMessageParamSpec: ContractMessageParamSpec;
ContractMessageSpec: ContractMessageSpec;
ContractMessageParamSpecLatest: ContractMessageParamSpecLatest;
ContractMessageParamSpecV0: ContractMessageParamSpecV0;
ContractMessageParamSpecV2: ContractMessageParamSpecV2;
ContractMessageSpecLatest: ContractMessageSpecLatest;
ContractMessageSpecV0: ContractMessageSpecV0;
ContractMessageSpecV2: ContractMessageSpecV2;
ContractMetadata: ContractMetadata;
ContractMetadataLatest: ContractMetadataLatest;
ContractMetadataV0: ContractMetadataV0;
ContractMetadataV1: ContractMetadataV1;
ContractMetadataV2: ContractMetadataV2;
ContractProject: ContractProject;
ContractProjectContract: ContractProjectContract;
ContractProjectInfo: ContractProjectInfo;
@@ -6,77 +6,10 @@
import type { Definitions } from '../../types';
import rpc from './rpc';
export default {
rpc: {
call: {
description: 'Executes a call to a contract',
params: [
{
name: 'callRequest',
type: 'ContractCallRequest'
},
{
name: 'at',
type: 'BlockHash',
isHistoric: true,
isOptional: true
}
],
type: 'ContractExecResult'
},
instantiate: {
description: 'Instantiate a new contract',
params: [
{
name: 'request',
type: 'InstantiateRequest'
},
{
name: 'at',
type: 'BlockHash',
isHstoric: true,
isOptional: true
}
],
type: 'ContractInstantiateResult'
},
getStorage: {
description: 'Returns the value under a specified storage key in a contract',
params: [
{
name: 'address',
type: 'AccountId'
},
{
name: 'key',
type: 'H256'
},
{
name: 'at',
type: 'BlockHash',
isHistoric: true,
isOptional: true
}
],
type: 'Option<Bytes>'
},
rentProjection: {
description: 'Returns the projected time a given contract will be able to sustain paying its rent',
params: [
{
name: 'address',
type: 'AccountId'
},
{
name: 'at',
type: 'BlockHash',
isHistoric: true,
isOptional: true
}
],
type: 'Option<BlockNumber>'
}
},
rpc,
types: {
AliveContractInfo: {
trieId: 'TrieId',
@@ -0,0 +1,78 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
// order important in structs... :)
/* eslint-disable sort-keys */
import type { DefinitionsRpc } from '../../types';
export default {
call: {
description: 'Executes a call to a contract',
params: [
{
name: 'callRequest',
type: 'ContractCallRequest'
},
{
name: 'at',
type: 'BlockHash',
isHistoric: true,
isOptional: true
}
],
type: 'ContractExecResult'
},
instantiate: {
description: 'Instantiate a new contract',
params: [
{
name: 'request',
type: 'InstantiateRequest'
},
{
name: 'at',
type: 'BlockHash',
isHstoric: true,
isOptional: true
}
],
type: 'ContractInstantiateResult'
},
getStorage: {
description: 'Returns the value under a specified storage key in a contract',
params: [
{
name: 'address',
type: 'AccountId'
},
{
name: 'key',
type: 'H256'
},
{
name: 'at',
type: 'BlockHash',
isHistoric: true,
isOptional: true
}
],
type: 'Option<Bytes>'
},
rentProjection: {
description: 'Returns the projected time a given contract will be able to sustain paying its rent',
params: [
{
name: 'address',
type: 'AccountId'
},
{
name: 'at',
type: 'BlockHash',
isHistoric: true,
isOptional: true
}
],
type: 'Option<BlockNumber>'
}
} as DefinitionsRpc;
@@ -57,40 +57,76 @@ const layout = {
};
const spec = {
ContractConstructorSpec: {
ContractConstructorSpecV0: {
name: 'Text',
selector: 'ContractSelector',
args: 'Vec<ContractMessageParamSpec>',
args: 'Vec<ContractMessageParamSpecV0>',
docs: 'Vec<Text>'
},
ContractContractSpec: {
constructors: 'Vec<ContractConstructorSpec>',
messages: 'Vec<ContractMessageSpec>',
events: 'Vec<ContractEventSpec>',
ContractConstructorSpecV2: {
label: 'Text',
selector: 'ContractSelector',
args: 'Vec<ContractMessageParamSpecV2>',
docs: 'Vec<Text>'
},
ContractContractSpecV0: {
constructors: 'Vec<ContractConstructorSpecV0>',
messages: 'Vec<ContractMessageSpecV0>',
events: 'Vec<ContractEventSpecV0>',
docs: 'Vec<Text>'
},
ContractContractSpecV2: {
constructors: 'Vec<ContractConstructorSpecV2>',
messages: 'Vec<ContractMessageSpecV2>',
events: 'Vec<ContractEventSpecV2>',
docs: 'Vec<Text>'
},
ContractDisplayName: 'SiPath',
ContractEventParamSpec: {
ContractEventParamSpecV0: {
name: 'Text',
indexed: 'bool',
type: 'ContractTypeSpec',
docs: 'Vec<Text>'
},
ContractEventSpec: {
name: 'Text',
args: 'Vec<ContractEventParamSpec>',
ContractEventParamSpecV2: {
label: 'Text',
indexed: 'bool',
type: 'ContractTypeSpec',
docs: 'Vec<Text>'
},
ContractMessageParamSpec: {
ContractEventSpecV0: {
name: 'Text',
args: 'Vec<ContractEventParamSpecV0>',
docs: 'Vec<Text>'
},
ContractEventSpecV2: {
label: 'Text',
args: 'Vec<ContractEventParamSpecV2>',
docs: 'Vec<Text>'
},
ContractMessageParamSpecV0: {
name: 'Text',
type: 'ContractTypeSpec'
},
ContractMessageSpec: {
ContractMessageParamSpecV2: {
label: 'Text',
type: 'ContractTypeSpec'
},
ContractMessageSpecV0: {
name: 'Text',
selector: 'ContractSelector',
mutates: 'bool',
payable: 'bool',
args: 'Vec<ContractMessageParamSpec>',
args: 'Vec<ContractMessageParamSpecV0>',
returnType: 'Option<ContractTypeSpec>',
docs: 'Vec<Text>'
},
ContractMessageSpecV2: {
label: 'Text',
selector: 'ContractSelector',
mutates: 'bool',
payable: 'bool',
args: 'Vec<ContractMessageParamSpecV2>',
returnType: 'Option<ContractTypeSpec>',
docs: 'Vec<Text>'
},
@@ -103,12 +139,17 @@ const spec = {
const ContractMetadataV0 = {
types: 'Vec<Si0Type>',
spec: 'ContractContractSpec'
spec: 'ContractContractSpecV0'
};
const ContractMetadataV1 = {
types: 'Vec<PortableType>',
spec: 'ContractContractSpec'
spec: 'ContractContractSpecV0'
};
const ContractMetadataV2 = {
types: 'Vec<PortableType>',
spec: 'ContractContractSpecV2'
};
const ContractProjectInfo = {
@@ -116,19 +157,29 @@ const ContractProjectInfo = {
contract: 'ContractProjectContract'
};
const latest = {
ContractConstructorSpecLatest: 'ContractConstructorSpecV2',
ContractEventSpecLatest: 'ContractEventSpecV2',
ContractEventParamSpecLatest: 'ContractEventParamSpecV2',
ContractMessageParamSpecLatest: 'ContractMessageParamSpecV2',
ContractMessageSpecLatest: 'ContractMessageSpecV2',
ContractMetadataLatest: 'ContractMetadataV2'
};
export default {
rpc: {},
types: objectSpread({}, layout, spec, {
types: objectSpread({}, layout, spec, latest, {
ContractProjectInfo,
ContractMetadataV0,
ContractMetadataV1,
ContractMetadataV2,
ContractMetadata: {
_enum: {
V0: 'ContractMetadataV0',
V1: 'ContractMetadataV1'
V1: 'ContractMetadataV1',
V2: 'ContractMetadataV2'
}
},
ContractMetadataLatest: 'ContractMetadataV1',
ContractProjectV0: objectSpread({ metadataVersion: 'Text' }, ContractProjectInfo, ContractMetadataV0),
ContractProject: '(ContractProjectInfo, ContractMetadata)',
ContractProjectContract: {
@@ -6,19 +6,38 @@ import type { BTreeMap, Bytes, Enum, Option, Raw, Struct, Text, U8aFixed, Vec, b
import type { Si0Type, SiLookupTypeId, SiPath } from '@polkadot/types/interfaces/scaleInfo';
import type { ITuple } from '@polkadot/types/types';
/** @name ContractConstructorSpec */
export interface ContractConstructorSpec extends Struct {
/** @name ContractConstructorSpecLatest */
export interface ContractConstructorSpecLatest extends ContractConstructorSpecV2 {}
/** @name ContractConstructorSpecV0 */
export interface ContractConstructorSpecV0 extends Struct {
readonly name: Text;
readonly selector: ContractSelector;
readonly args: Vec<ContractMessageParamSpec>;
readonly args: Vec<ContractMessageParamSpecV0>;
readonly docs: Vec<Text>;
}
/** @name ContractContractSpec */
export interface ContractContractSpec extends Struct {
readonly constructors: Vec<ContractConstructorSpec>;
readonly messages: Vec<ContractMessageSpec>;
readonly events: Vec<ContractEventSpec>;
/** @name ContractConstructorSpecV2 */
export interface ContractConstructorSpecV2 extends Struct {
readonly label: Text;
readonly selector: ContractSelector;
readonly args: Vec<ContractMessageParamSpecV2>;
readonly docs: Vec<Text>;
}
/** @name ContractContractSpecV0 */
export interface ContractContractSpecV0 extends Struct {
readonly constructors: Vec<ContractConstructorSpecV0>;
readonly messages: Vec<ContractMessageSpecV0>;
readonly events: Vec<ContractEventSpecV0>;
readonly docs: Vec<Text>;
}
/** @name ContractContractSpecV2 */
export interface ContractContractSpecV2 extends Struct {
readonly constructors: Vec<ContractConstructorSpecV2>;
readonly messages: Vec<ContractMessageSpecV2>;
readonly events: Vec<ContractEventSpecV2>;
readonly docs: Vec<Text>;
}
@@ -36,18 +55,39 @@ export interface ContractDiscriminant extends u32 {}
/** @name ContractDisplayName */
export interface ContractDisplayName extends SiPath {}
/** @name ContractEventParamSpec */
export interface ContractEventParamSpec extends Struct {
/** @name ContractEventParamSpecLatest */
export interface ContractEventParamSpecLatest extends ContractEventParamSpecV2 {}
/** @name ContractEventParamSpecV0 */
export interface ContractEventParamSpecV0 extends Struct {
readonly name: Text;
readonly indexed: bool;
readonly type: ContractTypeSpec;
readonly docs: Vec<Text>;
}
/** @name ContractEventSpec */
export interface ContractEventSpec extends Struct {
/** @name ContractEventParamSpecV2 */
export interface ContractEventParamSpecV2 extends Struct {
readonly label: Text;
readonly indexed: bool;
readonly type: ContractTypeSpec;
readonly docs: Vec<Text>;
}
/** @name ContractEventSpecLatest */
export interface ContractEventSpecLatest extends ContractEventSpecV2 {}
/** @name ContractEventSpecV0 */
export interface ContractEventSpecV0 extends Struct {
readonly name: Text;
readonly args: Vec<ContractEventParamSpec>;
readonly args: Vec<ContractEventParamSpecV0>;
readonly docs: Vec<Text>;
}
/** @name ContractEventSpecV2 */
export interface ContractEventSpecV2 extends Struct {
readonly label: Text;
readonly args: Vec<ContractEventParamSpecV2>;
readonly docs: Vec<Text>;
}
@@ -99,19 +139,42 @@ export interface ContractLayoutStructField extends Struct {
readonly name: Text;
}
/** @name ContractMessageParamSpec */
export interface ContractMessageParamSpec extends Struct {
/** @name ContractMessageParamSpecLatest */
export interface ContractMessageParamSpecLatest extends ContractMessageParamSpecV2 {}
/** @name ContractMessageParamSpecV0 */
export interface ContractMessageParamSpecV0 extends Struct {
readonly name: Text;
readonly type: ContractTypeSpec;
}
/** @name ContractMessageSpec */
export interface ContractMessageSpec extends Struct {
/** @name ContractMessageParamSpecV2 */
export interface ContractMessageParamSpecV2 extends Struct {
readonly label: Text;
readonly type: ContractTypeSpec;
}
/** @name ContractMessageSpecLatest */
export interface ContractMessageSpecLatest extends ContractMessageSpecV2 {}
/** @name ContractMessageSpecV0 */
export interface ContractMessageSpecV0 extends Struct {
readonly name: Text;
readonly selector: ContractSelector;
readonly mutates: bool;
readonly payable: bool;
readonly args: Vec<ContractMessageParamSpec>;
readonly args: Vec<ContractMessageParamSpecV0>;
readonly returnType: Option<ContractTypeSpec>;
readonly docs: Vec<Text>;
}
/** @name ContractMessageSpecV2 */
export interface ContractMessageSpecV2 extends Struct {
readonly label: Text;
readonly selector: ContractSelector;
readonly mutates: bool;
readonly payable: bool;
readonly args: Vec<ContractMessageParamSpecV2>;
readonly returnType: Option<ContractTypeSpec>;
readonly docs: Vec<Text>;
}
@@ -122,22 +185,30 @@ export interface ContractMetadata extends Enum {
readonly asV0: ContractMetadataV0;
readonly isV1: boolean;
readonly asV1: ContractMetadataV1;
readonly type: 'V0' | 'V1';
readonly isV2: boolean;
readonly asV2: ContractMetadataV2;
readonly type: 'V0' | 'V1' | 'V2';
}
/** @name ContractMetadataLatest */
export interface ContractMetadataLatest extends ContractMetadataV1 {}
export interface ContractMetadataLatest extends ContractMetadataV2 {}
/** @name ContractMetadataV0 */
export interface ContractMetadataV0 extends Struct {
readonly types: Vec<Si0Type>;
readonly spec: ContractContractSpec;
readonly spec: ContractContractSpecV0;
}
/** @name ContractMetadataV1 */
export interface ContractMetadataV1 extends Struct {
readonly types: Vec<PortableType>;
readonly spec: ContractContractSpec;
readonly spec: ContractContractSpecV0;
}
/** @name ContractMetadataV2 */
export interface ContractMetadataV2 extends Struct {
readonly types: Vec<PortableType>;
readonly spec: ContractContractSpecV2;
}
/** @name ContractProject */
@@ -175,7 +246,7 @@ export interface ContractProjectV0 extends Struct {
readonly source: ContractProjectSource;
readonly contract: ContractProjectContract;
readonly types: Vec<Si0Type>;
readonly spec: ContractContractSpec;
readonly spec: ContractContractSpecV0;
}
/** @name ContractSelector */