Retrieving Data from Stream

+2 votes

Hello,

I am integrating Python and Django with Multichain using streams. What I am trying to achieve is the following:

  • 3 participants are involved in this process. One of the participants merely views the data on the stream as the process progresses.
  • Participant A initially fills in a web form with data. This data gets save to a stream. They will fill out, for example, 4 fields (4 keys). The entire dataset is about 12 keys and an attachment.
  • Participant B gets a notification that a new stream has been created. Participant B looks at the data on the stream and will add information to the stream. Once done, a separate workflow engine sees the data entry as complete and notifies Participant A.
  • Participant A reviews the data and may either accept the data as good, or enter into a "interaction loop" with Participant B back and forth with additional data. There is a point where the dataset is consider completed and marked as "complete".

Participant A and B may do this process for multiple data sets. However, each process needs to be grouped.

So, how I am going about this:

  • When the process starts, a new stream is created in the chain called "ParA_B_1". The naming structure is basically the ID of both participants and an integer that identifies this data exchange process. There can also exist ParA_B_2, ParA_B_3, ParA_B_4 and so on.
  • All data in the stream has the same key value (for example, the number 1) as a way of being able to group data in the stream. Ultimately, 12 entries with key 1 will exist.

The issue I am facing is that when these interactions (data entry into the stream with the same key) happens and when I retrieve data, even though I may have 20 records in the stream when I query the stream only the last series of inputs appears. 

My question is:

  • I am not understanding the technology and each interaction (or step in a workflow) must be assigned a key within the stream and use the stream as the container for the interaction? For example, in this 4 step process 3 pieces of data are captured per step. Should each step have their own key? i.e: Step 1 - Key 1, Step 2 - Key 2 or can I have a single key for all steps?

The idea of this application is to have these participants interact with data exchange while a 3rd independant participant can monitor the process and use the immutability of blockchain as to validate that all data entered during the process between both participants cannot be modified and is open to all parties involved in this data exchange or am I approaching this problem incorrectly?

Thanks,

asked Mar 20, 2017 by kuantize50

1 Answer

+2 votes

First, all the stream retrieval APIs have parameters that let you control how many items to retrieve, so getting the full history for a key on the stream will just be a matter of passing the right parameters.

Second, I think you might be better off using a single stream item for a single event. So if a form is entered with 10 fields, that can still be a single stream item. Just use the data field of the stream item to store all of the data together, in JSON/XML/etc format. You just need to convert that to and from hexadecimal when communicating with MultiChain.

answered Mar 20, 2017 by MultiChain
First of all, thanks for your patience with this. So, to summarize in my own use case. For simplicity, let's assume a 3 step process.

Step 1 - Participant A enters in 4 pieces of information of a total of 10. I take this information and save in the format of choice, all together, in a stream key item.
Step 2 - I retrieve the information from that stream key and show it to Participant B. This individual will add 4 more pieces of information in addition to the 4 retrieve. This 8 pieces of information get sent back to the stream in a new single stream key with all the information in format of choice.

(ad eternum)

So basically I become much more economical with the amount of stream keys that are created.

Understood. Thanks,
That's almost what I was suggesting :) I don't think there's much sense in participant B including A's data in their own stream item – what if participant B modifies the fields? Instead, each participant should just publish their own generated data in a single item.
I will try out that scenario. Thank you!
...