@@ -31,7 +31,6 @@ import (
3131 "github.com/onflow/cadence"
3232 "github.com/onflow/cadence/encoding/json"
3333 "github.com/onflow/flow/protobuf/go/flow/access"
34- "github.com/onflow/flow/protobuf/go/flow/entities"
3534 "github.com/onflow/flow/protobuf/go/flow/executiondata"
3635
3736 "github.com/onflow/flow-go-sdk"
@@ -81,6 +80,7 @@ type BaseClient struct {
8180 executionDataClient ExecutionDataRPCClient
8281 close func () error
8382 jsonOptions []json.Option
83+ eventEncoding flow.EventEncodingVersion
8484}
8585
8686// NewBaseClient creates a new gRPC handler for network communication.
@@ -99,14 +99,16 @@ func NewBaseClient(url string, opts ...grpc.DialOption) (*BaseClient, error) {
9999 executionDataClient : execDataClient ,
100100 close : func () error { return conn .Close () },
101101 jsonOptions : []json.Option {json .WithAllowUnstructuredStaticTypes (true )},
102+ eventEncoding : flow .EventEncodingVersionCCF ,
102103 }, nil
103104}
104105
105106// NewFromRPCClient initializes a Flow client using a pre-configured gRPC provider.
106107func NewFromRPCClient (rpcClient RPCClient ) * BaseClient {
107108 return & BaseClient {
108- rpcClient : rpcClient ,
109- close : func () error { return nil },
109+ rpcClient : rpcClient ,
110+ close : func () error { return nil },
111+ eventEncoding : flow .EventEncodingVersionCCF ,
110112 }
111113}
112114
@@ -115,13 +117,22 @@ func NewFromExecutionDataRPCClient(rpcClient ExecutionDataRPCClient) *BaseClient
115117 return & BaseClient {
116118 executionDataClient : rpcClient ,
117119 close : func () error { return nil },
120+ eventEncoding : flow .EventEncodingVersionCCF ,
118121 }
119122}
120123
121124func (c * BaseClient ) SetJSONOptions (options []json.Option ) {
122125 c .jsonOptions = options
123126}
124127
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+
125136// Close closes the client connection.
126137func (c * BaseClient ) Close () error {
127138 return c .close ()
@@ -380,7 +391,7 @@ func (c *BaseClient) GetTransactionResult(
380391) (* flow.TransactionResult , error ) {
381392 req := & access.GetTransactionRequest {
382393 Id : txID .Bytes (),
383- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
394+ EventEncodingVersion : c . eventEncoding ,
384395 }
385396
386397 res , err := c .rpcClient .GetTransactionResult (ctx , req , opts ... )
@@ -406,7 +417,7 @@ func (c *BaseClient) GetTransactionResultByIndex(
406417 req := & access.GetTransactionByIndexRequest {
407418 BlockId : blockID .Bytes (),
408419 Index : index ,
409- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
420+ EventEncodingVersion : c . eventEncoding ,
410421 }
411422
412423 res , err := c .rpcClient .GetTransactionResultByIndex (ctx , req , opts ... )
@@ -429,7 +440,7 @@ func (c *BaseClient) GetTransactionResultsByBlockID(
429440
430441 req := & access.GetTransactionsByBlockIDRequest {
431442 BlockId : blockID .Bytes (),
432- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
443+ EventEncodingVersion : c . eventEncoding ,
433444 }
434445
435446 res , err := c .rpcClient .GetTransactionResultsByBlockID (ctx , req , opts ... )
@@ -607,7 +618,7 @@ func (c *BaseClient) GetEventsForHeightRange(
607618 Type : query .Type ,
608619 StartHeight : query .StartHeight ,
609620 EndHeight : query .EndHeight ,
610- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
621+ EventEncodingVersion : c . eventEncoding ,
611622 }
612623
613624 res , err := c .rpcClient .GetEventsForHeightRange (ctx , req , opts ... )
@@ -627,7 +638,7 @@ func (c *BaseClient) GetEventsForBlockIDs(
627638 req := & access.GetEventsForBlockIDsRequest {
628639 Type : eventType ,
629640 BlockIds : identifiersToMessages (blockIDs ),
630- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
641+ EventEncodingVersion : c . eventEncoding ,
631642 }
632643
633644 res , err := c .rpcClient .GetEventsForBlockIDs (ctx , req , opts ... )
@@ -724,7 +735,7 @@ func (c *BaseClient) GetExecutionDataByBlockID(
724735
725736 ed , err := c .executionDataClient .GetExecutionDataByBlockID (ctx , & executiondata.GetExecutionDataByBlockIDRequest {
726737 BlockId : identifierToMessage (blockID ),
727- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
738+ EventEncodingVersion : c . eventEncoding ,
728739 }, opts ... )
729740 if err != nil {
730741 return nil , newRPCError (err )
@@ -741,7 +752,7 @@ func (c *BaseClient) SubscribeExecutionDataByBlockID(
741752) (<- chan flow.ExecutionDataStreamResponse , <- chan error , error ) {
742753 req := executiondata.SubscribeExecutionDataRequest {
743754 StartBlockId : startBlockID [:],
744- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
755+ EventEncodingVersion : c . eventEncoding ,
745756 }
746757 return c .subscribeExecutionData (ctx , & req , opts ... )
747758}
@@ -753,7 +764,7 @@ func (c *BaseClient) SubscribeExecutionDataByBlockHeight(
753764) (<- chan flow.ExecutionDataStreamResponse , <- chan error , error ) {
754765 req := executiondata.SubscribeExecutionDataRequest {
755766 StartBlockHeight : startHeight ,
756- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
767+ EventEncodingVersion : c . eventEncoding ,
757768 }
758769 return c .subscribeExecutionData (ctx , & req , opts ... )
759770}
@@ -824,7 +835,7 @@ func (c *BaseClient) SubscribeEventsByBlockID(
824835) (<- chan flow.BlockEvents , <- chan error , error ) {
825836 req := executiondata.SubscribeEventsRequest {
826837 StartBlockId : startBlockID [:],
827- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
838+ EventEncodingVersion : c . eventEncoding ,
828839 }
829840 return c .subscribeEvents (ctx , & req , filter , opts ... )
830841}
@@ -837,7 +848,7 @@ func (c *BaseClient) SubscribeEventsByBlockHeight(
837848) (<- chan flow.BlockEvents , <- chan error , error ) {
838849 req := executiondata.SubscribeEventsRequest {
839850 StartBlockHeight : startHeight ,
840- EventEncodingVersion : entities . EventEncodingVersion_CCF_V0 ,
851+ EventEncodingVersion : c . eventEncoding ,
841852 }
842853 return c .subscribeEvents (ctx , & req , filter , opts ... )
843854}
0 commit comments