Skip to content

Commit

Permalink
fix(ExtrinsicPayload): decode assetId with and without option (#6037)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosala authored Nov 25, 2024
1 parent 8fd0763 commit 7a2da0c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/types/src/extrinsic/ExtrinsicPayload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -69,6 +71,7 @@ describe('ExtrinsicPayload', (): void => {
},
parents: 0
});
expect(ext.assetId.toJSON()).toEqual(ext2.assetId.toJSON());
});

it('handles toU8a(true) correctly', (): void => {
Expand Down
18 changes: 12 additions & 6 deletions packages/types/src/extrinsic/ExtrinsicPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }]);
Expand Down

0 comments on commit 7a2da0c

Please sign in to comment.