Skip to content

Commit

Permalink
Change assetId type in SignerPayloadJSON to HexString (#5967)
Browse files Browse the repository at this point in the history
* Change assetId type in SignerPayloadJSON to HexString

* fix encoding

* Fix tests

* also fix createClass
  • Loading branch information
TarikGul authored Sep 2, 2024
1 parent 25ab1d1 commit 1e604cc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/api/src/submittable/createClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
const ext = this.registry.createTypeUnsafe<Extrinsic>('Extrinsic', [result.signedTransaction]);
const newSignerPayload = this.registry.createTypeUnsafe<SignerPayload>('SignerPayload', [objectSpread({}, {
address,
assetId: ext.assetId ? ext.assetId.toHex() : null,
assetId: ext.assetId && ext.assetId.isSome ? ext.assetId.unwrap().toHex() : null,
blockHash: payload.blockHash,
blockNumber: header ? header.number : 0,
era: ext.era.toHex(),
Expand Down
8 changes: 4 additions & 4 deletions packages/types/src/extrinsic/SignerPayload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('SignerPayload', (): void => {
const TEST = {
address: '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE',
// eslint-disable-next-line sort-keys
assetId: { parents: 0, interior: { x2: [{ palletInstance: 50 }, { generalIndex: 123 }] } },
assetId: '0x0002043205ed01',
blockHash: '0xde8f69eeb5e065e18c6950ff708d7e551f68dc9bf59a07c52367c0280f805ec7',
blockNumber: '0x00231d30',
era: '0x0703',
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('SignerPayload', (): void => {
).toEqual({
address: '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE',
// eslint-disable-next-line sort-keys
assetId: { parents: 0, interior: { x2: [{ palletInstance: 50 }, { generalIndex: 123 }] } },
assetId: '0x0002043205ed01',
blockHash: '0xde8f69eeb5e065e18c6950ff708d7e551f68dc9bf59a07c52367c0280f805ec7',
blockNumber: '0x00231d30',
era: '0x0703',
Expand Down Expand Up @@ -88,12 +88,12 @@ describe('SignerPayload', (): void => {
expect(
test.toPayload().assetId
// eslint-disable-next-line sort-keys
).toEqual({ parents: 0, interior: { x2: [{ palletInstance: 50 }, { generalIndex: 123 }] } });
).toEqual('0x0002043205ed01');

expect(
new SignerPayload(registry, { assetId: 0 }).toPayload().assetId
// eslint-disable-next-line sort-keys
).toEqual({ parents: 0, interior: { here: null } });
).toEqual('0x0000');
});

it('re-constructs from JSON', (): void => {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/extrinsic/SignerPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign
// the known defaults as managed explicitly and has different
// formatting in cases, e.g. we mostly expose a hex format here
address: this.address.toString(),
assetId: this.assetId ? this.assetId.toJSON() : null,
assetId: this.assetId && this.assetId.isSome ? this.assetId.unwrap().toHex() : null,
blockHash: this.blockHash.toHex(),
blockNumber: this.blockNumber.toHex(),
era: this.era.toHex(),
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/types/extrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface SignerPayloadJSON {
/**
* @description The id of the asset used to pay fees, in hex
*/
assetId?: number | object;
assetId?: HexString;

/**
* @description The checkpoint hash of the block, in hex
Expand Down

0 comments on commit 1e604cc

Please sign in to comment.