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

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的