@@ -18,6 +18,7 @@ import (
1818 "github.com/hyperledger/fabric-sdk-go/api/apitxn/txnhandler"
1919 "github.com/hyperledger/fabric-sdk-go/pkg/errors"
2020 txnHandlerImpl "github.com/hyperledger/fabric-sdk-go/pkg/fabric-txn/txnhandler"
21+ "github.com/hyperledger/fabric-sdk-go/pkg/status"
2122)
2223
2324const (
@@ -57,19 +58,13 @@ func New(c Context) (*ChannelClient, error) {
5758}
5859
5960// Query chaincode using request and optional options provided
60- func (cc * ChannelClient ) Query (request apitxn.Request , options ... apitxn.Option ) ([]byte , error ) {
61-
62- response := cc .InvokeHandler (txnHandlerImpl .NewQueryHandler (), request , cc .addDefaultTimeout (apiconfig .Query , options ... )... )
63-
64- return response .Payload , response .Error
61+ func (cc * ChannelClient ) Query (request apitxn.Request , options ... apitxn.Option ) apitxn.Response {
62+ return cc .InvokeHandler (txnHandlerImpl .NewQueryHandler (), request , cc .addDefaultTimeout (apiconfig .Query , options ... )... )
6563}
6664
6765// Execute prepares and executes transaction using request and optional options provided
68- func (cc * ChannelClient ) Execute (request apitxn.Request , options ... apitxn.Option ) ([]byte , apitxn.TransactionID , error ) {
69-
70- response := cc .InvokeHandler (txnHandlerImpl .NewExecuteHandler (), request , cc .addDefaultTimeout (apiconfig .Execute , options ... )... )
71-
72- return response .Payload , response .TransactionID , response .Error
66+ func (cc * ChannelClient ) Execute (request apitxn.Request , options ... apitxn.Option ) apitxn.Response {
67+ return cc .InvokeHandler (txnHandlerImpl .NewExecuteHandler (), request , cc .addDefaultTimeout (apiconfig .Execute , options ... )... )
7368}
7469
7570//InvokeHandler invokes handler using request and options provided
@@ -87,19 +82,19 @@ func (cc *ChannelClient) InvokeHandler(handler txnhandler.Handler, request apitx
8782 return apitxn.Response {Error : err }
8883 }
8984
90- //Perform action through handler
91- go handler .Handle (requestContext , clientContext )
92-
93- //notifier in options will handle response if provided
94- if txnOpts .Notifier != nil {
95- return apitxn.Response {}
96- }
85+ complete := make (chan bool )
9786
87+ go func () {
88+ //Perform action through handler
89+ handler .Handle (requestContext , clientContext )
90+ complete <- true
91+ }()
9892 select {
99- case response := <- requestContext .Opts .Notifier :
100- return response
101- case <- time .After (requestContext .Opts .Timeout ):
102- return apitxn.Response {Error : errors .New ("handler timed out while performing operation" )}
93+ case <- complete :
94+ return requestContext .Response
95+ case <- time .After (txnOpts .Timeout ):
96+ return apitxn.Response {Error : status .New (status .ClientStatus , status .Timeout .ToInt32 (),
97+ "Operation timed out" , nil )}
10398 }
10499}
105100
@@ -127,10 +122,6 @@ func (cc *ChannelClient) prepareHandlerContexts(request apitxn.Request, options
127122 requestContext .Opts .Timeout = defaultHandlerTimeout
128123 }
129124
130- if requestContext .Opts .Notifier == nil {
131- requestContext .Opts .Notifier = make (chan apitxn.Response )
132- }
133-
134125 return requestContext , clientContext , nil
135126
136127}
0 commit comments