Blockchain 如何在链码中执行调用函数时返回事务id和时间戳?

Blockchain 如何在链码中执行调用函数时返回事务id和时间戳?,blockchain,hyperledger-fabric,Blockchain,Hyperledger Fabric,我需要在每次调用函数后在客户端接口上返回事务id和时间戳的指导 我发现stub.getXid()用于获取事务id,但peer.response只接受一个参数,因此我无法在客户端接口上返回TxID。您可以创建一个响应对象来捕获相关信息,将其封送到json并返回,类似这样: type ChaincodeResponse struct { txID string time *timestamp.Timestamp } 然后 // rest of the invoke co

我需要在每次调用函数后在客户端接口上返回事务id和时间戳的指导


我发现stub.getXid()用于获取事务id,但peer.response只接受一个参数,因此我无法在客户端接口上返回TxID。

您可以创建一个响应对象来捕获相关信息,将其封送到json并返回,类似这样:

 type ChaincodeResponse struct {
      txID string
      time *timestamp.Timestamp
 }
然后

// rest of the invoke code skipped, here is
// the relevant part:

resp, err := json.Marshal(ChaincodeResponse{
      txID: stub.GetTxID(),
      time: stub.GetTxTimestamp(),
})

// return json representation of relevant information
// in response
return shim.Success(resp)

您可以创建一个响应对象来捕获相关信息,将其封送到json并返回,如下所示:

 type ChaincodeResponse struct {
      txID string
      time *timestamp.Timestamp
 }
然后

// rest of the invoke code skipped, here is
// the relevant part:

resp, err := json.Marshal(ChaincodeResponse{
      txID: stub.GetTxID(),
      time: stub.GetTxTimestamp(),
})

// return json representation of relevant information
// in response
return shim.Success(resp)

我现在正在做一件事,要求我们所有的交易都有时间戳。我在上面代码的基础上尝试了一些东西,但我认为api自2017年以来已经有了很大的发展


目前,我正在添加一个
created:stub.GetTxTimestamp()
字段到我们放在分类账上的所有内容中,然后在以后的任何查询中读取它们。虽然我想知道时间戳是否已经生成和存储,因此这是不必要的-你知道时间戳是否仍然自动存储在分类账上的每个项目上吗?

我目前正在做一些事情,要求我们所有的交易都要有时间戳。我在上面代码的基础上尝试了一些东西,但我认为api自2017年以来已经有了很大的发展

目前,我正在添加一个
created:stub.GetTxTimestamp()
字段到我们放在分类账上的所有内容中,然后在以后的任何查询中读取它们。虽然我想知道时间戳是否已经生成并存储,因此不需要这样做-您知道时间戳是否仍然自动存储在分类账上的每个项目上吗