Skip to content

Commit

Permalink
feat: expose ChannelProvider from the gateway
Browse files Browse the repository at this point in the history
This can be a useful escape hatch when one needs a ledger client and
already has a Gateway available.

Signed-off-by: Matthieu Blottière <matthieu.blottiere@owkin.com>
  • Loading branch information
mblottiere committed Jul 29, 2022
1 parent 965abe3 commit d36373a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,21 @@ func WithBlockNum(from uint64) Option {
// Returns:
// A Network object representing the channel
func (gw *Gateway) GetNetwork(name string) (*Network, error) {
var channelProvider context.ChannelProvider
channelProvider := gw.GetChannelProvider(name)
return newNetwork(gw, channelProvider)
}

// GetChannelProvider returns a ChannelProvider function.
// Parameters:
// name is the name of the network channel
//
// Returns:
// A function returning a Channel client context
func (gw *Gateway) GetChannelProvider(name string) context.ChannelProvider {
if gw.options.Identity != nil {
channelProvider = gw.sdk.ChannelContext(name, fabsdk.WithIdentity(gw.options.Identity), fabsdk.WithOrg(gw.org))
} else {
channelProvider = gw.sdk.ChannelContext(name, fabsdk.WithUser(gw.options.User), fabsdk.WithOrg(gw.org))
return gw.sdk.ChannelContext(name, fabsdk.WithIdentity(gw.options.Identity), fabsdk.WithOrg(gw.org))
}
return newNetwork(gw, channelProvider)
return gw.sdk.ChannelContext(name, fabsdk.WithUser(gw.options.User), fabsdk.WithOrg(gw.org))
}

// Close the gateway connection and all associated resources, including removing listeners attached to networks and
Expand Down

0 comments on commit d36373a

Please sign in to comment.