简体   繁体   English

Hyperledger Fabric 中的借记和贷记(更改)state 数据

[英]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,其中事务参数包括:

  • varName: account变量名称:帐户
  • op: + or - operator op:+ 或 - 运算符
  • value: transaction value价值:交易价值
  • txID: this will make the key unique 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.

相关问题 Hyperledger Fabric:重复值 - Hyperledger Fabric : duplicated values Hyperledger Fabric 中的读取(查询)交易流程 - Read (query) transaction flow in Hyperledger Fabric 通过hyperledger结构中的事务ID获取发件人证书 - get certificate of sender by a transaction id in hyperledger fabric Hyperledger-fabric 如何确认用户是网络中的有效用户? - How does Hyperledger-fabric confirms the user as a valid user in the network? 在Hyperledger Fabric中执行事务时出错 - Error while executing transactions in hyperledger fabric 如何使用Hyperledger Fabric Node SDK获取事务列表 - How to fetch list of transactions using hyperledger fabric node sdk 如果应用程序是用 Javascript 编写的,而 Chaincode 是用 Go 编写的,它会影响 Hyperledger Fabric 中的任何内容吗? - If application is written in Javascript and Chaincode is written in Go, will it affect anything in Hyperledger Fabric? Hyperledger Fabric:HLF 事务模型类中应该存在哪些所有字段? - Hyperledger Fabric: What all fields should be present in a HLF Transaction Model class? 所有对等节点是否都在 Hyperledger Fabric 中保留所有用户的公钥? - Does all peer node keeps all users public key in Hyperledger Fabric? Hyperledger Fabric:我可以使用什么工具/方法来获得 HLF 中所有类型交易的完整原始/JSON 可视化? - Hyperledger Fabric: tool/method that I can use in order to get a complete raw/JSON visualization of all types of transactions in HLF?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM