Retrieve Block number and Transaction Id from query to Hyperledger Fabric - couchdb

I'm new to hyperledger fabric and I'm trying to query a chaincode for a specific key. I can retrieve the json data for the key but I would also like to get the block number and transaction id related to the last PutState call which created/updated the data I'm retrieving from couchDB. Is there a way to do that?
Thanks in advance

Responding to help anyone who could have the same problem and to check if the solution I adopted makes any sense. So as I understand Hyperledger allows you to get the transaction id before your transaction is submitted to the blockchain wich I found peculiar after having worked with ethereum. Using golang me and my colleagues found this line:
txID := ctx.GetStub().GetTxID();
So our solution was to save the transaction id inside the data we are storing in the blockchain, to easily retrieve it by a simple query (to couchDB for example).
In the end we retrieved the informations bound to the txid by calling the "GetBlockByTxID" sc of the "qscc" chaincode (present by default in every channel of hyperledger as far as I understand) using the "fabric-network" node module, and decoded it using "fabric-common" node module's BlockDecoder:
result = BlockDecoder.decode(result)

Related

One chaincode, Multiple assets

I am trying to create a chaincode with different assets types.
Imagine that I have a chaincode where I store the users created and also the transactions where the users receive points.
How can I create a chaincode in a way that I am able to queryAllUsers and queryAllPointsTransactions? without using lists as it is available in this github https://github.com/IBM/customer-loyalty-program-hyperledger-fabric-VSCode
Because when using lists we have problems with multiple clients and with multiple transactions at the same time.
Does anyone can help me on this?
Thanks a lot!
PutState the asset separately from each key, and use the function below.
GetQueryResult
GetStateByRange

How to save query historial in Hyperledger Fabric

I need to save the query historial in Hyperledger Fabric, for example if I have a marble Object and I query it 2 times, I would like to retrieve the query historial. I already try call a query with PEER INVOKE and then use GetHistorialForKey function but it does not work because of the asset is not been modify
You'd have to turn your queries into invokes, which would result in them being subject to the rules of invoke and slowing them down.

Hyperledger fabric - Uploaded wrong set of transactions. Want these to be excluded in chaincode queries

We have set up a hyperledger fabric network and uploaded a history of transactions. Realized that part of these transactions are incorrect and hence we want to exclude them from chaincode queries.
From whatever I understand, the shim API DelState can be used to delete an asset from World state and hence this will not appear in chaincode queries.
But, we do not want to delete the entire asset. We just want to mark few transactions as invalid.

What will happen to old data if data structure changes in hyperledger fabric chaincode

What will happen to old data if data structure changes in hyperledger fabric chaincode? will it affect when we read old data from couchdb and translate it into object of new structure? Lets say I've added a new field and removed old field in the structure. what will be the impact of this change to old data?
CouchDb is a Nosql DB. You don't specify a schema to the records which would be created. The records are in the form of a Document. You can just relate a record in CouchDB as a JSON.
Would JSON ever get affected by adding/deleting a key?
No, it doesn't. It's just that the old records won't have that key which is being added to the new records. Therefore, you might not be able to retrieve old records only if you are filtering/querying the records with newly added key.
Hope this helps.

How to create a new block in bigchain db?

I'm using bigchain db in our project. Currently we are using transaction model to create assets and transfer it. But now we want to implement block model. When I go through the documentation I can't find how to create a block? Is there any specific url or any function or do we have to use same url as like for transaction model for example http://ourserver.com:8080/api/v1/ ? Can any one help me in this. Thank you.
As with Bitcoin, one submits a transaction to a BigchainDB network and then it's up to the network (i.e. the nodes in the network) to put that transaction in a block (or not, if the transaction is invalid).

Resources