Skip to content

Commit 7a2da0c

Browse files
authored
fix(ExtrinsicPayload): decode assetId with and without option (#6037)
1 parent 8fd0763 commit 7a2da0c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

packages/types/src/extrinsic/ExtrinsicPayload.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ describe('ExtrinsicPayload', (): void => {
5555

5656
reg.setSignedExtensions(fallbackExtensions.concat(['ChargeAssetTxPayment']));
5757
const ext = new ExtrinsicPayload(reg, TEST_WITH_ASSET, { version: 4 });
58+
// remove option byte
59+
const ext2 = new ExtrinsicPayload(reg, { ...TEST_WITH_ASSET, assetId: `0x${TEST_WITH_ASSET.assetId.slice(4)}` }, { version: 4 });
5860

5961
expect(ext.assetId.toJSON()).toEqual({
6062
interior: {
@@ -69,6 +71,7 @@ describe('ExtrinsicPayload', (): void => {
6971
},
7072
parents: 0
7173
});
74+
expect(ext.assetId.toJSON()).toEqual(ext2.assetId.toJSON());
7275
});
7376

7477
it('handles toU8a(true) correctly', (): void => {

packages/types/src/extrinsic/ExtrinsicPayload.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,18 @@ function decodeExtrinsicPayload (registry: Registry, value?: GenericExtrinsicPay
5757
* ref: https://github.com/polkadot-js/api/pull/5967
5858
*/
5959
if (value && (value as ExtrinsicPayloadValue).assetId && isHex((value as ExtrinsicPayloadValue).assetId)) {
60-
const adjustedPayload = {
61-
...(value as ExtrinsicPayloadValue),
62-
assetId: registry.createType('TAssetConversion', hexToU8a((value as ExtrinsicPayloadValue).assetId)).toJSON()
63-
};
64-
65-
return registry.createTypeUnsafe(extVersion, [adjustedPayload, { version }]);
60+
const assetId = registry.createType('TAssetConversion', hexToU8a((value as ExtrinsicPayloadValue).assetId));
61+
62+
// we only want to adjust the payload if the hex passed has the option
63+
if ((value as ExtrinsicPayloadValue).assetId === '0x00' ||
64+
(value as ExtrinsicPayloadValue).assetId === '0x01' + assetId.toHex().slice(2)) {
65+
const adjustedPayload = {
66+
...(value as ExtrinsicPayloadValue),
67+
assetId: assetId.toJSON()
68+
};
69+
70+
return registry.createTypeUnsafe(extVersion, [adjustedPayload, { version }]);
71+
}
6672
}
6773

6874
return registry.createTypeUnsafe(extVersion, [value, { version }]);

0 commit comments

Comments
 (0)