Skip to content

Commit ef12f77

Browse files
committed
Report system chunk transactions within a block
1 parent 3455391 commit ef12f77

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

internal/blocks/blocks_test.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,31 @@ func Test_GetBlock(t *testing.T) {
4646
assert.Equal(t, uint64(100), args.Get(3).(uint64))
4747
}).Return(nil, nil)
4848

49-
srv.GetCollection.Return(nil, nil)
50-
5149
returnBlock := tests.NewBlock()
5250
returnBlock.Height = uint64(100)
5351

5452
srv.GetBlock.Run(func(args mock.Arguments) {
5553
assert.Equal(t, uint64(100), args.Get(1).(flowkit.BlockQuery).Height)
5654
}).Return(returnBlock, nil)
5755

56+
returnCollection := tests.NewCollection()
57+
transaction1 := tests.NewTransaction()
58+
transaction2 := tests.NewTransaction()
59+
returnCollection.TransactionIDs = []flow.Identifier{
60+
transaction1.ID(),
61+
transaction2.ID(),
62+
}
63+
transactions := []*flow.Transaction{
64+
transaction1,
65+
transaction2,
66+
}
67+
68+
srv.GetTransactionsByBlockID.Run(func(args mock.Arguments) {
69+
assert.Equal(t, returnBlock.ID, args.Get(1).(flow.Identifier))
70+
}).Return(transactions, nil, nil)
71+
72+
srv.GetCollection.Return(returnCollection, nil)
73+
5874
result, err := get(inArgs, command.GlobalFlags{}, util.NoLogger, rw, srv.Mock)
5975
assert.NotNil(t, result)
6076
assert.NoError(t, err)

internal/blocks/get.go

+18
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,31 @@ func get(
8282
}
8383

8484
collections := make([]*flowsdk.Collection, 0)
85+
collectionTxs := 0
8586
if command.ContainsFlag(blockFlags.Include, "transactions") {
87+
var lastCollection *flowsdk.Collection
8688
for _, guarantee := range block.CollectionGuarantees {
8789
collection, err := flow.GetCollection(context.Background(), guarantee.CollectionID)
8890
if err != nil {
8991
return nil, err
9092
}
9193
collections = append(collections, collection)
94+
collectionTxs += len(collection.TransactionIDs)
95+
lastCollection = collection
96+
}
97+
98+
transactions, _, err := flow.GetTransactionsByBlockID(context.Background(), block.ID)
99+
if err != nil {
100+
return nil, err
101+
}
102+
// The last transaction returned from `flow.GetTransactionsByBlockID`,
103+
// is the system chunk transaction. We add it as the last transaction
104+
// in the last collection.
105+
if lastCollection != nil && len(transactions) == (collectionTxs+1) {
106+
lastCollection.TransactionIDs = append(
107+
lastCollection.TransactionIDs,
108+
transactions[collectionTxs].ID(),
109+
)
92110
}
93111
}
94112

0 commit comments

Comments
 (0)