Auto Increment field in Composer

雨燕双飞 提交于 2019-12-02 15:22:01

问题


Is there any auto_increment field type is available when creating an Asset instance. For example, Asset id should be autogenerated field and should be created at runtime, instead of mentioning the value at the application level. I can achieve it by creating a transaction processor function to check the list of asset and add 1 to increment as an alternative.

Looking for new a feature which will help multiple developers while building an application.

Regards,

Pradeep P


回答1:


the best practice is to generate IDs client side, and send them in via the transaction. You can't for example, be certain that the transaction processor function would guarantee the same number (ID) each time when evaluated on endorsing peers that look at transaction proposals, let alone achieving the same deterministic value when it comes to sending the read/write (results) set back to the client application. The whole point is that the transaction proposal would yield the same asset ID EVERY time (as part of that - by putting it in a TP function, that would not be guaranteed EVERY time). Rather, you would send in the auto-increment value from the client side, for something that is ultimately, the responsibility of the client side.




回答2:


Also another description of why this isn't a good idea has been added to the issue you created, referencing here for completeness. https://github.com/hyperledger/composer/issues/2931



来源:https://stackoverflow.com/questions/47628303/auto-increment-field-in-composer

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