Allow extensions on typesBundle (#3142)
* Allow extensions on typesBundle * User extension take precedence
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export const emptyCheck = {
|
||||
import type { ExtInfo } from './types';
|
||||
|
||||
export const emptyCheck: ExtInfo = {
|
||||
extrinsic: {},
|
||||
payload: {}
|
||||
};
|
||||
|
||||
@@ -3,17 +3,14 @@
|
||||
|
||||
import type { ExtDef, ExtInfo, ExtTypes } from './types';
|
||||
|
||||
import polkadotExtensions from './polkadot';
|
||||
import substrateExtensions from './substrate';
|
||||
import { polkadot } from './polkadot';
|
||||
import { substrate } from './substrate';
|
||||
|
||||
// A mapping of the known signed extensions to the extra fields that they contain. Unlike in the actual extensions,
|
||||
// we define the extra fields not as a Tuple, but rather as a struct so they can be named. These will be expanded
|
||||
// into the various fields when added to the payload (we only support V4 onwards with these, V3 and earlier are
|
||||
// deemed fixed and non-changeable)
|
||||
const allExtensions: ExtDef = {
|
||||
...substrateExtensions,
|
||||
...polkadotExtensions
|
||||
};
|
||||
const allExtensions: ExtDef = { ...substrate, ...polkadot };
|
||||
|
||||
// the v4 signed extensions (the order is important here, as applied by default)
|
||||
const defaultExtensions: Array<keyof typeof allExtensions> = [
|
||||
@@ -34,6 +31,7 @@ function findUnknownExtensions (extensions: string[], userExtensions: ExtDef = {
|
||||
|
||||
function expandExtensionTypes (extensions: string[], type: keyof ExtInfo, userExtensions: ExtDef = {}): ExtTypes {
|
||||
return extensions
|
||||
// Always allow user extensions first - these should provide overrides
|
||||
.map((key) => userExtensions[key] || allExtensions[key])
|
||||
.filter((info): info is ExtInfo => !!info)
|
||||
.reduce((result, info): ExtTypes => ({ ...result, ...info[type] }), {});
|
||||
|
||||
@@ -5,11 +5,11 @@ import type { ExtDef } from './types';
|
||||
|
||||
import { emptyCheck } from './emptyCheck';
|
||||
|
||||
export default {
|
||||
export const polkadot: ExtDef = {
|
||||
LimitParathreadCommits: emptyCheck,
|
||||
OnlyStakingAndClaims: emptyCheck,
|
||||
PrevalidateAttests: emptyCheck,
|
||||
RestrictFunctionality: emptyCheck,
|
||||
TransactionCallFilter: emptyCheck,
|
||||
ValidateDoubleVoteReports: emptyCheck
|
||||
} as ExtDef;
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ExtDef } from './types';
|
||||
import type { ExtDef, ExtInfo } from './types';
|
||||
|
||||
import { emptyCheck } from './emptyCheck';
|
||||
|
||||
const CheckMortality = {
|
||||
const CheckMortality: ExtInfo = {
|
||||
extrinsic: {
|
||||
era: 'ExtrinsicEra'
|
||||
},
|
||||
@@ -14,7 +14,7 @@ const CheckMortality = {
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
export const substrate: ExtDef = {
|
||||
ChargeTransactionPayment: {
|
||||
extrinsic: {
|
||||
tip: 'Compact<Balance>'
|
||||
@@ -57,4 +57,4 @@ export default {
|
||||
CheckWeight: emptyCheck,
|
||||
LockStakingStatus: emptyCheck,
|
||||
ValidateEquivocationReport: emptyCheck
|
||||
} as ExtDef;
|
||||
};
|
||||
|
||||
@@ -49,6 +49,7 @@ export interface OverrideBundleDefinition {
|
||||
derives?: DeriveCustom;
|
||||
instances?: Record<string, string[]>;
|
||||
rpc?: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>;
|
||||
signedExtensions?: ExtDef;
|
||||
types?: OverrideVersionedType[];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user