Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit e985ca4

Browse files
committed
[FAB-7968] Remove channel client async option
Change-Id: I10c46419c449455df1c7741e6d24709d12058ea6 Signed-off-by: Divyank Katira <Divyank.Katira@securekey.com>
1 parent b0efb7e commit e985ca4

File tree

18 files changed

+230
-317
lines changed

18 files changed

+230
-317
lines changed

api/apitxn/opts.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ func WithTimeout(timeout time.Duration) Option {
1818
}
1919
}
2020

21-
//WithNotifier encapsulates Response to Option
22-
func WithNotifier(notifier chan Response) Option {
23-
return func(opts *Opts) error {
24-
opts.Notifier = notifier
25-
return nil
26-
}
27-
}
28-
2921
//WithProposalProcessor encapsulates ProposalProcessors to Option
3022
func WithProposalProcessor(proposalProcessors ...ProposalProcessor) Option {
3123
return func(opts *Opts) error {

api/apitxn/txn.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ type Response struct {
3131

3232
// Opts allows the user to specify more advanced options
3333
type Opts struct {
34-
Notifier chan Response // async
3534
ProposalProcessors []ProposalProcessor // targets
3635
Timeout time.Duration
3736
}
@@ -71,10 +70,10 @@ type CCEvent struct {
7170
type ChannelClient interface {
7271

7372
// Query chaincode with request and optional options provided
74-
Query(request Request, opts ...Option) ([]byte, error)
73+
Query(request Request, opts ...Option) Response
7574

7675
// Execute execute transaction with request and optional options provided
77-
Execute(request Request, opts ...Option) ([]byte, TransactionID, error)
76+
Execute(request Request, opts ...Option) Response
7877

7978
// RegisterChaincodeEvent registers chain code event
8079
// @param {chan bool} channel which receives event details when the event is complete

pkg/fabric-txn/chclient/chclient.go

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2324
const (
@@ -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

Comments
 (0)