douxian8883
2019-07-09 00:50
浏览 133
已采纳

我怎么知道,Hyperledger Fabric中的事务进行了哪个Peer?

I am working on getting a transaction id info, which will give the peer details for the transaction. Currently, I am able to retrieve the History for a key, which gives me the list of transaction committed to that key.

MyCode:

historyRes, err := stub.GetHistoryForKey(userNameIndexKey)

if err != nil {
    return shim.Error(fmt.Sprintf("Unable to get History key from the ledger: %v", err))
}

for historyRes.HasNext() {

    history, errIt := historyRes.Next()

    if errIt != nil {
        return shim.Error(fmt.Sprintf("Unable to retrieve history in the ledger: %v", errIt))
    }

    deleted := history.GetIsDelete()

    ds := strconv.FormatBool(deleted)

    fmt.Println("History TxId = "+history.GetTxId()+" --  Delete = "+ds)
 }

Output

History TxId = 78c8d17c668d7a9df8373fd85df4fc398388976a1c642753bbf73abc5c648dd8 -- Deleted = false

History TxId = 102bbb64a7ca93367334a8c98f1f7be17e6a8d5277f0167c73da47072d302fa3 -- Deleted = true

But I don't know, which peer did this transaction. Is there any API available in fabric-sdk-go to retrieve peer info for a transaction id.

please suggest me some solution.

图片转代码服务由CSDN问答提供 功能建议

我正在获取交易ID信息,该信息将提供交易的对等方详细信息。 目前,我可以检索某个密钥的历史记录,从而获得了提交给该密钥的事务列表。

MyCode: \ n

  historyRes,err:= stub.GetHistoryForKey(userNameIndexKey)
 
if err!= nil {
返回shim.Error(fmt.Sprintf(“无法从分类帐中获取历史记录密钥:  %v“,err))
} 
 
 for historyRes.HasNext(){
 
 history,errIt:= historyRes.Next()
 
 if errIt!= nil {
返回shim.Error  (fmt.Sprintf(“无法在分类帐中检索历史:%v”,errIt))
} 
 
已删除:= history.GetIsDelete()
 
 ds:= strconv.FormatBool(已删除)\  n 
 fmt.Println(“ H​​istory TxId =” + history.GetTxId()+“-删除=” + ds)
} 
   
 
 

输出

 历史记录TxId = 78c8d17c668d7a9df8373fd85df4fc398388976a1c642753bbf73abc5c648dd8-已删除= false 
 
历史记录TxId = 102bbb64a7ca93367334a8cdaf17c7d7c7d7a7d7a7d7a7d7c7f7d7c7d7e7d7c7d7e7e7c7d7e7e7e7e7e7e7e7e7e7c7d7e7e7c7e7e7c7d7e7b0c7d7e7c7d7b7c7b7b0bc7d7b7b0bd7c7d7b7b0bd7c7b7b7b0bd7c7b7b0bd7b0cb7b0bbcbbfbfbfbfbf人的人 > 
 
 

但是我不知道 现在,哪个同行进行了此交易。 fabric-sdk-go 中是否有可用的API来检索交易ID的对等信息。

请提出一些解决方案。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • doupu1727 2019-07-09 15:17
    最佳回答

    The call stub.GetHistoryForKey(userNameIndexKey) will query the state database and not the ledger (channel). The information about the identity who made the transaction is stored in the block.

    I have implemented the same thing with NodeJS SDK. However, Go SDK too contains similar API calls. The following steps worked for me:

    1. Using your SDK, get the transactionId
    2. Use the SDK function for querying block by transactionId. References here.
    3. At this step, you'll get the block. Now the identity of the submitter is located within this block. Hints: Payload -> Header -> Signature Header -> Creater -> IdBytes.
    4. These identity bytes are the X509 certs of the submitter. You can read the certificate info to find out which member did submit this transaction. The subject and OUs will indicate the Organization of the peer that did the transaction.
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题