hyperledger-fabrichyperledger-chaincode

How to get list of channel member organizations in Hyperledger Fabric chaincode?


I am trying to implement a smart contract where a member of an organization can submit a proposal document (this is a simple text that will be recorded in the state), other orgs can vote on it (approve/reject), and if the majority have approved, the proposal gets accepted.

The documentation about transaction flow and the accepted answer here suggest that endorsement of transactions should not encode "business logic", i.e. a transaction that "plays by the rules" should get endorsed.

Therefore, I want to implement this approval/rejection process on the smart contract level. In this model the proposal, as well as each vote is a separate transaction. Then, the proposer can submit another transaction to count the votes and finalize the proposal.

For this, I need to get the list of organizations that are member of the channel. How can this be done within a smart contract's functions?


Solution

  • You would need to be able the chaincode smart contract to retrieve the latest configuration block from the peer/orderer and then parse that block to get the list of organizations.

    This means you'll need a way to send the private key of a client into the chaincode invocation.

    To send the private key of a client, it's better to have a dedicated MSP only for that client, so the MSP will be not included in any endorsement policies, or other channel config policies for security reasons.

    Then, to parse the config block you can follow the code here.

    Note that you cannot use a QSCC query inside a chaincode, although it is tempting to do so, because chaincode-to-chaincode invocations with QSCC are fobidden.