I am working on Nodejs chaincode on Fabric 2.1, when I tried to fetch the history for a key. It returns the "Timestamp" and "value" correctly, but the tx_id in the iterator is always undefined. has anyone successfully retrived the associated transaction ID ??
async getAllResults(iterator, isHistory) {
let allResults = [];
while (true) {
let res = await iterator.next();
if (res.value && res.value.value.toString()) {
let jsonRes = {};
console.log(res.value.toString('utf8'));
console.log(res.value.tx_id);
console.log(res.value.value.toString('utf8'));
logs:
dev-peer0.org1.example.com-mycc_7-7cd3dda|[object Object]
dev-peer0.org1.example.com-mycc_7-7cd3dda|undefined
dev-peer0.org1.example.com-mycc_7-7cd3dda|{"entityType":"product","model":"somemodel","name":"bike","newdata":"somedata","owner":"e7854d50-8793-449a-a903-d740d8d5952b","txDate":"Wed Jul 29 2020"}
At last i figured it out,
the iterator returns "txId" and not "tx_id"
correct way is
jsonRes.TxId = res.value.txId;
Apparently the code from https://github.com/hyperledger/fabric-samples/blob/master/chaincode/marbles02/javascript/marbles_chaincode.js has it wrong, or it is old and needs to be updated