问题描述
我们想从go语言链码本身调用其中一个功能.这样做的原因是,我们希望基于流为某些逻辑创建单独的事务块.
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.
例如,如果我们有一个名为" transferFund "的函数,并且在其中,我们正在读取两个人的余额(让它成为一个名为" readBalance "的函数).我们希望创建3个块:1个用于" transferFund ",另外2个用于" readBalance "
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)
如果要在同一通道中调用链码,则channelName
可以为空.
where channelName
can be empty if you want to call chaincode in the same channel.
但是,我认为该调用不会添加新的事务,因为必须验证另一个代码的调用,并且您可以使用该调用的结果在此基础上更改分类帐上的数据.因此,一切都会以1次交易结束.
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.
还要确保区分区块和交易.
一组有序交易,这些交易以密码方式链接到通道上的先前区块.
An ordered set of transactions that is cryptographically linked to the preceding block(s) on a channel.
交易
调用或实例化提交的结果以进行排序,验证和提交.调用是从分类帐读取/写入数据的请求.实例化是在通道上启动和初始化链码的请求.应用程序客户端从背书对等方收集调用或实例化响应,并将结果和背书打包到提交以进行订购,验证和提交的事务中.
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
这篇关于如何从自身调用chaincode函数以记录子交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!