How to send a list of arguments to Chaincode? - hyperledger-fabric

I am working with the Hyperledger Fabric, I want to write a chaincode in go lang which takes list of arguments which contains a list in it.
For example: client will be calling chaincode function with parameters passed are [uname,job,[21,23,45]].
Can anyone help me in reading data in chaincode?

You can send them as ["uname","job","21","23","45"], and in chaincode you can store the arguments by assigning them to your asset.

Related

Hyperledger Fabric 2.2 - securing private data with collection-config

I have gone through documentation and I want to secure private data using GetTransient but I am not having idea that where to put collection-config.json.
If it is needed to be put under package root, then when should I pass it by flag --collections-config. As per documentation, it is suggested to pass for all three later methods - approveformyorg, checkcommitreadiness & commit. I could not get example for this (node chaincode example will be preferred).
Any help or direction, will be appreciated.
--collections-config is a flag on the peer lifecycle chaincode commands. It is independent of the chaincode package and chaincode language, the actual JSON file can reside anywhere as long as the flag specifies the location.
You can see an example in the private data tutorial.

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)

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

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.

Need specific chaincode for PDC(Private Data Collection)?

I am trying using PDC on hyperledger fabric for testing.
So then, I heard that PDC needs specific chaincode for itself, not exactly.
For using PDC, do it need something special chaincode only for PDC??
First of all, you need to make colletions_config.yaml file.
When you instantiate the chaincode, specify the flag --collections-config [path]
Chaincode Functions:
stub.GetPrivateData()
stub.PutPrivateData()
See this page
https://hyperledger-fabric.readthedocs.io/en/release-1.4/private_data_tutorial.html

Resources