How to get the data stored in the ledger via TxnID in fabric-sdk-go?

767 Views Asked by At

I have stored a data let's say ABC in the Ledger and got X123 as a Transaction hash in response. Now, I want to use this transaction hash X123 to fetch the data ABC from the ledger. I found this package which provides the method QueryTransaction(txn_hash) and states that QueryTransaction queries the ledger for processed transaction by transaction ID

My questions are:

  1. Is this a correct method to do the above operation? If no, Please suggest some methods.
  2. If yes, Do I have to use some parsing logic to correctly format it?

  3. Do we have parsing logic or decoder in go-sdk like BlockDecoder is there in node-sdk?

the screenshot of the response that I'm getting using this method.

QueryTransaction response

1

There are 1 best solutions below

0
On

Download the fabric sample from https://github.com/hyperledger/fabric-samples

Q1: In the Balance Transfer project. At the bottom of the app.js, all methods are already implemented.

  1. Query Get Block by BlockNumber
  2. Query Get Transaction by Transaction ID
  3. Query Get Block by Hash
  4. The query for Channel Information
  5. The query for Channel instantiated chaincodes
  6. Query to fetch all Installed/instantiated chaincodes
  7. Query to fetch channels

All the functions are defined in Query.js, please refer to this project.

Q2: All requested data will be coming as JSON, so no need to parse.

Q3: Even fF you want to decode any .pb file, you a use configtxlator tool, Please make sure that you have configtxlater binary available. For decoding .pb file use following command For Envelope

configtxlator proto_decode --input your_file.pb --type common.Envelope

For Block file

configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config.json