From 7a2da0c6d1a8c666aa605ab1aaba41c96a553b5f Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Mon, 25 Nov 2024 15:07:40 +0100 Subject: [PATCH] fix(ExtrinsicPayload): decode assetId with and without option (#6037) --- .../src/extrinsic/ExtrinsicPayload.spec.ts | 3 +++ .../types/src/extrinsic/ExtrinsicPayload.ts | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/types/src/extrinsic/ExtrinsicPayload.spec.ts b/packages/types/src/extrinsic/ExtrinsicPayload.spec.ts index 86fcee6e85c..03fca46ac86 100644 --- a/packages/types/src/extrinsic/ExtrinsicPayload.spec.ts +++ b/packages/types/src/extrinsic/ExtrinsicPayload.spec.ts @@ -55,6 +55,8 @@ describe('ExtrinsicPayload', (): void => { reg.setSignedExtensions(fallbackExtensions.concat(['ChargeAssetTxPayment'])); const ext = new ExtrinsicPayload(reg, TEST_WITH_ASSET, { version: 4 }); + // remove option byte + const ext2 = new ExtrinsicPayload(reg, { ...TEST_WITH_ASSET, assetId: `0x${TEST_WITH_ASSET.assetId.slice(4)}` }, { version: 4 }); expect(ext.assetId.toJSON()).toEqual({ interior: { @@ -69,6 +71,7 @@ describe('ExtrinsicPayload', (): void => { }, parents: 0 }); + expect(ext.assetId.toJSON()).toEqual(ext2.assetId.toJSON()); }); it('handles toU8a(true) correctly', (): void => { diff --git a/packages/types/src/extrinsic/ExtrinsicPayload.ts b/packages/types/src/extrinsic/ExtrinsicPayload.ts index ffe17c54360..1da7af67940 100644 --- a/packages/types/src/extrinsic/ExtrinsicPayload.ts +++ b/packages/types/src/extrinsic/ExtrinsicPayload.ts @@ -57,12 +57,18 @@ function decodeExtrinsicPayload (registry: Registry, value?: GenericExtrinsicPay * ref: https://github.com/polkadot-js/api/pull/5967 */ if (value && (value as ExtrinsicPayloadValue).assetId && isHex((value as ExtrinsicPayloadValue).assetId)) { - const adjustedPayload = { - ...(value as ExtrinsicPayloadValue), - assetId: registry.createType('TAssetConversion', hexToU8a((value as ExtrinsicPayloadValue).assetId)).toJSON() - }; - - return registry.createTypeUnsafe(extVersion, [adjustedPayload, { version }]); + const assetId = registry.createType('TAssetConversion', hexToU8a((value as ExtrinsicPayloadValue).assetId)); + + // we only want to adjust the payload if the hex passed has the option + if ((value as ExtrinsicPayloadValue).assetId === '0x00' || + (value as ExtrinsicPayloadValue).assetId === '0x01' + assetId.toHex().slice(2)) { + const adjustedPayload = { + ...(value as ExtrinsicPayloadValue), + assetId: assetId.toJSON() + }; + + return registry.createTypeUnsafe(extVersion, [adjustedPayload, { version }]); + } } return registry.createTypeUnsafe(extVersion, [value, { version }]);