@@ -31,7 +31,6 @@ import (
31
31
"github.com/onflow/cadence"
32
32
"github.com/onflow/cadence/encoding/json"
33
33
"github.com/onflow/flow/protobuf/go/flow/access"
34
- "github.com/onflow/flow/protobuf/go/flow/entities"
35
34
"github.com/onflow/flow/protobuf/go/flow/executiondata"
36
35
37
36
"github.com/onflow/flow-go-sdk"
@@ -81,6 +80,7 @@ type BaseClient struct {
81
80
executionDataClient ExecutionDataRPCClient
82
81
close func () error
83
82
jsonOptions []json.Option
83
+ eventEncoding flow.EventEncodingVersion
84
84
}
85
85
86
86
// NewBaseClient creates a new gRPC handler for network communication.
@@ -99,14 +99,16 @@ func NewBaseClient(url string, opts ...grpc.DialOption) (*BaseClient, error) {
99
99
executionDataClient : execDataClient ,
100
100
close : func () error { return conn .Close () },
101
101
jsonOptions : []json.Option {json .WithAllowUnstructuredStaticTypes (true )},
102
+ eventEncoding : flow .EventEncodingVersionCCF ,
102
103
}, nil
103
104
}
104
105
105
106
// NewFromRPCClient initializes a Flow client using a pre-configured gRPC provider.
106
107
func NewFromRPCClient (rpcClient RPCClient ) * BaseClient {
107
108
return & BaseClient {
108
- rpcClient : rpcClient ,
109
- close : func () error { return nil },
109
+ rpcClient : rpcClient ,
110
+ close : func () error { return nil },
111
+ eventEncoding : flow .EventEncodingVersionCCF ,
110
112
}
111
113
}
112
114
@@ -115,13 +117,22 @@ func NewFromExecutionDataRPCClient(rpcClient ExecutionDataRPCClient) *BaseClient
115
117
return & BaseClient {
116
118
executionDataClient : rpcClient ,
117
119
close : func () error { return nil },
120
+ eventEncoding : flow .EventEncodingVersionCCF ,
118
121
}
119
122
}
120
123
121
124
func (c * BaseClient ) SetJSONOptions (options []json.Option ) {
122
125
c .jsonOptions = options
123
126
}
124
127
128
+ func (c * BaseClient ) SetEventEncoding (version flow.EventEncodingVersion ) {
129
+ c .eventEncoding = version
130
+ }
131
+
132
+ func (c * BaseClient ) RPCClient () RPCClient {
133
+ return c .rpcClient
134
+ }
135
+
125
136
// Close closes the client connection.
126
137
func (c * BaseClient ) Close () error {
127
138
return c .close ()
@@ -380,7 +391,7 @@ func (c *BaseClient) GetTransactionResult(
380
391
) (* flow.TransactionResult , error ) {
381
392
req := & access.GetTransactionRequest {
382
393
Id : txID .Bytes (),
383
- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
394
+ EventEncodingVersion : c . eventEncoding ,
384
395
}
385
396
386
397
res , err := c .rpcClient .GetTransactionResult (ctx , req , opts ... )
@@ -406,7 +417,7 @@ func (c *BaseClient) GetTransactionResultByIndex(
406
417
req := & access.GetTransactionByIndexRequest {
407
418
BlockId : blockID .Bytes (),
408
419
Index : index ,
409
- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
420
+ EventEncodingVersion : c . eventEncoding ,
410
421
}
411
422
412
423
res , err := c .rpcClient .GetTransactionResultByIndex (ctx , req , opts ... )
@@ -429,7 +440,7 @@ func (c *BaseClient) GetTransactionResultsByBlockID(
429
440
430
441
req := & access.GetTransactionsByBlockIDRequest {
431
442
BlockId : blockID .Bytes (),
432
- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
443
+ EventEncodingVersion : c . eventEncoding ,
433
444
}
434
445
435
446
res , err := c .rpcClient .GetTransactionResultsByBlockID (ctx , req , opts ... )
@@ -607,7 +618,7 @@ func (c *BaseClient) GetEventsForHeightRange(
607
618
Type : query .Type ,
608
619
StartHeight : query .StartHeight ,
609
620
EndHeight : query .EndHeight ,
610
- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
621
+ EventEncodingVersion : c . eventEncoding ,
611
622
}
612
623
613
624
res , err := c .rpcClient .GetEventsForHeightRange (ctx , req , opts ... )
@@ -627,7 +638,7 @@ func (c *BaseClient) GetEventsForBlockIDs(
627
638
req := & access.GetEventsForBlockIDsRequest {
628
639
Type : eventType ,
629
640
BlockIds : identifiersToMessages (blockIDs ),
630
- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
641
+ EventEncodingVersion : c . eventEncoding ,
631
642
}
632
643
633
644
res , err := c .rpcClient .GetEventsForBlockIDs (ctx , req , opts ... )
@@ -724,7 +735,7 @@ func (c *BaseClient) GetExecutionDataByBlockID(
724
735
725
736
ed , err := c .executionDataClient .GetExecutionDataByBlockID (ctx , & executiondata.GetExecutionDataByBlockIDRequest {
726
737
BlockId : identifierToMessage (blockID ),
727
- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
738
+ EventEncodingVersion : c . eventEncoding ,
728
739
}, opts ... )
729
740
if err != nil {
730
741
return nil , newRPCError (err )
@@ -741,7 +752,7 @@ func (c *BaseClient) SubscribeExecutionDataByBlockID(
741
752
) (<- chan flow.ExecutionDataStreamResponse , <- chan error , error ) {
742
753
req := executiondata.SubscribeExecutionDataRequest {
743
754
StartBlockId : startBlockID [:],
744
- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
755
+ EventEncodingVersion : c . eventEncoding ,
745
756
}
746
757
return c .subscribeExecutionData (ctx , & req , opts ... )
747
758
}
@@ -753,7 +764,7 @@ func (c *BaseClient) SubscribeExecutionDataByBlockHeight(
753
764
) (<- chan flow.ExecutionDataStreamResponse , <- chan error , error ) {
754
765
req := executiondata.SubscribeExecutionDataRequest {
755
766
StartBlockHeight : startHeight ,
756
- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
767
+ EventEncodingVersion : c . eventEncoding ,
757
768
}
758
769
return c .subscribeExecutionData (ctx , & req , opts ... )
759
770
}
@@ -824,7 +835,7 @@ func (c *BaseClient) SubscribeEventsByBlockID(
824
835
) (<- chan flow.BlockEvents , <- chan error , error ) {
825
836
req := executiondata.SubscribeEventsRequest {
826
837
StartBlockId : startBlockID [:],
827
- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
838
+ EventEncodingVersion : c . eventEncoding ,
828
839
}
829
840
return c .subscribeEvents (ctx , & req , filter , opts ... )
830
841
}
@@ -837,7 +848,7 @@ func (c *BaseClient) SubscribeEventsByBlockHeight(
837
848
) (<- chan flow.BlockEvents , <- chan error , error ) {
838
849
req := executiondata.SubscribeEventsRequest {
839
850
StartBlockHeight : startHeight ,
840
- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
851
+ EventEncodingVersion : c . eventEncoding ,
841
852
}
842
853
return c .subscribeEvents (ctx , & req , filter , opts ... )
843
854
}
0 commit comments