Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: parse message response from getMessageByNonce #3098

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1734,8 +1734,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 @@ -1864,13 +1863,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 = {
Torres-ssf marked this conversation as resolved.
Show resolved Hide resolved
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
Loading