在Hyperledger Composer事务中以确定性方式获取时间戳 [英] Getting timestamps in deterministic way in Hyperledger Composer transactions

查看:43
本文介绍了在Hyperledger Composer事务中以确定性方式获取时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有确定的方法来获取事务功能中的时间戳,类似于可以在Go版本的Fabric链码中使用的stub.GetTxTimestamp().

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.

推荐答案

只需共享一个适用于basic-sample-network网络的示例:

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

在模型文件(lib/org.acme.sample.cto)中,我扩展了SampleAsset定义,添加了名为DateTime类型的所有添加的新属性,称为timestamp:

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
}

在脚本文件(lib/logic.js)中,onSampleTransaction函数使用当前事务的时间戳更新SampleAsset的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);
        });
}

这篇关于在Hyperledger Composer事务中以确定性方式获取时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆