Getting timestamps in deterministic way in Hyperledger Composer transactions

落花浮王杯 提交于 2019-12-01 22:19:04

问题


Is there a deterministic way to get timestamp in transaction function, similar to stub.GetTxTimestamp() that can be used in Go version of Fabric's chaincode.


回答1:


Just sharing an example that works with basic-sample-network network:

In the model file (lib/org.acme.sample.cto) I extended SampleAsset definition any added new property called timestamp of type DateTime:

asset SampleAsset identified by assetId {
  o String assetId
  --> SampleParticipant owner
  o String value
  o DateTime timestamp
}

In the script file (lib/logic.js), the onSampleTransaction function to update SampleAsset's timestamp with current transaction's timestamp:

function onSampleTransaction(sampleTransaction) {
  sampleTransaction.asset.value = sampleTransaction.newValue;
  sampleTransaction.asset.timestamp = sampleTransaction.timestamp;
  return getAssetRegistry('org.acme.sample.SampleAsset')
       .then(function (assetRegistry) {
               return assetRegistry.update(sampleTransaction.asset);
        });
}



回答2:


All transactions have a system property called timestamp, so you can use myTransaction.timestamp.




回答3:


we cannot use the proto from the vendor folder ...

https://github.com/hyperledger-archives/fabric/issues/1832



来源:https://stackoverflow.com/questions/43656164/getting-timestamps-in-deterministic-way-in-hyperledger-composer-transactions

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