-1

In a hyperledger fabric network with multiple peers in an organization, Can I use Go SDK to query the chaincode through targetted peers from a particular organization?

I know I can query the chaincode using the channel package with the *channel.Client Query() function, however, I need to query through each peer individually.

Captain Levi
  • 804
  • 7
  • 18
James
  • 97
  • 1
  • 1
  • 5

1 Answers1

0

The way pass the targetted peers in Query call on channel client is by using the channel.WithTargetEndpoints() as a options parameter to the Query function.

An example to demonstrate this is:

req := channel.Request{
        ChaincodeID: chaincodeID,
        Fcn:         "invoke",
        Args:        queryArg,
    }

resp, err := client.Query(req, channel.WithTargetEndpoints("peer0.org0.example.com"), channel.WithRetry(retry.DefaultChannelOpts))

Captain Levi
  • 804
  • 7
  • 18
  • Thank You, how do I get an instance of a client to represent my channel? – James Feb 27 '19 at 14:50
  • Basically you create a channelClientContext like `channelClientCtx := sdk.ChannelContext(channelID, fabsdk.WithUser("Admin"), fabsdk.WithOrg(orgName))` and use that to generate client like `channelClient, err := channel.New(channelClientCtx)` . Also, If this helped you, Would you mind accepting this answer? It might help people experiencing a similar issue and will help getting your question noticed. For more information, take a look at our [FAQ](https://stackoverflow.com/help/accepted-answer). Thanks and welcome to SO! – Captain Levi Feb 27 '19 at 18:24
  • Thank you, have you got any resources where I can learn to use the go sdk? – James Mar 08 '19 at 11:55
  • You're welcome, No man, There isn't a guide. however, github [docs](https://github.com/hyperledger/fabric-sdk-go/) is very well documented. That's how I learned most of what I know. – Captain Levi Mar 08 '19 at 14:11
  • Okay, I've been reading and I'm getting there. So I've written a basic go application to query each of the ledgers. My network is in docker containers, where can I run my go application from to query it? – James Mar 11 '19 at 15:45
  • I keep getting this error when trying to declare var mainSDK *fabsdk.FabricSDK .go:227:23: not enough arguments in call to s.statsd.SendLoop have (<-chan time.Time, string, string) want (context.Context, <-chan time.Time, string, string) – James Mar 11 '19 at 16:34