[英]Debiting and crediting (changing) state data in Hyperledger Fabric
All examples for Hyperledger Fabric seem to focus on posting a new state that just overwrite the previous state of a record, for example owner A is replaced by owner B for car 1. Hyperledger Fabric 的所有示例似乎都集中在发布一个新的 state,它只是覆盖了以前的 state 记录,例如车主 A 被车主 B 替换为车 1。
I haven't found any example of "stateful" change of state though.不过,我还没有找到 state 的“有状态”更改的任何示例。 For example when we have a bank account record in the state, with a balance.例如,当我们在 state 中有一个银行账户记录时,有余额。 We would post a debit or credit transaction to the ledger that would need to read the current balance of the account, and decrease or increase it.我们会将借记或贷记交易发布到需要读取帐户当前余额并减少或增加它的分类帐。 This would possibly involve putting a lock on the account state record until the change is completed.这可能涉及锁定帐户 state 记录,直到更改完成。 Are there any examples of this, how can this be done properly in chaincode to ensure data consistency?有没有这方面的例子,如何在链码中正确完成以确保数据一致性?
Hyperledger Fabric has an example of bank-transfer-like here - high throughput Hyperledger Fabric 有一个类似银行转账的例子——高吞吐量
Because of the Read-Write set, we can not make a chaincode which modify the same key multiple times at the same time ([MVCC_READ_CONFLICT] error).由于读写集,我们不能创建一个链码同时多次修改同一个键([MVCC_READ_CONFLICT] 错误)。 You can read more about RW set here , or this article你可以在这里阅读更多关于 RW 集的信息,或者这篇文章
The key idea of this sample is that it makes a unique key with the same prefix for every transaction: varName~op~value~txID, where a transaction params include:该示例的关键思想是它为每个事务创建一个具有相同前缀的唯一键:varName~op~value~txID,其中事务参数包括:
After that, at the GET query phase, it uses GetStateByPartialCompositeKey()
function to get theses records which include the account in the key and then sum up to get the current balance of that account之后,在 GET 查询阶段,它使用GetStateByPartialCompositeKey()
function 来获取这些记录,其中包括 key 中的帐户,然后汇总得到该帐户的当前余额
Hope this can give you some ideas!希望这能给你一些想法!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.