From ef12f7712a12137dd07bbb5505c6228384d8bc74 Mon Sep 17 00:00:00 2001 From: Ardit Marku Date: Thu, 13 Jul 2023 12:06:51 +0300 Subject: [PATCH] Report system chunk transactions within a block --- internal/blocks/blocks_test.go | 20 ++++++++++++++++++-- internal/blocks/get.go | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/internal/blocks/blocks_test.go b/internal/blocks/blocks_test.go index 04f6dd12d..077d2d8d3 100644 --- a/internal/blocks/blocks_test.go +++ b/internal/blocks/blocks_test.go @@ -46,8 +46,6 @@ func Test_GetBlock(t *testing.T) { assert.Equal(t, uint64(100), args.Get(3).(uint64)) }).Return(nil, nil) - srv.GetCollection.Return(nil, nil) - returnBlock := tests.NewBlock() returnBlock.Height = uint64(100) @@ -55,6 +53,24 @@ func Test_GetBlock(t *testing.T) { assert.Equal(t, uint64(100), args.Get(1).(flowkit.BlockQuery).Height) }).Return(returnBlock, nil) + returnCollection := tests.NewCollection() + transaction1 := tests.NewTransaction() + transaction2 := tests.NewTransaction() + returnCollection.TransactionIDs = []flow.Identifier{ + transaction1.ID(), + transaction2.ID(), + } + transactions := []*flow.Transaction{ + transaction1, + transaction2, + } + + srv.GetTransactionsByBlockID.Run(func(args mock.Arguments) { + assert.Equal(t, returnBlock.ID, args.Get(1).(flow.Identifier)) + }).Return(transactions, nil, nil) + + srv.GetCollection.Return(returnCollection, nil) + result, err := get(inArgs, command.GlobalFlags{}, util.NoLogger, rw, srv.Mock) assert.NotNil(t, result) assert.NoError(t, err) diff --git a/internal/blocks/get.go b/internal/blocks/get.go index de384fd27..27353531e 100644 --- a/internal/blocks/get.go +++ b/internal/blocks/get.go @@ -82,13 +82,31 @@ func get( } collections := make([]*flowsdk.Collection, 0) + collectionTxs := 0 if command.ContainsFlag(blockFlags.Include, "transactions") { + var lastCollection *flowsdk.Collection for _, guarantee := range block.CollectionGuarantees { collection, err := flow.GetCollection(context.Background(), guarantee.CollectionID) if err != nil { return nil, err } collections = append(collections, collection) + collectionTxs += len(collection.TransactionIDs) + lastCollection = collection + } + + transactions, _, err := flow.GetTransactionsByBlockID(context.Background(), block.ID) + if err != nil { + return nil, err + } + // The last transaction returned from `flow.GetTransactionsByBlockID`, + // is the system chunk transaction. We add it as the last transaction + // in the last collection. + if lastCollection != nil && len(transactions) == (collectionTxs+1) { + lastCollection.TransactionIDs = append( + lastCollection.TransactionIDs, + transactions[collectionTxs].ID(), + ) } }