Ensure SignerPayload has withSignedTransaction (#5922)

* Ensure SignerPayload has `withSignedTransaction`

* remove console.log

* fix tests
This commit is contained in:
Tarik Gul
2024-06-27 16:32:45 -04:00
committed by GitHub
parent 0bac3d4915
commit 5a44d3b6e0
2 changed files with 18 additions and 7 deletions
@@ -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 => {
+10 -3
View File
@@ -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<string, unknown> | Map<unknown, unknown> | unknown[]) {
const extensionTypes = objectSpread<Record<string, string>>({}, registry.getSignedExtensionTypes(), registry.getSignedExtensionExtra());
super(registry, objectSpread<Record<string, string>>({}, extensionTypes, knownTypes), value);
super(registry, objectSpread<Record<string, string>>({}, 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
});
}