From c648992f2d1872cb2a6c07e1f69052a0ed9e9611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:19:58 -0300 Subject: [PATCH 1/6] modify blockFragment --- packages/account/src/providers/operations.graphql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/account/src/providers/operations.graphql b/packages/account/src/providers/operations.graphql index c40006dbef1..cde0e9b628b 100644 --- a/packages/account/src/providers/operations.graphql +++ b/packages/account/src/providers/operations.graphql @@ -221,6 +221,14 @@ fragment blockFragment on Block { height header { time + daHeight + stateTransitionBytecodeVersion + transactionsCount + transactionsRoot + messageOutboxRoot + eventInboxRoot + prevRoot + applicationHash } transactions { id From 7e42a1c7fe0fd39f233d7d746bd3c8f1ae195862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:20:18 -0300 Subject: [PATCH 2/6] update block type --- packages/account/src/providers/provider.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index bed4c0a2200..c9a7da5967b 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -91,6 +91,16 @@ export type Block = { height: BN; time: string; transactionIds: string[]; + header: { + daHeight: BN; + stateTransitionBytecodeVersion: string; + transactionsCount: string; + transactionsRoot: string; + messageOutboxRoot: string; + eventInboxRoot: string; + prevRoot: string; + applicationHash: string; + }; }; export type GetCoinsResponse = { From c1b8817e86631e0111a0d134139e214fb8028c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:21:05 -0300 Subject: [PATCH 3/6] update provider block related methods responses --- packages/account/src/providers/provider.ts | 40 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index c9a7da5967b..7bc93a78e02 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -1437,11 +1437,23 @@ Supported fuel-core version: ${supportedVersion}.` return null; } + const { header, height, id, transactions } = block; + return { - id: block.id, - height: bn(block.height), - time: block.header.time, - transactionIds: block.transactions.map((tx) => tx.id), + id, + height: bn(height), + time: header.time, + header: { + applicationHash: header.applicationHash, + daHeight: bn(header.daHeight), + eventInboxRoot: header.eventInboxRoot, + messageOutboxRoot: header.messageOutboxRoot, + prevRoot: header.prevRoot, + stateTransitionBytecodeVersion: header.stateTransitionBytecodeVersion, + transactionsCount: header.transactionsCount, + transactionsRoot: header.transactionsRoot, + }, + transactionIds: transactions.map((tx) => tx.id), }; } @@ -1465,6 +1477,16 @@ Supported fuel-core version: ${supportedVersion}.` id: block.id, height: bn(block.height), time: block.header.time, + header: { + applicationHash: block.header.applicationHash, + daHeight: bn(block.header.daHeight), + eventInboxRoot: block.header.eventInboxRoot, + messageOutboxRoot: block.header.messageOutboxRoot, + prevRoot: block.header.prevRoot, + stateTransitionBytecodeVersion: block.header.stateTransitionBytecodeVersion, + transactionsCount: block.header.transactionsCount, + transactionsRoot: block.header.transactionsRoot, + }, transactionIds: block.transactions.map((tx) => tx.id), })); @@ -1500,6 +1522,16 @@ Supported fuel-core version: ${supportedVersion}.` id: block.id, height: bn(block.height, 10), time: block.header.time, + header: { + applicationHash: block.header.applicationHash, + daHeight: bn(block.header.daHeight), + eventInboxRoot: block.header.eventInboxRoot, + messageOutboxRoot: block.header.messageOutboxRoot, + prevRoot: block.header.prevRoot, + stateTransitionBytecodeVersion: block.header.stateTransitionBytecodeVersion, + transactionsCount: block.header.transactionsCount, + transactionsRoot: block.header.transactionsRoot, + }, transactionIds: block.transactions.map((tx) => tx.id), transactions: block.transactions.map( (tx) => new TransactionCoder().decode(arrayify(tx.rawPayload), 0)?.[0] From 1b6f011448aafe287983eb4eb89351f5fe525ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:21:12 -0300 Subject: [PATCH 4/6] update fixture --- packages/account/test/fixtures/chain.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/account/test/fixtures/chain.ts b/packages/account/test/fixtures/chain.ts index b0eec54572f..82dda8ca058 100644 --- a/packages/account/test/fixtures/chain.ts +++ b/packages/account/test/fixtures/chain.ts @@ -280,7 +280,17 @@ export const MOCK_CHAIN: GqlChainInfoFragment = { latestBlock: { id: '0xb9e55ced368c8d8f1aa487d33e97043e5891406792ea5d61f7807d0441d34722', height: '234', - header: { time: '4611686020122537935' }, + header: { + time: '4611686020152758037', + applicationHash: '0x9b4b3f3021fec42b2d946b2c6547841e379716122f78a6f22d65f51d6e1a2746', + daHeight: '0', + eventInboxRoot: '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', + messageOutboxRoot: '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', + prevRoot: '0x68a08304aa13a972e471d3b15e9a59d18a50301c3990840ed4282b2e7b6a9008', + stateTransitionBytecodeVersion: '0', + transactionsCount: '1', + transactionsRoot: '0x4d9e0e3cda1af0c5bbf3dff9af9025ee2e264cc88bdef9dd103fb3a96d0a21ba', + }, transactions: [ { id: '0x304fb90a1a9897d839dcd9a5b93739ca6045638fc6520e2cf5735dd84b2de4a7', From f4d396457630ff4aebd02bae45950ea5e1f24972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:21:23 -0300 Subject: [PATCH 5/6] add and improve some test cases --- .../account/src/providers/provider.test.ts | 72 ++++++++++++++++--- 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index c92f2c5b656..478e0e62256 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -845,6 +845,29 @@ describe('Provider', () => { ); }); + it('can getBlock', async () => { + using launched = await setupTestProviderAndWallets(); + const { provider } = launched; + await provider.produceBlocks(1); + const block = await provider.getBlock('latest'); + expect(block).toStrictEqual({ + id: expect.any(String), + height: expect.any(BN), + time: expect.any(String), + header: { + applicationHash: expect.any(String), + daHeight: expect.any(BN), + eventInboxRoot: expect.any(String), + messageOutboxRoot: expect.any(String), + prevRoot: expect.any(String), + stateTransitionBytecodeVersion: expect.any(String), + transactionsCount: expect.any(String), + transactionsRoot: expect.any(String), + }, + transactionIds: expect.any(Array), + }); + }); + it('can getBlocks', async () => { using launched = await setupTestProviderAndWallets(); const blocksLenght = 5; @@ -856,14 +879,47 @@ describe('Provider', () => { }); expect(blocks.length).toBe(blocksLenght); blocks.forEach((block) => { - expect(block).toEqual( - expect.objectContaining({ - id: expect.any(String), - height: expect.any(BN), - time: expect.any(String), - transactionIds: expect.any(Array), - }) - ); + expect(block).toStrictEqual({ + id: expect.any(String), + height: expect.any(BN), + time: expect.any(String), + header: { + applicationHash: expect.any(String), + daHeight: expect.any(BN), + eventInboxRoot: expect.any(String), + messageOutboxRoot: expect.any(String), + prevRoot: expect.any(String), + stateTransitionBytecodeVersion: expect.any(String), + transactionsCount: expect.any(String), + transactionsRoot: expect.any(String), + }, + transactionIds: expect.any(Array), + }); + }); + }); + + it('can getBlockWithTransactions', async () => { + using launched = await setupTestProviderAndWallets(); + const { provider } = launched; + await provider.produceBlocks(1); + const block = await provider.getBlockWithTransactions('latest'); + const { transactions } = await provider.getTransactions({ first: 100 }); + expect(block).toStrictEqual({ + id: expect.any(String), + height: expect.any(BN), + time: expect.any(String), + header: { + applicationHash: expect.any(String), + daHeight: expect.any(BN), + eventInboxRoot: expect.any(String), + messageOutboxRoot: expect.any(String), + prevRoot: expect.any(String), + stateTransitionBytecodeVersion: expect.any(String), + transactionsCount: expect.any(String), + transactionsRoot: expect.any(String), + }, + transactionIds: expect.any(Array), + transactions, }); }); From 60cdb1296c5806e190370fb805b013c24392cc23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:21:30 -0300 Subject: [PATCH 6/6] add changeset --- .changeset/fifty-roses-fry.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fifty-roses-fry.md diff --git a/.changeset/fifty-roses-fry.md b/.changeset/fifty-roses-fry.md new file mode 100644 index 00000000000..7930fcee637 --- /dev/null +++ b/.changeset/fifty-roses-fry.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/account": patch +--- + +feat: add block header to responses in block-related queries