diff --git a/.changeset/wet-toes-switch.md b/.changeset/wet-toes-switch.md new file mode 100644 index 00000000000..b42a506be63 --- /dev/null +++ b/.changeset/wet-toes-switch.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/account": patch +--- + +feat: parse message response from `getMessageByNonce` diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 87f152814f1..ede8ad984f8 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -1790,8 +1790,15 @@ Supported fuel-core version: ${mock.supportedVersion}.` const nonce = '0x381de90750098776c71544527fd253412908dec3d07ce9a7367bd1ba975908a0'; const message = await provider.getMessageByNonce(nonce); - expect(message).toBeDefined(); - expect(message?.nonce).toEqual(nonce); + expect(message).toStrictEqual({ + messageId: expect.any(String), + sender: expect.any(Address), + recipient: expect.any(Address), + nonce: expect.any(String), + amount: expect.any(BN), + data: expect.any(Uint8Array), + daHeight: expect.any(BN), + }); }); describe('paginated methods', () => { diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 710327bfdbb..6133c83c70a 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -27,7 +27,6 @@ import type { GqlTxParameters as TxParameters, GqlPageInfo, GqlRelayedTransactionFailed, - GqlMessage, Requester, } from './__generated__/operations'; import type { Coin } from './coin'; @@ -1906,13 +1905,29 @@ Supported fuel-core version: ${supportedVersion}.` * @param nonce - The nonce of the message to retrieve. * @returns A promise that resolves to the Message object or null. */ - async getMessageByNonce(nonce: string): Promise { - const { message } = await this.operations.getMessageByNonce({ nonce }); + async getMessageByNonce(nonce: string): Promise { + const { message: rawMessage } = await this.operations.getMessageByNonce({ nonce }); - if (!message) { + if (!rawMessage) { return null; } + const message: Message = { + messageId: InputMessageCoder.getMessageId({ + sender: rawMessage.sender, + recipient: rawMessage.recipient, + nonce: rawMessage.nonce, + amount: bn(rawMessage.amount), + data: rawMessage.data, + }), + sender: Address.fromAddressOrString(rawMessage.sender), + recipient: Address.fromAddressOrString(rawMessage.recipient), + nonce: rawMessage.nonce, + amount: bn(rawMessage.amount), + data: InputMessageCoder.decodeData(rawMessage.data), + daHeight: bn(rawMessage.daHeight), + }; + return message; }