From 5a44d3b6e089b71d202c160992e8503be8544057 Mon Sep 17 00:00:00 2001 From: Tarik Gul <47201679+TarikGul@users.noreply.github.com> Date: Thu, 27 Jun 2024 13:32:45 -0700 Subject: [PATCH] Ensure SignerPayload has `withSignedTransaction` (#5922) * Ensure SignerPayload has `withSignedTransaction` * remove console.log * fix tests --- packages/types/src/extrinsic/SignerPayload.spec.ts | 12 ++++++++---- packages/types/src/extrinsic/SignerPayload.ts | 13 ++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/types/src/extrinsic/SignerPayload.spec.ts b/packages/types/src/extrinsic/SignerPayload.spec.ts index f50e7b9168..23515cea96 100644 --- a/packages/types/src/extrinsic/SignerPayload.spec.ts +++ b/packages/types/src/extrinsic/SignerPayload.spec.ts @@ -31,7 +31,8 @@ describe('SignerPayload', (): void => { specVersion: '0x00000006', tip: '0x00000000000000000000000000005678', transactionVersion: '0x00000007', - version: 4 + version: 4, + withSignedTransaction: false }; it('creates a valid JSON output', (): void => { @@ -50,7 +51,8 @@ describe('SignerPayload', (): void => { nonce: 0x1234, signedExtensions: ['CheckNonce'], tip: 0x5678, - version: 4 + version: 4, + withSignedTransaction: true }).toPayload() ).toEqual({ address: '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE', @@ -68,7 +70,8 @@ describe('SignerPayload', (): void => { specVersion: '0x00000000', tip: '0x00000000000000000000000000005678', transactionVersion: '0x00000000', - version: 4 + version: 4, + withSignedTransaction: true }); }); @@ -164,7 +167,8 @@ describe('SignerPayload', (): void => { specVersion: '0x00000006', tip: '0x00000000000000000000000000005678', transactionVersion: '0x00000007', - version: 4 + version: 4, + withSignedTransaction: false }; it('can build SignerPayload without additional SignedExtensions', (): void => { diff --git a/packages/types/src/extrinsic/SignerPayload.ts b/packages/types/src/extrinsic/SignerPayload.ts index 1e89b631ee..35806703e1 100644 --- a/packages/types/src/extrinsic/SignerPayload.ts +++ b/packages/types/src/extrinsic/SignerPayload.ts @@ -1,7 +1,7 @@ // Copyright 2017-2024 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Text, Vec } from '@polkadot/types-codec'; +import type { bool, Text, Vec } from '@polkadot/types-codec'; import type { AnyJson, Registry } from '@polkadot/types-codec/types'; import type { HexString } from '@polkadot/util/types'; import type { Address, BlockHash, Call, ExtrinsicEra, Hash, MultiLocation } from '../interfaces/index.js'; @@ -55,7 +55,7 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign constructor (registry: Registry, value?: HexString | Record | Map | unknown[]) { const extensionTypes = objectSpread>({}, registry.getSignedExtensionTypes(), registry.getSignedExtensionExtra()); - super(registry, objectSpread>({}, extensionTypes, knownTypes), value); + super(registry, objectSpread>({}, extensionTypes, knownTypes, { withSignedTransaction: 'bool' }), value); this.#extraTypes = {}; const getter = (key: string) => this.get(key); @@ -126,6 +126,12 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign return this.getT('metadataHash'); } + get withSignedTransaction (): boolean { + const val: bool = this.getT('withSignedTransaction'); + + return val.isTrue; + } + /** * @description Creates an representation of the structure as an ISignerPayload JSON */ @@ -166,7 +172,8 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign specVersion: this.runtimeVersion.specVersion.toHex(), tip: this.tip.toHex(), transactionVersion: this.runtimeVersion.transactionVersion.toHex(), - version: this.version.toNumber() + version: this.version.toNumber(), + withSignedTransaction: this.withSignedTransaction }); }