chainHero / heroes-service

Short tutorial to build a blockchain application in Go with Hyperledger Fabric
https://chainhero.io/2018/06/tutorial-build-blockchain-app-v1-1-0/
Apache License 2.0
275 stars 147 forks source link

How can I list all of the peers in a channel? #10

Closed xuchenhao001 closed 6 years ago

xuchenhao001 commented 6 years ago

Thanks for your sample! That makes me easier to use fabric-go-sdk.(about join channel, install chaincode, instantiate, invoke and query) However, I want to build a more complex application through this SDK, for example, list all of the peers in a channel. How to do so? Thanks!

xuchenhao001 commented 6 years ago

@MaximeAubanel Thank you! but now my question is, when I instantiate my chaincode on a 2 orgs channel, the chaincode container just running for 1 org. And I have to do invoke to active another org's chaincode container. I think this is so odd. I have tried to sent instantiate proposal to all of the peers on a channel, but it says it needs MSP2 but not MSP1, and just built chincode containers for Org1, so that I can just instantiate peers in Org1 at one time. Any workaround for this? Thank you!

antitoine commented 6 years ago

Hi @xuchenhao001, It is possible to discover the peers that there are in a channel. However, this service is in an embryonic state. For this you need to use the Discovery Service of the SDK:

chClCtx, err := sdk.ChannelContext("Channel_ID", fabsdk.WithUser("User_ID"), fabsdk.WithOrg("Org_ID"))()
if err != nil {
    return nil, errors.WithMessage(err, "failed to get client channel context")
}
peers, err := chClCtx.DiscoveryService().GetPeers()

For your second point, you need to change your SDK context to instantiate the chaincode with the second organization.

I close this ticket as it is not related to the tutorial. But I invite you to communicate with the community on the chat: http://chat.hyperledger.org/