Skip to content

Commit

Permalink
Merge branch 'master' into st/feat/add-block-header-to-queries-responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Torres-ssf authored Sep 4, 2024
2 parents 8e7c2f3 + 4cbba82 commit 37c0310
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/wet-toes-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": patch
---

feat: parse message response from `getMessageByNonce`
11 changes: 9 additions & 2 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
23 changes: 19 additions & 4 deletions packages/account/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import type {
GqlTxParameters as TxParameters,
GqlPageInfo,
GqlRelayedTransactionFailed,
GqlMessage,
Requester,
} from './__generated__/operations';
import type { Coin } from './coin';
Expand Down Expand Up @@ -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<GqlMessage | null> {
const { message } = await this.operations.getMessageByNonce({ nonce });
async getMessageByNonce(nonce: string): Promise<Message | null> {
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;
}

Expand Down

0 comments on commit 37c0310

Please sign in to comment.