@@ -25,6 +25,8 @@ import (
2525 "strings"
2626
2727 "github.com/onflow/flow-go-sdk"
28+ "github.com/onflow/flow-go/fvm/systemcontracts"
29+ flowGo "github.com/onflow/flow-go/model/flow"
2830 "github.com/spf13/cobra"
2931
3032 "github.com/onflow/flowkit/v2/output"
@@ -60,37 +62,26 @@ type transactionResult struct {
6062 tx * flow.Transaction
6163 include []string
6264 exclude []string
63- network string
64- }
65-
66- func NewTransactionResult (tx * flow.Transaction , result * flow.TransactionResult ) * transactionResult {
67- return & transactionResult {
68- result : result ,
69- tx : tx ,
70- network : "" , // Default to empty, should be set by caller
71- }
65+ chainID flowGo.ChainID
7266}
7367
7468// getBlockExplorerLink returns the block explorer link for the transaction if it's on mainnet or testnet
7569func (r * transactionResult ) getBlockExplorerLink () string {
76- if r .network == "" {
77- return ""
78- }
79-
80- // Only show block explorer links for mainnet and testnet
81- if r .network != "mainnet" && r .network != "testnet" {
70+ if r .chainID == "" {
8271 return ""
8372 }
8473
8574 txID := r .tx .ID ().String ()
8675
87- if r .network == "mainnet" {
76+ // Only show block explorer links for mainnet and testnet
77+ switch r .chainID {
78+ case flowGo .Mainnet :
8879 return fmt .Sprintf ("https://www.flowscan.io/tx/%s" , txID )
89- } else if r . network == "testnet" {
80+ case flowGo . Testnet :
9081 return fmt .Sprintf ("https://testnet.flowscan.io/tx/%s" , txID )
82+ default :
83+ return ""
9184 }
92-
93- return ""
9485}
9586
9687func (r * transactionResult ) JSON () any {
@@ -109,8 +100,9 @@ func (r *transactionResult) JSON() any {
109100 result ["block_height" ] = r .result .BlockHeight
110101 result ["status" ] = r .result .Status .String ()
111102
112- txEvents := make ([]any , 0 , len (r .result .Events ))
113- for _ , event := range r .result .Events {
103+ events := r .getDisplayEvents ()
104+ txEvents := make ([]any , 0 , len (events ))
105+ for _ , event := range events {
114106 txEvents = append (txEvents , map [string ]any {
115107 "index" : event .EventIndex ,
116108 "type" : event .Type ,
@@ -129,11 +121,48 @@ func (r *transactionResult) JSON() any {
129121 return result
130122}
131123
124+ func (r * transactionResult ) getDisplayEvents () []flow.Event {
125+ if r .result == nil || command .ContainsFlag (r .exclude , "events" ) {
126+ return nil
127+ }
128+
129+ events := r .result .Events
130+ if ! command .ContainsFlag (r .include , "fee-events" ) {
131+ events = filterFeeEvents (events , r .chainID )
132+ }
133+ return events
134+ }
135+
136+ func filterFeeEvents (events []flow.Event , chainID flowGo.ChainID ) []flow.Event {
137+ const feeEventsCountAppended = 4
138+
139+ if len (events ) == 0 || chainID == "" {
140+ return events
141+ }
142+
143+ // Get the FlowFees system contract address for this chain
144+ systemContracts := systemcontracts .SystemContractsForChain (chainID )
145+ flowFeesAddress := systemContracts .FlowFees .Address
146+
147+ // Build the expected event type: A.<address>.FlowFees.FeesDeducted
148+ expectedEventType := fmt .Sprintf ("A.%s.FlowFees.FeesDeducted" , flowFeesAddress .Hex ())
149+
150+ // Fee events are always at the end, so just check the last event
151+ lastEvent := events [len (events )- 1 ]
152+ if strings .HasPrefix (lastEvent .Type , expectedEventType ) {
153+ cutIndex := len (events ) - feeEventsCountAppended
154+ if cutIndex < 0 {
155+ cutIndex = 0
156+ }
157+ return events [:cutIndex ]
158+ }
159+
160+ return events
161+ }
162+
132163func (r * transactionResult ) String () string {
133164 var b bytes.Buffer
134165 writer := util .CreateTabWriter (& b )
135- const feeEventsCountAppended = 5
136- const feeDeductedEvent = "FeesDeducted"
137166
138167 if r .result != nil {
139168 _ , _ = fmt .Fprintf (writer , "%s\t %s\n " , branding .GrayStyle .Render ("Block ID" ), branding .PurpleStyle .Render (r .result .BlockID .String ()))
@@ -199,19 +228,10 @@ func (r *transactionResult) String() string {
199228 _ , _ = fmt .Fprintf (writer , "\n %s" , branding .GrayStyle .Render ("Signatures (minimized, use --include signatures)" ))
200229 }
201230
202- if r .result != nil && ! command .ContainsFlag (r .exclude , "events" ) {
231+ displayEvents := r .getDisplayEvents ()
232+ if displayEvents != nil {
203233 e := events.EventResult {
204- Events : r .result .Events ,
205- }
206-
207- if r .result != nil && e .Events != nil && ! command .ContainsFlag (r .include , "fee-events" ) {
208- for _ , event := range e .Events {
209- if strings .Contains (event .Type , feeDeductedEvent ) {
210- // if fee event are present remove them
211- e .Events = e .Events [:len (e .Events )- feeEventsCountAppended ]
212- break
213- }
214- }
234+ Events : displayEvents ,
215235 }
216236
217237 eventsOutput := e .String ()
@@ -263,7 +283,8 @@ func (r *transactionResult) Oneliner() string {
263283 r .tx .ID (), r .tx .Payer , r .tx .Authorizers )
264284
265285 if r .result != nil {
266- result += fmt .Sprintf (", Status: %s, Events: %s" , r .result .Status , r .result .Events )
286+ displayEvents := r .getDisplayEvents ()
287+ result += fmt .Sprintf (", Status: %s, Events: %s" , r .result .Status , displayEvents )
267288 }
268289
269290 return result
0 commit comments