Auto Increment field in Composer

2019-03-06 11:35发布

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

2条回答
来,给爷笑一个
2楼-- · 2019-03-06 12:16

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

查看更多
Luminary・发光体
3楼-- · 2019-03-06 12:33

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.

查看更多
登录 后发表回答