Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump metadata, allow type alias on events #2351

Merged
merged 5 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/metadata/src/Metadata/v11/static-substrate.json
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,39 @@
"documentation": [
" Some amount was deposited (e.g. for transaction fees)."
]
},
{
"name": "Reserved",
"args": [
"AccountId",
"Balance"
],
"documentation": [
" Some balance was reserved (moved from free to reserved)."
]
},
{
"name": "Unreserved",
"args": [
"AccountId",
"Balance"
],
"documentation": [
" Some balance was unreserved (moved from reserved to free)."
]
},
{
"name": "ReserveRepatriated",
"args": [
"AccountId",
"AccountId",
"Balance",
"BalanceStatus"
],
"documentation": [
" Some balance was moved from the reserve of the first account to the second account.",
" Final argument indicates the destination balance type."
]
}
],
"constants": [
Expand Down
2 changes: 1 addition & 1 deletion packages/metadata/src/Metadata/v11/static.ts

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion packages/metadata/src/Metadata/v11/toLatest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import { FunctionMetadataV11, FunctionMetadataLatest, MetadataV11, MetadataLatest, ModuleMetadataLatest, StorageMetadataV11, StorageMetadataLatest, StorageEntryMetadataLatest } from '@polkadot/types/interfaces/metadata';
import { EventMetadataV11, EventMetadataLatest, FunctionMetadataV11, FunctionMetadataLatest, MetadataV11, MetadataLatest, ModuleMetadataLatest, StorageMetadataV11, StorageMetadataLatest, StorageEntryMetadataLatest } from '@polkadot/types/interfaces/metadata';
import { Registry, OverrideModuleType } from '@polkadot/types/types';

import { getModuleTypes } from '@polkadot/types-known';
Expand Down Expand Up @@ -35,6 +35,18 @@ function convertCalls (registry: Registry, calls: FunctionMetadataV11[], section
});
}

/**
* Apply module-specific type overrides (always be done as part of toLatest)
* @internal
**/
function convertEvents (registry: Registry, events: EventMetadataV11[], sectionTypes: OverrideModuleType): EventMetadataLatest[] {
return events.map(({ args, documentation, name }): EventMetadataLatest => {
args.forEach((type): void => setTypeOverride(sectionTypes, type));

return registry.createType('EventMetadataLatest', { args, documentation, name });
});
}

/**
* Apply module-specific storage type overrides (always part of toLatest)
* @internal
Expand Down Expand Up @@ -70,6 +82,7 @@ export default function toLatest (registry: Registry, { extrinsic, modules }: Me
extrinsic,
modules: modules.map((mod): ModuleMetadataLatest => {
const calls = mod.calls.unwrapOr(null);
const events = mod.events.unwrapOr(null);
const storage = mod.storage.unwrapOr(null);
const sectionTypes = getModuleTypes(registry, stringCamelCase(mod.name.toString()));

Expand All @@ -78,6 +91,9 @@ export default function toLatest (registry: Registry, { extrinsic, modules }: Me
calls: calls
? convertCalls(registry, calls, sectionTypes)
: null,
events: events
? convertEvents(registry, events, sectionTypes)
: null,
storage: storage
? convertStorage(registry, storage, sectionTypes)
: null
Expand Down
3 changes: 2 additions & 1 deletion packages/types-known/src/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { OverrideModuleType } from '@polkadot/types/types';
// type overrides for modules (where duplication between modules exist)
const typesModules: Record<string, OverrideModuleType> = {
balances: {
Releases: 'ReleasesBalances'
Releases: 'ReleasesBalances',
Status: 'BalanceStatus'
},
contract: { // old metadata & naming
// v2 & v3
Expand Down
5 changes: 4 additions & 1 deletion packages/types/src/augment/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RawAuraPreDigest } from '@polkadot/types/interfaces/aura';
import { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interfaces/author';
import { UncleEntryItem } from '@polkadot/types/interfaces/authorship';
import { AllowedSlots, BabeAuthorityWeight, BabeBlockWeight, BabeWeight, EpochAuthorship, MaybeRandomness, MaybeVrf, NextConfigDescriptor, NextConfigDescriptorV1, Randomness, RawBabePreDigest, RawBabePreDigestCompat, RawBabePreDigestPrimary, RawBabePreDigestPrimaryTo159, RawBabePreDigestSecondaryPlain, RawBabePreDigestSecondaryTo159, RawBabePreDigestSecondaryVRF, RawBabePreDigestTo159, SlotNumber, VrfData, VrfOutput, VrfProof } from '@polkadot/types/interfaces/babe';
import { AccountData, BalanceLock, BalanceLockTo212, Reasons, ReleasesBalances, VestingSchedule, WithdrawReasons } from '@polkadot/types/interfaces/balances';
import { AccountData, BalanceLock, BalanceLockTo212, BalanceStatus, Reasons, ReleasesBalances, VestingSchedule, WithdrawReasons } from '@polkadot/types/interfaces/balances';
import { BlockHash } from '@polkadot/types/interfaces/chain';
import { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate';
import { EthereumAddress, StatementKind } from '@polkadot/types/interfaces/claims';
Expand Down Expand Up @@ -384,6 +384,9 @@ declare module '@polkadot/types/types/registry' {
BalanceLock: BalanceLock;
'Option<BalanceLock>': Option<BalanceLock>;
'Vec<BalanceLock>': Vec<BalanceLock>;
BalanceStatus: BalanceStatus;
'Option<BalanceStatus>': Option<BalanceStatus>;
'Vec<BalanceStatus>': Vec<BalanceStatus>;
ReleasesBalances: ReleasesBalances;
'Option<ReleasesBalances>': Option<ReleasesBalances>;
'Vec<ReleasesBalances>': Vec<ReleasesBalances>;
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/interfaces/balances/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default {
amount: 'Balance',
reasons: 'Reasons'
},
BalanceStatus: {
_enum: ['Free', 'Reserved']
},
ReleasesBalances: {
_enum: ['V1_0_0', 'V2_0_0']
},
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/interfaces/balances/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export interface BalanceLockTo212 extends Struct {
readonly reasons: WithdrawReasons;
}

/** @name BalanceStatus */
export interface BalanceStatus extends Enum {
readonly isFree: boolean;
readonly isReserved: boolean;
}

/** @name Reasons */
export interface Reasons extends Enum {
readonly isFee: boolean;
Expand Down