From 57e9857ed800aeb823959df7a152b4e4507fd604 Mon Sep 17 00:00:00 2001 From: Jaco Date: Wed, 30 Nov 2022 07:35:31 +0200 Subject: [PATCH] Converts payloads to use BlockHash types (#5358) --- packages/types/src/extrinsic/ExtrinsicPayload.ts | 16 ++++++++-------- packages/types/src/extrinsic/SignerPayload.ts | 6 +++--- .../types/src/extrinsic/v4/ExtrinsicPayload.ts | 15 +++++++-------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/packages/types/src/extrinsic/ExtrinsicPayload.ts b/packages/types/src/extrinsic/ExtrinsicPayload.ts index e3a6257deb..0d785fd524 100644 --- a/packages/types/src/extrinsic/ExtrinsicPayload.ts +++ b/packages/types/src/extrinsic/ExtrinsicPayload.ts @@ -3,11 +3,11 @@ import type { AnyJson, BareOpts, Registry } from '@polkadot/types-codec/types'; import type { HexString } from '@polkadot/util/types'; +import type { BlockHash } from '../interfaces/chain'; import type { ExtrinsicPayloadV4 } from '../interfaces/extrinsics'; -import type { Hash } from '../interfaces/runtime'; import type { ExtrinsicPayloadValue, ICompact, IKeyringPair, INumber } from '../types'; -import { AbstractBase, Raw } from '@polkadot/types-codec'; +import { AbstractBase, Bytes } from '@polkadot/types-codec'; import { u8aToHex } from '@polkadot/util'; import { DEFAULT_VERSION } from './constants'; @@ -49,9 +49,9 @@ export class GenericExtrinsicPayload extends AbstractBase { } /** - * @description The block [[Hash]] the signature applies to (mortal/immortal) + * @description The block [[BlockHash]] the signature applies to (mortal/immortal) */ - public get blockHash (): Hash { + public get blockHash (): BlockHash { return this.inner.blockHash; } @@ -63,17 +63,17 @@ export class GenericExtrinsicPayload extends AbstractBase { } /** - * @description The genesis block [[Hash]] the signature applies to + * @description The genesis block [[BlockHash]] the signature applies to */ - public get genesisHash (): Hash { + public get genesisHash (): BlockHash { // NOTE only v3+ return this.inner.genesisHash || this.registry.createTypeUnsafe('Hash', []); } /** - * @description The [[Raw]] contained in the payload + * @description The [[Bytes]] contained in the payload */ - public get method (): Raw { + public get method (): Bytes { return this.inner.method; } diff --git a/packages/types/src/extrinsic/SignerPayload.ts b/packages/types/src/extrinsic/SignerPayload.ts index 704908aa7c..6c12be949b 100644 --- a/packages/types/src/extrinsic/SignerPayload.ts +++ b/packages/types/src/extrinsic/SignerPayload.ts @@ -3,7 +3,7 @@ import type { Registry } from '@polkadot/types-codec/types'; import type { HexString } from '@polkadot/util/types'; -import type { Address, Call, ExtrinsicEra, Hash } from '../interfaces'; +import type { Address, BlockHash, Call, ExtrinsicEra, Hash } from '../interfaces'; import type { Codec, ICompact, INumber, IRuntimeVersion, ISignerPayload, SignerPayloadJSON, SignerPayloadRaw } from '../types'; import { Option, Struct, Text, Vec } from '@polkadot/types-codec'; @@ -67,7 +67,7 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign return this.getT('address'); } - get blockHash (): Hash { + get blockHash (): BlockHash { return this.getT('blockHash'); } @@ -79,7 +79,7 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign return this.getT('era'); } - get genesisHash (): Hash { + get genesisHash (): BlockHash { return this.getT('genesisHash'); } diff --git a/packages/types/src/extrinsic/v4/ExtrinsicPayload.ts b/packages/types/src/extrinsic/v4/ExtrinsicPayload.ts index c4363d0f03..f6283d91ff 100644 --- a/packages/types/src/extrinsic/v4/ExtrinsicPayload.ts +++ b/packages/types/src/extrinsic/v4/ExtrinsicPayload.ts @@ -4,8 +4,8 @@ import type { SignOptions } from '@polkadot/keyring/types'; import type { Inspect, Registry } from '@polkadot/types-codec/types'; import type { HexString } from '@polkadot/util/types'; +import type { BlockHash } from '../../interfaces/chain'; import type { ExtrinsicEra } from '../../interfaces/extrinsics'; -import type { Hash } from '../../interfaces/runtime'; import type { ExtrinsicPayloadValue, ICompact, IKeyringPair, INumber, IOption } from '../../types'; import { Bytes, Enum, Struct } from '@polkadot/types-codec'; @@ -45,9 +45,9 @@ export class GenericExtrinsicPayloadV4 extends Struct { } /** - * @description The block [[Hash]] the signature applies to (mortal/immortal) + * @description The block [[BlockHash]] the signature applies to (mortal/immortal) */ - public get blockHash (): Hash { + public get blockHash (): BlockHash { return this.getT('blockHash'); } @@ -59,9 +59,9 @@ export class GenericExtrinsicPayloadV4 extends Struct { } /** - * @description The genesis [[Hash]] the signature applies to (mortal/immortal) + * @description The genesis [[BlockHash]] the signature applies to (mortal/immortal) */ - public get genesisHash (): Hash { + public get genesisHash (): BlockHash { return this.getT('genesisHash'); } @@ -101,8 +101,7 @@ export class GenericExtrinsicPayloadV4 extends Struct { } /** - * @description - * The (optional) asset id for this signature for chains that support transaction fees in assets + * @description The (optional) asset id for this signature for chains that support transaction fees in assets */ public get assetId (): IOption { return this.getT('assetId'); @@ -116,7 +115,7 @@ export class GenericExtrinsicPayloadV4 extends Struct { // don't want the method (Bytes) to have the length prefix included. This // means that the data-as-signed is un-decodable, but is also doesn't need // the extra information, only the pure data (and is not decoded) ... - // The same applies to V1..V3, if we have a V5, carrythis comment + // The same applies to V1..V3, if we have a V5, carry this comment return sign(this.registry, signerPair, this.toU8a({ method: true }), this.#signOptions); } }