From e6018f2f751bf3816233a62cd61faada1a5d7013 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 28 Jan 2020 09:52:40 +0100 Subject: [PATCH] Add society-specific Vote type (#1754) * Add society-specific Vote type * Cnvert storage types via toLatest --- packages/api/src/query.types.ts | 6 +-- .../src/Metadata/v10/static-substrate.json | 4 +- .../metadata/src/Metadata/v10/toLatest.ts | 37 +++++++++++++++++-- packages/types/src/interfaceRegistry.ts | 10 ++++- .../src/interfaces/metadata/definitions.ts | 1 + .../types/src/interfaces/metadata/types.ts | 3 ++ .../src/interfaces/society/definitions.ts | 4 ++ .../types/src/interfaces/society/types.ts | 10 +++++ packages/types/src/known/overrides.ts | 4 ++ 9 files changed, 69 insertions(+), 10 deletions(-) diff --git a/packages/api/src/query.types.ts b/packages/api/src/query.types.ts index 502a08635f..4997947d7c 100644 --- a/packages/api/src/query.types.ts +++ b/packages/api/src/query.types.ts @@ -19,7 +19,7 @@ import { AuthIndex } from '@polkadot/types/interfaces/imOnline'; import { Kind, OffenceDetails, OpaqueTimeSlot, ReportIdOf } from '@polkadot/types/interfaces/offences'; import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery'; import { Keys, SessionIndex } from '@polkadot/types/interfaces/session'; -import { Bid, BidKind, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society'; +import { Bid, BidKind, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society'; import { EraIndex, EraPoints, Exposure, Forcing, MomentOf, Nominations, RewardDestination, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs } from '@polkadot/types/interfaces/staking'; import { DigestOf, EventIndex, EventRecord } from '@polkadot/types/interfaces/system'; import { OpenTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury'; @@ -246,9 +246,9 @@ declare module './types' { vouching: StorageEntryExact Observable>> & QueryableStorageEntry; payouts: StorageEntryExact Observable>>> & QueryableStorageEntry; strikes: StorageEntryExact Observable> & QueryableStorageEntry; - votes: StorageEntryExact Observable>> & QueryableStorageEntry; + votes: StorageEntryExact Observable>> & QueryableStorageEntry; defender: StorageEntryExact Observable>> & QueryableStorageEntry; - defenderVotes: StorageEntryExact Observable>> & QueryableStorageEntry; + defenderVotes: StorageEntryExact Observable>> & QueryableStorageEntry; maxMembers: StorageEntryExact Observable> & QueryableStorageEntry; }; recovery: { diff --git a/packages/metadata/src/Metadata/v10/static-substrate.json b/packages/metadata/src/Metadata/v10/static-substrate.json index 0eec9bf739..ea9eb592d6 100644 --- a/packages/metadata/src/Metadata/v10/static-substrate.json +++ b/packages/metadata/src/Metadata/v10/static-substrate.json @@ -6631,7 +6631,7 @@ "hasher": "twox64Concat", "key1": "AccountId", "key2": "AccountId", - "value": "Vote", + "value": "SocietyVote", "key2Hasher": "twox64Concat" } }, @@ -6658,7 +6658,7 @@ "Map": { "hasher": "twox64Concat", "key": "AccountId", - "value": "Vote", + "value": "SocietyVote", "linked": false } }, diff --git a/packages/metadata/src/Metadata/v10/toLatest.ts b/packages/metadata/src/Metadata/v10/toLatest.ts index 13e33d5202..b51b252406 100644 --- a/packages/metadata/src/Metadata/v10/toLatest.ts +++ b/packages/metadata/src/Metadata/v10/toLatest.ts @@ -3,14 +3,14 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { OverrideModuleType } from '@polkadot/types/known/types'; -import { FunctionMetadataV10, FunctionMetadataLatest, MetadataV10, MetadataLatest, ModuleMetadataV10, ModuleMetadataLatest } from '@polkadot/types/interfaces/metadata'; +import { FunctionMetadataV10, FunctionMetadataLatest, MetadataV10, MetadataLatest, ModuleMetadataV10, ModuleMetadataLatest, StorageMetadataV10, StorageMetadataLatest, StorageEntryMetadataLatest } from '@polkadot/types/interfaces/metadata'; import { Registry } from '@polkadot/types/types'; import { getModuleTypes } from '@polkadot/types/known'; -import { createType } from '@polkadot/types'; +import { Type, createType } from '@polkadot/types'; import { stringCamelCase } from '@polkadot/util'; -// apply module-specific type overrides - this should always be done as part of toLatest +// apply module-specific type overrides (always be done as part of toLatest) /** @internal */ function convertCalls (registry: Registry, calls: FunctionMetadataV10[], sectionTypes: OverrideModuleType[]): FunctionMetadataLatest[] { return calls.map(({ args, documentation, name }): FunctionMetadataLatest => { @@ -26,15 +26,46 @@ function convertCalls (registry: Registry, calls: FunctionMetadataV10[], section }); } +// apply module-specific storage type overrides (always part of toLatest) +/** @internal */ +function convertStorage (registry: Registry, { items, prefix }: StorageMetadataV10, sectionTypes: OverrideModuleType[]): StorageMetadataLatest { + return createType(registry, 'StorageMetadataLatest', { + items: items.map(({ documentation, fallback, modifier, name, type }): StorageEntryMetadataLatest => { + let resultType: Type; + + if (type.isMap) { + resultType = type.asMap.value; + } else if (type.isDoubleMap) { + resultType = type.asDoubleMap.value; + } else { + resultType = type.asPlain; + } + + const queued = sectionTypes.find(({ name }): boolean => resultType.eq(name)); + + if (queued) { + resultType.setOverride(queued.override); + } + + return createType(registry, 'StorageEntryMetadataLatest', { documentation, fallback, modifier, name, type }); + }), + prefix + }); +} + /** @internal */ function convertModule (registry: Registry, mod: ModuleMetadataV10): ModuleMetadataLatest { const calls = mod.calls.unwrapOr(null); + const storage = mod.storage.unwrapOr(null); const sectionTypes = getModuleTypes(stringCamelCase(mod.name.toString())) || []; return createType(registry, 'ModuleMetadataLatest', { ...mod, calls: calls ? convertCalls(registry, calls, sectionTypes) + : null, + storage: storage + ? convertStorage(registry, storage, sectionTypes) : null }); } diff --git a/packages/types/src/interfaceRegistry.ts b/packages/types/src/interfaceRegistry.ts index 38f20cb731..e904d1f63d 100644 --- a/packages/types/src/interfaceRegistry.ts +++ b/packages/types/src/interfaceRegistry.ts @@ -21,7 +21,7 @@ import { AuthIndex, AuthoritySignature, Heartbeat, OpaqueMultiaddr, OpaqueNetwor import { Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences'; import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery'; import { FullIdentification, IdentificationTuple, Keys, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6 } from '@polkadot/types/interfaces/session'; -import { Bid, BidKind, BidKindVouch, SocietyJudgement, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society'; +import { Bid, BidKind, BidKindVouch, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society'; import { EraIndex, EraPoints, EraRewards, Exposure, Forcing, IndividualExposure, MomentOf, Nominations, Points, RewardDestination, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking'; import { DigestOf, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Key, Phase } from '@polkadot/types/interfaces/system'; import { OpenTip, OpenTipFinder, OpenTipTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury'; @@ -30,7 +30,7 @@ import { Multisig, Timepoint } from '@polkadot/types/interfaces/utility'; import { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/types/interfaces/attestations'; import { EthereumAddress } from '@polkadot/types/interfaces/claims'; import { AttestedCandidate, AuctionIndex, BalanceUpload, Bidder, CandidateReceipt, CollatorId, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParaInfo, ParaScheduling, ParachainDispatchOrigin, Retriable, SlotRange, SubId, UpwardMessage, ValidatorIndex, ValidityAttestation, ValidityVote, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains'; -import { CallMetadataV0, DoubleMapTypeLatest, DoubleMapTypeV10, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, DoubleMapTypeV9, ErrorMetadataV10, ErrorMetadataV8, ErrorMetadataV9, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV10, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, EventMetadataV9, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV10, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV10, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, FunctionMetadataV9, MapTypeLatest, MapTypeV0, MapTypeV10, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MapTypeV9, MetadataAll, MetadataLatest, MetadataV0, MetadataV1, MetadataV10, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, MetadataV9, ModuleConstantMetadataLatest, ModuleConstantMetadataV10, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleConstantMetadataV9, ModuleMetadataLatest, ModuleMetadataV0, ModuleMetadataV1, ModuleMetadataV10, ModuleMetadataV2, ModuleMetadataV3, ModuleMetadataV4, ModuleMetadataV5, ModuleMetadataV6, ModuleMetadataV7, ModuleMetadataV8, ModuleMetadataV9, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV10, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, PlainTypeV9, RuntimeModuleMetadataV0, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV6, StorageEntryMetadataV7, StorageEntryMetadataV8, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV6, StorageEntryTypeV7, StorageEntryTypeV8, StorageEntryTypeV9, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionMetadataV2, StorageFunctionMetadataV3, StorageFunctionMetadataV4, StorageFunctionMetadataV5, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageFunctionTypeV2, StorageFunctionTypeV3, StorageFunctionTypeV4, StorageFunctionTypeV5, StorageHasher, StorageHasherV10, StorageHasherV4, StorageHasherV5, StorageHasherV6, StorageHasherV7, StorageHasherV8, StorageHasherV9, StorageMetadataV0, StorageMetadataV10, StorageMetadataV7, StorageMetadataV8, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata'; +import { CallMetadataV0, DoubleMapTypeLatest, DoubleMapTypeV10, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, DoubleMapTypeV9, ErrorMetadataV10, ErrorMetadataV8, ErrorMetadataV9, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV10, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, EventMetadataV9, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV10, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV10, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, FunctionMetadataV9, MapTypeLatest, MapTypeV0, MapTypeV10, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MapTypeV9, MetadataAll, MetadataLatest, MetadataV0, MetadataV1, MetadataV10, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, MetadataV9, ModuleConstantMetadataLatest, ModuleConstantMetadataV10, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleConstantMetadataV9, ModuleMetadataLatest, ModuleMetadataV0, ModuleMetadataV1, ModuleMetadataV10, ModuleMetadataV2, ModuleMetadataV3, ModuleMetadataV4, ModuleMetadataV5, ModuleMetadataV6, ModuleMetadataV7, ModuleMetadataV8, ModuleMetadataV9, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV10, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, PlainTypeV9, RuntimeModuleMetadataV0, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV6, StorageEntryMetadataV7, StorageEntryMetadataV8, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV6, StorageEntryTypeV7, StorageEntryTypeV8, StorageEntryTypeV9, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionMetadataV2, StorageFunctionMetadataV3, StorageFunctionMetadataV4, StorageFunctionMetadataV5, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageFunctionTypeV2, StorageFunctionTypeV3, StorageFunctionTypeV4, StorageFunctionTypeV5, StorageHasher, StorageHasherV10, StorageHasherV4, StorageHasherV5, StorageHasherV6, StorageHasherV7, StorageHasherV8, StorageHasherV9, StorageMetadataLatest, StorageMetadataV0, StorageMetadataV10, StorageMetadataV7, StorageMetadataV8, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata'; import { ApiId, BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/rpc'; export interface InterfaceRegistry { @@ -662,6 +662,9 @@ export interface InterfaceRegistry { SocietyJudgement: SocietyJudgement; 'Option': Option; 'Vec': Vec; + SocietyVote: SocietyVote; + 'Option': Option; + 'Vec': Vec; StrikeCount: StrikeCount; 'Compact': Compact; 'Option': Option; @@ -1370,6 +1373,9 @@ export interface InterfaceRegistry { StorageEntryTypeLatest: StorageEntryTypeLatest; 'Option': Option; 'Vec': Vec; + StorageMetadataLatest: StorageMetadataLatest; + 'Option': Option; + 'Vec': Vec; StorageHasher: StorageHasher; 'Option': Option; 'Vec': Vec; diff --git a/packages/types/src/interfaces/metadata/definitions.ts b/packages/types/src/interfaces/metadata/definitions.ts index 5c48eec480..22c33f06f5 100644 --- a/packages/types/src/interfaces/metadata/definitions.ts +++ b/packages/types/src/interfaces/metadata/definitions.ts @@ -447,6 +447,7 @@ export default { StorageEntryMetadataLatest: 'StorageEntryMetadataV10', StorageEntryModifierLatest: 'StorageEntryModifierV10', StorageEntryTypeLatest: 'StorageEntryTypeV10', + StorageMetadataLatest: 'StorageMetadataV10', StorageHasher: 'StorageHasherV10', // the enum containing all the mappings diff --git a/packages/types/src/interfaces/metadata/types.ts b/packages/types/src/interfaces/metadata/types.ts index f083663eca..e7429db681 100644 --- a/packages/types/src/interfaces/metadata/types.ts +++ b/packages/types/src/interfaces/metadata/types.ts @@ -962,6 +962,9 @@ export interface StorageHasherV8 extends StorageHasherV7 {} /** StorageHasherV8 */ export interface StorageHasherV9 extends StorageHasherV8 {} +/** StorageMetadataV10 */ +export interface StorageMetadataLatest extends StorageMetadataV10 {} + /** Struct */ export interface StorageMetadataV0 extends Struct { /** Text */ diff --git a/packages/types/src/interfaces/society/definitions.ts b/packages/types/src/interfaces/society/definitions.ts index 7ac0f63c08..bb14d56154 100644 --- a/packages/types/src/interfaces/society/definitions.ts +++ b/packages/types/src/interfaces/society/definitions.ts @@ -20,6 +20,10 @@ export default { SocietyJudgement: { _enum: ['Rebid', 'Reject', 'Approve'] }, + // a society-specific Vote + SocietyVote: { + _enum: ['Skeptic', 'Reject', 'Approve'] + }, StrikeCount: 'u32', VouchingStatus: { _enum: ['Vouching', 'Banned'] diff --git a/packages/types/src/interfaces/society/types.ts b/packages/types/src/interfaces/society/types.ts index 8c23e1427f..86f01d0e18 100644 --- a/packages/types/src/interfaces/society/types.ts +++ b/packages/types/src/interfaces/society/types.ts @@ -41,6 +41,16 @@ export interface SocietyJudgement extends Enum { readonly isApprove: boolean; } +/** Enum */ +export interface SocietyVote extends Enum { + /** 0:: Skeptic */ + readonly isSkeptic: boolean; + /** 1:: Reject */ + readonly isReject: boolean; + /** 2:: Approve */ + readonly isApprove: boolean; +} + /** u32 */ export interface StrikeCount extends u32 {} diff --git a/packages/types/src/known/overrides.ts b/packages/types/src/known/overrides.ts index 7dccb4940d..1c1ce9bf74 100644 --- a/packages/types/src/known/overrides.ts +++ b/packages/types/src/known/overrides.ts @@ -16,6 +16,10 @@ const TYPES_MODULES: Record = { { name: 'Judgement', override: 'SocietyJudgement' + }, + { + name: 'Vote', + override: 'SocietyVote' } ] };