From f2fd5c52400493258b6dfecf0ed2e5e07bfef4ba Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Mon, 1 Dec 2025 13:53:37 -0800 Subject: [PATCH 1/3] Include system transactions in `flow blocks get ` --- internal/blocks/blocks.go | 73 +++++++++++++++++++++++++--------- internal/blocks/blocks_test.go | 13 ++++-- internal/blocks/get.go | 21 +++++----- 3 files changed, 74 insertions(+), 33 deletions(-) diff --git a/internal/blocks/blocks.go b/internal/blocks/blocks.go index e4f1a5907..c1a013fef 100644 --- a/internal/blocks/blocks.go +++ b/internal/blocks/blocks.go @@ -42,10 +42,11 @@ func init() { } type blockResult struct { - block *flow.Block - events []flow.BlockEvents - collections []*flow.Collection - included []string + block *flow.Block + events []flow.BlockEvents + transactions []*flow.Transaction + results []*flow.TransactionResult + included []string } func (r *blockResult) JSON() any { @@ -56,23 +57,36 @@ func (r *blockResult) JSON() any { result["totalSeals"] = len(r.block.Seals) result["totalCollections"] = len(r.block.CollectionGuarantees) + // Keep collection info for backwards compatibility collections := make([]any, 0, len(r.block.CollectionGuarantees)) - for i, guarantee := range r.block.CollectionGuarantees { + for _, guarantee := range r.block.CollectionGuarantees { collection := make(map[string]any) collection["id"] = guarantee.CollectionID.String() - - if command.ContainsFlag(r.included, "transactions") { - txs := make([]string, 0) - for _, tx := range r.collections[i].TransactionIDs { - txs = append(txs, tx.String()) + collections = append(collections, collection) + } + result["collections"] = collections + + // Add transaction details if requested + if command.ContainsFlag(r.included, "transactions") && len(r.transactions) > 0 { + txs := make([]map[string]any, 0, len(r.transactions)) + for i, tx := range r.transactions { + txData := make(map[string]any) + txData["id"] = tx.ID().String() + txData["status"] = r.results[i].Status.String() + + // System transactions have empty collection ID + if r.results[i].CollectionID == flow.EmptyID { + txData["type"] = "system" + } else { + txData["type"] = "user" + txData["collectionId"] = r.results[i].CollectionID.String() } - collection["transactions"] = txs - } - collections = append(collections, collection) + txs = append(txs, txData) + } + result["transactions"] = txs } - result["collection"] = collections return result } @@ -99,17 +113,40 @@ func (r *blockResult) String() string { _, _ = fmt.Fprintf(writer, "Status\t%s\n", blockStatusToString(r.block.Status)) _, _ = fmt.Fprintf(writer, "Total Seals\t%v\n", len(r.block.Seals)) - _, _ = fmt.Fprintf(writer, "Total Collections\t%v\n", len(r.block.CollectionGuarantees)) + // Show collections for i, guarantee := range r.block.CollectionGuarantees { _, _ = fmt.Fprintf(writer, " Collection %d:\t%s\n", i, guarantee.CollectionID) + } - if command.ContainsFlag(r.included, "transactions") { - for x, tx := range r.collections[i].TransactionIDs { - _, _ = fmt.Fprintf(writer, " Transaction %d: %s\n", x, tx) + // Show transactions if included + if command.ContainsFlag(r.included, "transactions") && len(r.transactions) > 0 { + _, _ = fmt.Fprintf(writer, "\nTransactions:\n") + + userCount := 0 + systemCount := 0 + + for i, tx := range r.transactions { + var txType string + if r.results[i].CollectionID == flow.EmptyID { + txType = "system" + systemCount++ + } else { + txType = "user" + userCount++ } + + _, _ = fmt.Fprintf(writer, " [%d] %s\t%s (%s)\n", + i, + tx.ID().String(), + r.results[i].Status.String(), + txType, + ) } + + _, _ = fmt.Fprintf(writer, "\nTotal: %d transactions (%d user, %d system)\n", + len(r.transactions), userCount, systemCount) } if len(r.events) > 0 { diff --git a/internal/blocks/blocks_test.go b/internal/blocks/blocks_test.go index 7de64f141..5e3b15d4b 100644 --- a/internal/blocks/blocks_test.go +++ b/internal/blocks/blocks_test.go @@ -47,7 +47,11 @@ func Test_GetBlock(t *testing.T) { assert.Equal(t, uint64(100), args.Get(3).(uint64)) }).Return(nil, nil) - srv.GetCollection.Return(nil, nil) + srv.GetTransactionsByBlockID.Return( + []*flow.Transaction{tests.NewTransaction()}, + []*flow.TransactionResult{tests.NewTransactionResult(nil)}, + nil, + ) returnBlock := tests.NewBlock() returnBlock.Height = uint64(100) @@ -64,8 +68,9 @@ func Test_GetBlock(t *testing.T) { func Test_Result(t *testing.T) { result := blockResult{ - block: tests.NewBlock(), - collections: []*flow.Collection{tests.NewCollection()}, + block: tests.NewBlock(), + transactions: []*flow.Transaction{}, + results: []*flow.TransactionResult{}, } assert.Equal(t, strings.TrimPrefix(` @@ -86,7 +91,7 @@ Total Collections 3 t, map[string]any{ "blockId": "0303030303030303030303030303030303030303030303030303030303030303", - "collection": []any{ + "collections": []any{ map[string]any{"id": "0202020202020202020202020202020202020202020202020202020202020202"}, map[string]any{"id": "0404040404040404040404040404040404040404040404040404040404040404"}, map[string]any{"id": "0606060606060606060606060606060606060606060606060606060606060606"}, diff --git a/internal/blocks/get.go b/internal/blocks/get.go index 8f34517c9..edbfb15a1 100644 --- a/internal/blocks/get.go +++ b/internal/blocks/get.go @@ -82,21 +82,20 @@ func get( } } - collections := make([]*flowsdk.Collection, 0) + var transactions []*flowsdk.Transaction + var results []*flowsdk.TransactionResult if command.ContainsFlag(blockFlags.Include, "transactions") { - for _, guarantee := range block.CollectionGuarantees { - collection, err := flow.GetCollection(context.Background(), guarantee.CollectionID) - if err != nil { - return nil, err - } - collections = append(collections, collection) + transactions, results, err = flow.GetTransactionsByBlockID(context.Background(), block.ID) + if err != nil { + return nil, err } } return &blockResult{ - block: block, - events: events, - collections: collections, - included: blockFlags.Include, + block: block, + events: events, + transactions: transactions, + results: results, + included: blockFlags.Include, }, nil } From 04f2f100977c25f08960f066d2bba88aeb2aaf9b Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Fri, 5 Dec 2025 14:31:57 -0800 Subject: [PATCH 2/3] restore previous keying --- internal/blocks/blocks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/blocks/blocks.go b/internal/blocks/blocks.go index c1a013fef..3da55a8c8 100644 --- a/internal/blocks/blocks.go +++ b/internal/blocks/blocks.go @@ -64,7 +64,7 @@ func (r *blockResult) JSON() any { collection["id"] = guarantee.CollectionID.String() collections = append(collections, collection) } - result["collections"] = collections + result["collection"] = collections // Add transaction details if requested if command.ContainsFlag(r.included, "transactions") && len(r.transactions) > 0 { From 9c9144b5b22511d4ec67241cc7f63c23304f3b90 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Mon, 8 Dec 2025 11:01:13 -0800 Subject: [PATCH 3/3] fix test --- internal/blocks/blocks_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/blocks/blocks_test.go b/internal/blocks/blocks_test.go index 5e3b15d4b..3deb8c154 100644 --- a/internal/blocks/blocks_test.go +++ b/internal/blocks/blocks_test.go @@ -91,7 +91,7 @@ Total Collections 3 t, map[string]any{ "blockId": "0303030303030303030303030303030303030303030303030303030303030303", - "collections": []any{ + "collection": []any{ map[string]any{"id": "0202020202020202020202020202020202020202020202020202020202020202"}, map[string]any{"id": "0404040404040404040404040404040404040404040404040404040404040404"}, map[string]any{"id": "0606060606060606060606060606060606060606060606060606060606060606"},