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 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 diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index ece2951206c..ede8ad984f8 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, }); }); diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index f26ca222a71..6133c83c70a 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 = { @@ -1427,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), }; } @@ -1455,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), })); @@ -1490,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] 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',