Skip to content

Commit

Permalink
revert original deletion and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
TarikGul committed Nov 20, 2024
1 parent 307f7a2 commit d670457
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/types/src/extrinsic/ExtrinsicPayload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('ExtrinsicPayload', (): void => {

const TEST_WITH_ASSET = {
address: '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE',
assetId: '0x0002043205011f' as `0x${string}`,
assetId: '0x010002043205011f' as `0x${string}`,
blockHash: '0xde8f69eeb5e065e18c6950ff708d7e551f68dc9bf59a07c52367c0280f805ec7',
era: '0x0703',
genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b',
Expand Down
22 changes: 21 additions & 1 deletion packages/types/src/extrinsic/ExtrinsicPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { GenericExtrinsicEra } from './ExtrinsicEra.js';
import type { Preamble } from './types.js';

import { AbstractBase } from '@polkadot/types-codec';
import { u8aToHex } from '@polkadot/util';
import { hexToU8a, isHex, u8aToHex } from '@polkadot/util';

import { DEFAULT_PREAMBLE, LATEST_EXTRINSIC_VERSION } from './constants.js';

Expand Down Expand Up @@ -47,6 +47,26 @@ function decodeExtrinsicPayload (registry: Registry, value?: GenericExtrinsicPay

const extVersion = version === 5 ? PREAMBLES[preamble] : VERSIONS[version] || VERSIONS[0];

/**
* HACK: In order to change the assetId from `number | object` to HexString (While maintaining the true type ie Option<TAssetConversion>),
* to allow for easier generalization of the SignerPayloadJSON interface the below check is necessary. The ExtrinsicPayloadV4 class does not like
* a value passed in as an Option, and can't decode it properly. Therefore, we ensure to convert the following below, and then pass the option as a unwrapped
* JSON value.
*
* ref: https://github.com/polkadot-js/api/pull/5968
* 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()
};

console.log(JSON.stringify(registry.createType('TAssetConversion', hexToU8a((value as ExtrinsicPayloadValue).assetId)).toJSON(), null, 4));

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

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

Expand Down

0 comments on commit d670457

Please sign in to comment.