Update known extensions (with Polkadot) (#1800)

* Update known extensions (with Polkadot)

* Split definitions for signed extensions
This commit is contained in:
Jaco Greeff
2020-02-03 17:25:33 +01:00
committed by GitHub
parent b82c90679d
commit 9e29e89baf
5 changed files with 86 additions and 49 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ import { assert, isFunction, isString, isUndefined, stringCamelCase, u8aToHex }
import Raw from '../Raw';
import { EventData } from '../../primitive/Generic/Event';
import { defaultExtensions, expandExtensionTypes, findUnknownExtensions } from '../../primitive/Extrinsic/SignedExtensions';
import { defaultExtensions, expandExtensionTypes, findUnknownExtensions } from '../../primitive/Extrinsic/signedExtensions';
import { createClass } from './createClass';
import { getTypeClass } from './getTypeClass';
import { getTypeDef } from './getTypeDef';
@@ -2,62 +2,21 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { InterfaceTypes } from '../../types';
import { ExtDef, ExtInfo, ExtTypes } from './types';
type ExtTypes = Record<string, InterfaceTypes>;
type ExtInfo = {
extra: ExtTypes;
types: ExtTypes;
}
import polkadotExtensions from './polkadot';
import substrateExtensions 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
// deemded fixed and non-changeable)
const allExtensions: Record<string, ExtInfo> = {
ChargeTransactionPayment: {
extra: {},
types: {
tip: 'Compact<Balance>'
}
},
CheckBlockGasLimit: {
extra: {},
types: {}
},
CheckEra: {
extra: {
blockHash: 'Hash'
},
types: {
era: 'ExtrinsicEra'
}
},
CheckGenesis: {
extra: {
genesisHash: 'Hash'
},
types: {}
},
CheckNonce: {
extra: {},
types: {
nonce: 'Compact<Index>'
}
},
CheckVersion: {
extra: {
specVersion: 'u32'
},
types: {}
},
CheckWeight: {
extra: {},
types: {}
}
const allExtensions: ExtDef = {
...substrateExtensions,
...polkadotExtensions
};
// the v4 signed extensions (the order is important here)
// the v4 signed extensions (the order is important here, as applied by default)
const defaultExtensions: Array<keyof typeof allExtensions> = [
'CheckVersion',
'CheckGenesis',
@@ -0,0 +1,16 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ExtDef } from './types';
export default {
RestrictFunctionality: {
extra: {},
types: {}
},
LimitParathreadCommits: {
extra: {},
types: {}
}
} as ExtDef;
@@ -0,0 +1,48 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ExtDef } from './types';
export default {
ChargeTransactionPayment: {
extra: {},
types: {
tip: 'Compact<Balance>'
}
},
CheckBlockGasLimit: {
extra: {},
types: {}
},
CheckEra: {
extra: {
blockHash: 'Hash'
},
types: {
era: 'ExtrinsicEra'
}
},
CheckGenesis: {
extra: {
genesisHash: 'Hash'
},
types: {}
},
CheckNonce: {
extra: {},
types: {
nonce: 'Compact<Index>'
}
},
CheckVersion: {
extra: {
specVersion: 'u32'
},
types: {}
},
CheckWeight: {
extra: {},
types: {}
}
} as ExtDef;
@@ -0,0 +1,14 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { InterfaceTypes } from '../../../types';
export type ExtTypes = Record<string, InterfaceTypes>;
export type ExtInfo = {
extra: ExtTypes;
types: ExtTypes;
}
export type ExtDef = Record<string, ExtInfo>;