如何从自身调用chaincode函数以记录子交易

We want to invoke one of the functions from go language chaincode itself. The reason for doing so is that we want to create separate transaction blocks for some logics based on flow.

For example, if we have a function named 'transferFund' and within that, we are reading balances of two persons (let it be a function named 'readBalance'). We want 3 blocks to be created: 1 for 'transferFund' and 2 for 'readBalance'

To invoke another chaincode within your chaincode you can use

stub.InvokeChaincode(chaincodeName, queryArgs, channelName)

where channelName can be empty if you want to call chaincode in the same channel.

source: https://github.com/hyperledger/fabric/blob/release/examples/chaincode/go/chaincode_example05/chaincode_example05.go#L90

However, I think that the call will not add a new transaction because the call of another code has to be validated and you could use the result of the call to change data on the ledger base on it. So everything will end up in 1 transaction.

Also be sure to differentiate between blocks and transactions.

Block

An ordered set of transactions that is cryptographically linked to the preceding block(s) on a channel.

Transaction

Invoke or instantiate results that are submitted for ordering, validation, and commit. Invokes are requests to read/write data from the ledger. Instantiate is a request to start and initialize a chaincode on a channel. Application clients gather invoke or instantiate responses from endorsing peers and package the results and endorsements into a transaction that is submitted for ordering, validation, and commit.

http://hyperledger-fabric.readthedocs.io/en/release/glossary.html