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

我怎么知道,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.

  • 写回答

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.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图