From 072f69a91c366204ba39ca8430507d31ea237a12 Mon Sep 17 00:00:00 2001 From: bee344 Date: Tue, 24 Sep 2024 14:30:56 -0300 Subject: [PATCH] Revert "unfinished Preamble Class" This reverts commit 0b1c350fcc97e6f724ed84f66742be472c5daa71. --- .../types-augment/src/registry/interfaces.ts | 7 +-- packages/types/src/extrinsic/Extrinsic.ts | 35 +++++------ .../types/src/extrinsic/ExtrinsicPayload.ts | 10 +-- packages/types/src/extrinsic/constants.ts | 2 +- packages/types/src/extrinsic/types.ts | 4 +- packages/types/src/extrinsic/v5/Extrinsic.ts | 54 ++++++---------- .../src/extrinsic/v5/ExtrinsicSignature.ts | 2 +- packages/types/src/extrinsic/v5/Preamble.ts | 63 ------------------- .../src/interfaces/extrinsics/definitions.ts | 17 +---- .../types/src/interfaces/extrinsics/types.ts | 33 +--------- packages/types/src/types/extrinsic.ts | 4 +- 11 files changed, 49 insertions(+), 182 deletions(-) delete mode 100644 packages/types/src/extrinsic/v5/Preamble.ts diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index 91f4c086d5d..5b77684993c 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -35,7 +35,7 @@ import type { ApprovalFlag, DefunctVoter, Renouncing, SetIndex, Vote, VoteIndex, import type { CreatedBlock, ImportedAux } from '@polkadot/types/interfaces/engine'; import type { BlockV0, BlockV1, BlockV2, EIP1559Transaction, EIP2930Transaction, EthAccessList, EthAccessListItem, EthAccount, EthAddress, EthBlock, EthBloom, EthCallRequest, EthFeeHistory, EthFilter, EthFilterAddress, EthFilterChanges, EthFilterTopic, EthFilterTopicEntry, EthFilterTopicInner, EthHeader, EthLog, EthReceipt, EthReceiptV0, EthReceiptV3, EthRichBlock, EthRichHeader, EthStorageProof, EthSubKind, EthSubParams, EthSubResult, EthSyncInfo, EthSyncStatus, EthTransaction, EthTransactionAction, EthTransactionCondition, EthTransactionRequest, EthTransactionSignature, EthTransactionStatus, EthWork, EthereumAccountId, EthereumAddress, EthereumLookupSource, EthereumSignature, LegacyTransaction, TransactionV0, TransactionV1, TransactionV2 } from '@polkadot/types/interfaces/eth'; import type { EvmAccount, EvmCallInfo, EvmCallInfoV2, EvmCreateInfo, EvmCreateInfoV2, EvmLog, EvmVicinity, EvmWeightInfo, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed } from '@polkadot/types/interfaces/evm'; -import type { AnySignature, EcdsaSignature, Ed25519Signature, Era, Extension, ExtensionVersion, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV4, ExtrinsicPayloadV5, ExtrinsicSignature, ExtrinsicSignatureV4, ExtrinsicSignatureV5, ExtrinsicUnknown, ExtrinsicV4, ExtrinsicV5, ExtrinsicVersion, ImmortalEra, MortalEra, MultiSignature, Preamble, Signature, SignerPayload, Sr25519Signature, TransactionExtension } from '@polkadot/types/interfaces/extrinsics'; +import type { AnySignature, EcdsaSignature, Ed25519Signature, Era, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV4, ExtrinsicPayloadV5, ExtrinsicSignature, ExtrinsicSignatureV4, ExtrinsicSignatureV5, ExtrinsicUnknown, ExtrinsicV4, ExtrinsicV5, ImmortalEra, MortalEra, MultiSignature, Signature, SignerPayload, Sr25519Signature } from '@polkadot/types/interfaces/extrinsics'; import type { FungiblesAccessError } from '@polkadot/types/interfaces/fungibles'; import type { AssetOptions, Owner, PermissionLatest, PermissionVersions, PermissionsV1 } from '@polkadot/types/interfaces/genericAsset'; import type { GenesisBuildErr } from '@polkadot/types/interfaces/genesisBuilder'; @@ -491,8 +491,6 @@ declare module '@polkadot/types/types/registry' { ExplicitDisputeStatement: ExplicitDisputeStatement; Exposure: Exposure; ExtendedBalance: ExtendedBalance; - Extension: Extension; - ExtensionVersion: ExtensionVersion; Extrinsic: Extrinsic; ExtrinsicEra: ExtrinsicEra; ExtrinsicInclusionMode: ExtrinsicInclusionMode; @@ -515,7 +513,6 @@ declare module '@polkadot/types/types/registry' { ExtrinsicUnknown: ExtrinsicUnknown; ExtrinsicV4: ExtrinsicV4; ExtrinsicV5: ExtrinsicV5; - ExtrinsicVersion: ExtrinsicVersion; f32: f32; F32: F32; f64: f64; @@ -893,7 +890,6 @@ declare module '@polkadot/types/types/registry' { PortableType: PortableType; PortableTypeV14: PortableTypeV14; PostDispatchInfo: PostDispatchInfo; - Preamble: Preamble; Precommits: Precommits; PrefabWasmModule: PrefabWasmModule; PrefixedStorageKey: PrefixedStorageKey; @@ -1182,7 +1178,6 @@ declare module '@polkadot/types/types/registry' { TraceBlockResponse: TraceBlockResponse; TraceError: TraceError; TransactionalError: TransactionalError; - TransactionExtension: TransactionExtension; TransactionInfo: TransactionInfo; TransactionLongevity: TransactionLongevity; TransactionPriority: TransactionPriority; diff --git a/packages/types/src/extrinsic/Extrinsic.ts b/packages/types/src/extrinsic/Extrinsic.ts index 14ce5fa11ae..9e886694cff 100644 --- a/packages/types/src/extrinsic/Extrinsic.ts +++ b/packages/types/src/extrinsic/Extrinsic.ts @@ -9,17 +9,17 @@ import type { Address, Call, CodecHash, Hash } from '../interfaces/runtime/index import type { MultiLocation } from '../interfaces/types.js'; import type { CallBase, ExtrinsicPayloadValue, ICompact, IExtrinsic, IKeyringPair, INumber, Registry, SignatureOptions } from '../types/index.js'; import type { GenericExtrinsicEra } from './ExtrinsicEra.js'; +import type { Preamble } from './types.js'; import type { ExtrinsicValueV5 } from './v5/Extrinsic.js'; import { AbstractBase } from '@polkadot/types-codec'; import { compactAddLength, compactFromU8a, compactToU8a, isHex, isU8a, objectProperty, objectSpread, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util'; -import { BARE_EXTRINSIC, BIT_SIGNED, BIT_UNSIGNED, DEFAULT_PREAMBLE_KIND, GENERAL_EXTRINSIC, LATEST_EXTRINSIC_VERSION, LOWEST_SUPPORTED_EXTRINSIC_FORMAT_VERSION, SIGNED_EXTRINSIC, UNMASK_VERSION } from './constants.js'; -import type { PreambleKind } from './types.js'; +import { BARE_EXTRINSIC, BIT_SIGNED, BIT_UNSIGNED, DEFAULT_PREAMBLE, GENERAL_EXTRINSIC, LATEST_EXTRINSIC_VERSION, LOWEST_SUPPORTED_EXTRINSIC_FORMAT_VERSION, SIGNED_EXTRINSIC, UNMASK_VERSION } from './constants.js'; interface CreateOptions { version?: number; - preambleKind?: PreambleKind; + preamble?: Preamble; } // NOTE The following 2 types, as well as the VERSION structure and the latest export @@ -50,17 +50,16 @@ const PreambleMask = { signed: SIGNED_EXTRINSIC }; - export { LATEST_EXTRINSIC_VERSION }; /** @internal */ -function newFromValue (registry: Registry, value: any, version: number, preambleKind: PreambleKind): ExtrinsicVx | ExtrinsicUnknown { +function newFromValue (registry: Registry, value: any, version: number, preamble: Preamble): ExtrinsicVx | ExtrinsicUnknown { if (value instanceof GenericExtrinsic) { return value.unwrap(); } const isSigned = (version & BIT_SIGNED) === BIT_SIGNED; - const type = (version & UNMASK_VERSION) === 5 ? PREAMBLE[preambleKind] : VERSIONS[version & UNMASK_VERSION] || VERSIONS[0]; + const type = (version & UNMASK_VERSION) === 5 ? PREAMBLE[preamble] : VERSIONS[version & UNMASK_VERSION] || VERSIONS[0]; // we cast here since the VERSION definition is incredibly broad - we don't have a // slice for "only add extrinsic types", and more string definitions become unwieldy @@ -68,20 +67,20 @@ function newFromValue (registry: Registry, value: any, version: number, preamble } /** @internal */ -function decodeExtrinsic (registry: Registry, value?: GenericExtrinsic | ExtrinsicValue | AnyU8a | Call, version: number = LOWEST_SUPPORTED_EXTRINSIC_FORMAT_VERSION, preambleKind: PreambleKind = 'signed'): ExtrinsicVx | ExtrinsicUnknown { +function decodeExtrinsic (registry: Registry, value?: GenericExtrinsic | ExtrinsicValue | AnyU8a | Call, version: number = LOWEST_SUPPORTED_EXTRINSIC_FORMAT_VERSION, preamble: Preamble = DEFAULT_PREAMBLE): ExtrinsicVx | ExtrinsicUnknown { if (isU8a(value) || Array.isArray(value) || isHex(value)) { - return decodeU8a(registry, u8aToU8a(value), version, preambleKind); + return decodeU8a(registry, u8aToU8a(value), version, preamble); } else if (value instanceof registry.createClassUnsafe('Call')) { - return newFromValue(registry, { method: value }, version, preambleKind); + return newFromValue(registry, { method: value }, version, preamble); } - return newFromValue(registry, value, version, preambleKind); + return newFromValue(registry, value, version, preamble); } /** @internal */ -function decodeU8a (registry: Registry, value: Uint8Array, version: number, preambleKind: PreambleKind): ExtrinsicVx | ExtrinsicUnknown { +function decodeU8a (registry: Registry, value: Uint8Array, version: number, preamble: Preamble): ExtrinsicVx | ExtrinsicUnknown { if (!value.length) { - return newFromValue(registry, new Uint8Array(), version, preambleKind); + return newFromValue(registry, new Uint8Array(), version, preamble); } const [offset, length] = compactFromU8a(value); @@ -93,13 +92,13 @@ function decodeU8a (registry: Registry, value: Uint8Array, version: number, prea const data = value.subarray(offset, total); - return newFromValue(registry, data.subarray(1), data[0], preambleKind); + return newFromValue(registry, data.subarray(1), data[0], preamble); } abstract class ExtrinsicBase extends AbstractBase { - readonly #preamble: PreambleKind; + readonly #preamble: Preamble; - constructor (registry: Registry, value: ExtrinsicV5 | ExtrinsicUnknown, initialU8aLength?: number, preambleKind?: PreambleKind) { + constructor (registry: Registry, value: ExtrinsicV5 | ExtrinsicUnknown, initialU8aLength?: number, preamble?: Preamble) { super(registry, value, initialU8aLength); const signKeys = Object.keys(registry.getSignedExtensionTypes()); @@ -111,7 +110,7 @@ abstract class ExtrinsicBase extends AbstractBase extends ExtrinsicBa static LATEST_EXTRINSIC_VERSION = LATEST_EXTRINSIC_VERSION; - constructor (registry: Registry, value?: GenericExtrinsic | ExtrinsicValue | AnyU8a | Call, { preambleKind, version }: CreateOptions = {}) { - super(registry, decodeExtrinsic(registry, value, version || registry.metadata.extrinsic.version?.toNumber(), preambleKind), undefined, preambleKind); + constructor (registry: Registry, value?: GenericExtrinsic | ExtrinsicValue | AnyU8a | Call, { preamble, version }: CreateOptions = {}) { + super(registry, decodeExtrinsic(registry, value, version || registry.metadata.extrinsic.version?.toNumber(), preamble), undefined, preamble); } /** diff --git a/packages/types/src/extrinsic/ExtrinsicPayload.ts b/packages/types/src/extrinsic/ExtrinsicPayload.ts index 022c5d5a9d6..4b90787f0e5 100644 --- a/packages/types/src/extrinsic/ExtrinsicPayload.ts +++ b/packages/types/src/extrinsic/ExtrinsicPayload.ts @@ -9,16 +9,16 @@ import type { ExtrinsicPayloadV5 } from '../interfaces/extrinsics/index.js'; import type { Hash, MultiLocation } from '../interfaces/types.js'; import type { ExtrinsicPayloadValue, ICompact, IKeyringPair, INumber, IOption } from '../types/index.js'; import type { GenericExtrinsicEra } from './ExtrinsicEra.js'; +import type { Preamble } from './types.js'; import { AbstractBase } from '@polkadot/types-codec'; import { hexToU8a, isHex, u8aToHex } from '@polkadot/util'; -import { DEFAULT_PREAMBLE_KIND, LATEST_EXTRINSIC_VERSION } from './constants.js'; -import type { PreambleKind } from './types.js'; +import { DEFAULT_PREAMBLE, LATEST_EXTRINSIC_VERSION } from './constants.js'; interface ExtrinsicPayloadOptions { version?: number; - pramble?: PreambleKind; + pramble?: Preamble; } // all our known types that can be returned @@ -41,12 +41,12 @@ const PREAMBLES = { }; /** @internal */ -function decodeExtrinsicPayload (registry: Registry, value?: GenericExtrinsicPayload | ExtrinsicPayloadValue | Uint8Array | string, version = LATEST_EXTRINSIC_VERSION, preambleKind: PreambleKind = DEFAULT_PREAMBLE_KIND): ExtrinsicPayloadVx { +function decodeExtrinsicPayload (registry: Registry, value?: GenericExtrinsicPayload | ExtrinsicPayloadValue | Uint8Array | string, version = LATEST_EXTRINSIC_VERSION, preamble: Preamble = DEFAULT_PREAMBLE): ExtrinsicPayloadVx { if (value instanceof GenericExtrinsicPayload) { return value.unwrap(); } - const extVersion = version === 5 ? PREAMBLES[preambleKind] : VERSIONS[version] || VERSIONS[0]; + const extVersion = version === 5 ? PREAMBLES[preamble] : VERSIONS[version] || VERSIONS[0]; /** * HACK: In order to change the assetId from `number | object` to HexString (While maintaining the true type ie Option), diff --git a/packages/types/src/extrinsic/constants.ts b/packages/types/src/extrinsic/constants.ts index 6528a1212a4..aff05aef2d3 100644 --- a/packages/types/src/extrinsic/constants.ts +++ b/packages/types/src/extrinsic/constants.ts @@ -13,7 +13,7 @@ export const IMMORTAL_ERA = new Uint8Array([0]); export const UNMASK_VERSION = 0b01111111; -export const DEFAULT_PREAMBLE_KIND = 'signed'; +export const DEFAULT_PREAMBLE = 'signed'; // Latest extrinsic version is v5, which has backwards compatibility for v4 signed extrinsics export const LATEST_EXTRINSIC_VERSION = 5; diff --git a/packages/types/src/extrinsic/types.ts b/packages/types/src/extrinsic/types.ts index de47cb688b1..c468dc8582d 100644 --- a/packages/types/src/extrinsic/types.ts +++ b/packages/types/src/extrinsic/types.ts @@ -2,12 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 import type { AnyNumber } from '@polkadot/types-codec/types'; -import type { Preamble } from '../interfaces/types.js'; export interface ExtrinsicOptions { isSigned: boolean; version: number; - preambleKind: PreambleKind; } export interface ExtrinsicPayloadOptions { @@ -24,4 +22,4 @@ export interface ExtrinsicExtraValue { tip?: AnyNumber; } -export type PreambleKind = 'bare' | 'general' | 'signed'; +export type Preamble = 'signed' | 'bare' | 'general'; diff --git a/packages/types/src/extrinsic/v5/Extrinsic.ts b/packages/types/src/extrinsic/v5/Extrinsic.ts index 9429f6f4d0b..a1fd4f2ca9c 100644 --- a/packages/types/src/extrinsic/v5/Extrinsic.ts +++ b/packages/types/src/extrinsic/v5/Extrinsic.ts @@ -2,20 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 import type { HexString } from '@polkadot/util/types'; -import type { ExtrinsicSignatureV5, Preamble } from '../../interfaces/extrinsics/index.js'; +import type { ExtrinsicSignatureV5 } from '../../interfaces/extrinsics/index.js'; import type { Address, Call } from '../../interfaces/runtime/index.js'; import type { ExtrinsicPayloadValue, IExtrinsicV5Impl, IKeyringPair, Registry, SignatureOptions } from '../../types/index.js'; -import type { ExtrinsicOptions, PreambleKind } from '../types.js'; +import type { ExtrinsicOptions, Preamble } from '../types.js'; import { Struct } from '@polkadot/types-codec'; import { isU8a } from '@polkadot/util'; -import { DEFAULT_PREAMBLE_KIND } from '../constants.js'; export const EXTRINSIC_VERSION = 5; export interface ExtrinsicValueV5 { method?: Call; - preamble?: Preamble; + signature?: ExtrinsicSignatureV5; } /** @@ -24,45 +23,28 @@ export interface ExtrinsicValueV5 { * The third generation of compact extrinsics */ export class GenericExtrinsicV5 extends Struct implements IExtrinsicV5Impl { - constructor(registry: Registry, value?: Uint8Array | ExtrinsicValueV5 | Call, { preambleKind }: Partial = {}) { - + constructor (registry: Registry, value?: Uint8Array | ExtrinsicValueV5 | Call, { isSigned }: Partial = {}) { super(registry, { - preamble: 'Preamble', + signature: 'ExtrinsicSignatureV5', // eslint-disable-next-line sort-keys method: 'Call' - }, GenericExtrinsicV5.decodeExtrinsic(registry, value, preambleKind)); + }, GenericExtrinsicV5.decodeExtrinsic(registry, value, isSigned)); } /** @internal */ - public static decodeExtrinsic(registry: Registry, value?: Call | Uint8Array | ExtrinsicValueV5, preambleKind = DEFAULT_PREAMBLE_KIND): ExtrinsicValueV5 { + public static decodeExtrinsic (registry: Registry, value?: Call | Uint8Array | ExtrinsicValueV5, isSigned = false): ExtrinsicValueV5 { if (value instanceof GenericExtrinsicV5) { return value; } else if (value instanceof registry.createClassUnsafe('Call')) { return { method: value }; } else if (isU8a(value)) { - let preamble: Preamble; // here we decode manually since we need to pull through the version information - if (preambleKind === 'bare') { - preamble = registry.createTypeUnsafe('Preamble', [{ - type: 'Bare', - asBare: EXTRINSIC_VERSION - }]) - } else if (preambleKind === 'signed') { - preamble = registry.createTypeUnsafe('Preamble', [{ - type: 'Signed', - asSigned: value - }]) - } else { - preamble = registry.createTypeUnsafe('Preamble', [{ - type: 'General', - asSigned: value - }]) - } - const method = registry.createTypeUnsafe('Call', [value.subarray(preamble.encodedLength)]); + const signature = registry.createTypeUnsafe('ExtrinsicSignatureV5', [value, { isSigned }]); + const method = registry.createTypeUnsafe('Call', [value.subarray(signature.encodedLength)]); return { method, - preamble + signature }; } @@ -72,39 +54,39 @@ export class GenericExtrinsicV5 extends Struct implements IExtrinsicV5Impl { /** * @description The length of the value when encoded as a Uint8Array */ - public override get encodedLength(): number { + public override get encodedLength (): number { return this.toU8a().length; } /** * @description The [[Call]] this extrinsic wraps */ - public get method(): Call { + public get method (): Call { return this.getT('method'); } /** * @description The [[ExtrinsicSignatureV5]] */ - public get signature(): ExtrinsicSignatureV5 { + public get signature (): ExtrinsicSignatureV5 { return this.getT('signature'); } /** * @description The version for the signature */ - public get version(): number { + public get version (): number { return EXTRINSIC_VERSION; } - public get preamble(): Preamble { + public get preamble (): Preamble { return this.getT('preamble'); } /** * @description Add an [[ExtrinsicSignatureV5]] to the extrinsic (already generated) */ - public addSignature(signer: Address | Uint8Array | string, signature: Uint8Array | HexString, payload: ExtrinsicPayloadValue | Uint8Array | HexString): GenericExtrinsicV5 { + public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | HexString, payload: ExtrinsicPayloadValue | Uint8Array | HexString): GenericExtrinsicV5 { this.signature.addSignature(signer, signature, payload); return this; @@ -113,7 +95,7 @@ export class GenericExtrinsicV5 extends Struct implements IExtrinsicV5Impl { /** * @description Sign the extrinsic with a specific keypair */ - public sign(account: IKeyringPair, options: SignatureOptions): GenericExtrinsicV5 { + public sign (account: IKeyringPair, options: SignatureOptions): GenericExtrinsicV5 { this.signature.sign(this.method, account, options); return this; @@ -122,7 +104,7 @@ export class GenericExtrinsicV5 extends Struct implements IExtrinsicV5Impl { /** * @describe Adds a fake signature to the extrinsic */ - public signFake(signer: Address | Uint8Array | string, options: SignatureOptions): GenericExtrinsicV5 { + public signFake (signer: Address | Uint8Array | string, options: SignatureOptions): GenericExtrinsicV5 { this.signature.signFake(this.method, signer, options); return this; diff --git a/packages/types/src/extrinsic/v5/ExtrinsicSignature.ts b/packages/types/src/extrinsic/v5/ExtrinsicSignature.ts index 469d510a0ca..7ab070ff187 100644 --- a/packages/types/src/extrinsic/v5/ExtrinsicSignature.ts +++ b/packages/types/src/extrinsic/v5/ExtrinsicSignature.ts @@ -38,7 +38,7 @@ export class GenericExtrinsicSignatureV5 extends Struct implements IExtrinsicSig registry, objectSpread( // eslint-disable-next-line sort-keys - { extrinsicFormatVersion: 'ExtrinsicVersion', signer: 'Address', signature: 'ExtrinsicSignature', transactionExtensionVersion: 'ExtensionVersion' }, + { signer: 'Address', signature: 'ExtrinsicSignature', transactionExtensionVersion: 'u8' }, signTypes ), GenericExtrinsicSignatureV5.decodeExtrinsicSignature(value, isSigned) diff --git a/packages/types/src/extrinsic/v5/Preamble.ts b/packages/types/src/extrinsic/v5/Preamble.ts deleted file mode 100644 index eb13a591367..00000000000 --- a/packages/types/src/extrinsic/v5/Preamble.ts +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2017-2024 @polkadot/types authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import type { ITuple, Registry } from "@polkadot/types-codec/types"; -import type { Extension, ExtensionVersion, ExtrinsicSignatureV4, ExtrinsicVersion, MultiAddress, Preamble } from "@polkadot/types/interfaces"; - -export class GenericPreamble implements Preamble { - #preambleType: 'Bare' | 'Signed' | 'General'; - #asBare?: ExtrinsicVersion; - #asGeneral?: ITuple<[ExtensionVersion, Extension]>; - #asSigned?: ITuple<[MultiAddress, ExtrinsicSignatureV4, ExtensionVersion, Extension, ExtrinsicVersion]>; - - constructor(registry: Registry, type: 'Bare' | 'Signed' | 'General', data: any) { - this.#preambleType = type; - - if (type === 'Bare') { - this.#asBare = registry.createTypeUnsafe('u8', data); - } else if (type === 'Signed') { - this.#asSigned = registry.createTypeUnsafe>('(MultiAddress, ExtrinsicSignatureV4, ExtensionVersion, Extension, ExtrinsicVersion)', data); - } else { - this.#asGeneral = registry.createTypeUnsafe>('(ExtensionVersion, Extension)', data) - } - } - - get isBare(): boolean { - return this.#preambleType === 'Bare'; - } - - get asBare(): ExtrinsicVersion { - if (!this.isBare) { - throw new Error("Not a Bare type"); - } - return this.#asBare!; - } - - get isSigned(): boolean { - return this.#preambleType === 'Signed'; - } - - get asSigned(): ITuple<[MultiAddress, ExtrinsicSignatureV4, ExtensionVersion, Extension, ExtrinsicVersion]> { - if (!this.isSigned) { - throw new Error("Not a Signed type"); - } - return this.#asSigned!; - } - - get isGeneral(): boolean { - return this.#preambleType === 'General'; - } - - get asGeneral(): ITuple<[ExtensionVersion, Extension]> { - if (!this.isGeneral) { - throw new Error("Not a General type"); - } - return this.#asGeneral!; - } - - get type(): 'Bare' | 'Signed' | 'General' { - return this.#preambleType; - } - - -} \ No newline at end of file diff --git a/packages/types/src/interfaces/extrinsics/definitions.ts b/packages/types/src/interfaces/extrinsics/definitions.ts index a9c06d1c83f..a0c78d17492 100644 --- a/packages/types/src/interfaces/extrinsics/definitions.ts +++ b/packages/types/src/interfaces/extrinsics/definitions.ts @@ -40,21 +40,6 @@ export default { SignerPayload: 'GenericSignerPayload', EcdsaSignature: '[u8; 65]', Ed25519Signature: 'H512', - Sr25519Signature: 'H512', - ExtrinsicVersion: 'u8', - ExtensionVersion: 'u8', - TransactionExtension: { - identifier: 'Text', - type: 'SiLookupTypeId', - Implicit: 'SiLookupTypeId' - }, - Extension: 'TransactionExtension', - Preamble: { - _enum: { - Bare: '(ExtrinsicVersion)', - Signed: '(MultiAddress, GenericExtrinsicSignatureV4, ExtensionVersion, Extension, ExtrinsicVersion)', - General: '(ExtensionVersion, Extension)', - } - } + Sr25519Signature: 'H512' } } as Definitions; diff --git a/packages/types/src/interfaces/extrinsics/types.ts b/packages/types/src/interfaces/extrinsics/types.ts index 6b435e2e8df..056443f0884 100644 --- a/packages/types/src/interfaces/extrinsics/types.ts +++ b/packages/types/src/interfaces/extrinsics/types.ts @@ -2,10 +2,8 @@ /* eslint-disable */ import type { GenericExtrinsic, GenericExtrinsicEra, GenericExtrinsicPayload, GenericExtrinsicPayloadUnknown, GenericExtrinsicPayloadV4, GenericExtrinsicPayloadV5, GenericExtrinsicSignatureV4, GenericExtrinsicSignatureV5, GenericExtrinsicUnknown, GenericExtrinsicV4, GenericExtrinsicV5, GenericImmortalEra, GenericMortalEra, GenericSignerPayload } from '@polkadot/types'; -import type { Enum, Struct, Text, U8aFixed, u8 } from '@polkadot/types-codec'; -import type { ITuple } from '@polkadot/types-codec/types'; -import type { H512, MultiAddress } from '@polkadot/types/interfaces/runtime'; -import type { SiLookupTypeId } from '@polkadot/types/interfaces/scaleInfo'; +import type { Enum, U8aFixed } from '@polkadot/types-codec'; +import type { H512 } from '@polkadot/types/interfaces/runtime'; /** @name AnySignature */ export interface AnySignature extends H512 {} @@ -19,12 +17,6 @@ export interface Ed25519Signature extends H512 {} /** @name Era */ export interface Era extends ExtrinsicEra {} -/** @name Extension */ -export interface Extension extends TransactionExtension {} - -/** @name ExtensionVersion */ -export interface ExtensionVersion extends u8 {} - /** @name Extrinsic */ export interface Extrinsic extends GenericExtrinsic {} @@ -61,9 +53,6 @@ export interface ExtrinsicV4 extends GenericExtrinsicV4 {} /** @name ExtrinsicV5 */ export interface ExtrinsicV5 extends GenericExtrinsicV5 {} -/** @name ExtrinsicVersion */ -export interface ExtrinsicVersion extends u8 {} - /** @name ImmortalEra */ export interface ImmortalEra extends GenericImmortalEra {} @@ -81,17 +70,6 @@ export interface MultiSignature extends Enum { readonly type: 'Ed25519' | 'Sr25519' | 'Ecdsa'; } -/** @name Preamble */ -export interface Preamble extends Enum { - readonly isBare: boolean; - readonly asBare: ExtrinsicVersion; - readonly isSigned: boolean; - readonly asSigned: ITuple<[MultiAddress, GenericExtrinsicSignatureV4, ExtensionVersion, Extension, ExtrinsicVersion]>; - readonly isGeneral: boolean; - readonly asGeneral: ITuple<[ExtensionVersion, Extension]>; - readonly type: 'Bare' | 'Signed' | 'General'; -} - /** @name Signature */ export interface Signature extends H512 {} @@ -101,11 +79,4 @@ export interface SignerPayload extends GenericSignerPayload {} /** @name Sr25519Signature */ export interface Sr25519Signature extends H512 {} -/** @name TransactionExtension */ -export interface TransactionExtension extends Struct { - readonly identifier: Text; - readonly type: SiLookupTypeId; - readonly Implicit: SiLookupTypeId; -} - export type PHANTOM_EXTRINSICS = 'extrinsics'; diff --git a/packages/types/src/types/extrinsic.ts b/packages/types/src/types/extrinsic.ts index 2845adaa92a..ed0546aef04 100644 --- a/packages/types/src/types/extrinsic.ts +++ b/packages/types/src/types/extrinsic.ts @@ -4,7 +4,7 @@ import type { AnyJson, AnyNumber, AnyTuple, AnyU8a, Codec } from '@polkadot/types-codec/types'; import type { HexString } from '@polkadot/util/types'; import type { ExtrinsicStatus } from '../interfaces/author/index.js'; -import type { EcdsaSignature, Ed25519Signature, Preamble, Sr25519Signature } from '../interfaces/extrinsics/index.js'; +import type { EcdsaSignature, Ed25519Signature, Sr25519Signature } from '../interfaces/extrinsics/index.js'; import type { Address, Call, H256, Hash } from '../interfaces/runtime/index.js'; import type { DispatchError, DispatchInfo, EventRecord } from '../interfaces/system/index.js'; import type { ICompact, IKeyringPair, IMethod, INumber, IRuntimeVersionBase } from './interfaces.js'; @@ -249,7 +249,7 @@ export interface IExtrinsicImpl extends IExtrinsicSignable { export interface IExtrinsicV5Impl extends IExtrinsicSignable { readonly method: Call; - readonly preamble: Preamble; + readonly signature: IExtrinsicSignature; readonly version: number; }