Skip to content

Commit

Permalink
Report system chunk transactions within a block
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter committed Jul 27, 2023
1 parent 3455391 commit ef12f77
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/blocks/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,31 @@ 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)

srv.GetBlock.Run(func(args mock.Arguments) {
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)
Expand Down
18 changes: 18 additions & 0 deletions internal/blocks/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
}

Expand Down

0 comments on commit ef12f77

Please sign in to comment.