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

Commit 4462385

Browse files
committed
feat: expose ChannelProvider from the gateway
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 <[email protected]>
1 parent 965abe3 commit 4462385

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pkg/gateway/gateway.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,22 @@ func WithBlockNum(from uint64) Option {
259259
// Returns:
260260
// A Network object representing the channel
261261
func (gw *Gateway) GetNetwork(name string) (*Network, error) {
262-
var channelProvider context.ChannelProvider
262+
channelProvider := gw.GetChannelProvider(name)
263+
return newNetwork(gw, channelProvider)
264+
}
265+
266+
// GetChannelProvider returns a ChannelProvider function.
267+
// Parameters:
268+
// name is the name of the network channel
269+
//
270+
// Returns:
271+
// A function returning a Channel client context
272+
func (gw *Gateway) GetChannelProvider(name string) context.ChannelProvider {
263273
if gw.options.Identity != nil {
264-
channelProvider = gw.sdk.ChannelContext(name, fabsdk.WithIdentity(gw.options.Identity), fabsdk.WithOrg(gw.org))
274+
return gw.sdk.ChannelContext(name, fabsdk.WithIdentity(gw.options.Identity), fabsdk.WithOrg(gw.org))
265275
} else {
266-
channelProvider = gw.sdk.ChannelContext(name, fabsdk.WithUser(gw.options.User), fabsdk.WithOrg(gw.org))
276+
return gw.sdk.ChannelContext(name, fabsdk.WithUser(gw.options.User), fabsdk.WithOrg(gw.org))
267277
}
268-
return newNetwork(gw, channelProvider)
269278
}
270279

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

0 commit comments

Comments
 (0)