how to invoke chaincode function from itself to record sub transactions

最后都变了- 提交于 2019-12-23 03:22:15

问题


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'


回答1:


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



来源:https://stackoverflow.com/questions/47808793/how-to-invoke-chaincode-function-from-itself-to-record-sub-transactions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!