One chaincode, Multiple assets - hyperledger-fabric

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

Related

Terra (LUNA) get list of transactions NodeJs

I research the Terra (LUNA) blockchain and use js library (#terra-money/terra.js). But I can't find the method for getting list of transactions.
How can I get transaction by wallet address using NodeJs?
you need to go via the FCD, there is a example from testnet:
https://bombay-fcd.terra.dev/v1/txs?offset=0&limit=100&account=<ACCOUNT>

Retrieve Block number and Transaction Id from query to Hyperledger Fabric

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)

Insights + Evaluating gRPC Message Flow Hyperledger Fabric

I want to examine the gRPC Message Flow from invoking a smart contract until a block is created:
I exactly want to examine these steps (the used message stream) I later found composed in a whole block (If I understand it right these parts are only put together at the end in a block some adds):
Invoke call of a Chaincode e.g. Change Value "a" to "10" in using CLI:
1. CLI sends Proposal to Endorser -> [SignedProposal with Signature, Proposal:(Header+Payload)]
2. Endorser sends Proposal Response back to CLI -> [ProposalResponse with its Endorsement,
PropRespPayload]
3. CLI packs endorsements into Transaction + sends them to orderer for block creation
4. Block is created by orderer + validation of sign.
What is the fastest way to fetch them?
What I did:
(Not good, rather laborious) Try to modificate code in binaries like "peer" where gRPC is handled, rebuild images:
My problem is that I am able to build and modificate the binaries like the peer executable (which is used in images and started inside a docker container like the peer), but I finally want to use them and make us of the sample projects like first-network, where I can invoke a transaction and log with own implementations what is gRPCed there. What I could do here and what is very time consuming is to rebuild all images and later make all sample files fitting to the new environement and implement this parts, but I think there have to be a faster way of evaluating the message flow (with the output of the full gRPC message stream /decoded and encoded).
(I think the best way for now):
I have not discovered faster ways yet (am new to Go and gRPC), instead of logging what gRPC is sending with wireshark and try to decode it (but it won't work for all parts, cause of incomplete messages or afraid). For some parts (proving sign) it is necessary that I have the marshalled version of some objects. This is what I need the most actually, but therefore I need to understand the gRPC content of the wiresharked parts :)
Do you have any suggestions for me? Would you rather go on with Way1 or Way2? Or am I on a too complicated way to fix it?
Is there a faster way existing? I mean I need the unmarshaled parts, but also the marshaled content of some objects and I have the proto files (when these are the correct ones for the logging parts I did in wireshark while an invoke was take place).
You can make your own gRPC api by following those simple steps:
1st you need to make a signed proposal. To make a signed proposal, you can get idea from endorser_test.go file.
To send a signed proposal to peer for endorsement, you need a ProcessProposal gRPC call where you can get the response from endorsing peer and your need to create a EndorserClient too.
After that you need to collect all endorsements from peers and have to make signed envelope
To make a signed envelope, you can take help from txutils.go file
To send a signed envelope to orderers you need to broadcast your envelope to orderers with Send gRPC call where we need to create a AtomicBroadcastClient.
This seems closely related to the question you posted a month or so ago.
As you point out, if you wish to do things like validate signatures, you will need the marshaled form of the messages, but if you wish to inspect the messages, you will need to unmarshal them.
I would think that option 1 (modifying the code to dump the information you need) is still the most useful. As you can perform whatever serialization, persistence, or analysis inside the code itself. If you simply store these data structures to disk via something like wire-shark, then you will need to track them, parse them, etc., which seems like more work to me.
If you have marshaled messages on disk, you can try using a tool like configtxlator to unmarshal the messages to a more friendly JSON format, if you have tracked the appropriate type, though this still seems more difficult than simply injecting code to me.

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.

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