How to store only node specific off-ledger custom data in corda? - corda

I created custom table in corda using QueryableState. e.g. IOUStates table.
I can able to see the custom information getting stored in this kind of table.
but i observed that if party A and Party B is doing the transaction then this
custom information gets stored at both the places , e.g. IOUStates
table getting created at nodeA ledger as well as nodeB's ledger.
and custom information is stored in partyA's and PartyB's ledger.
My Question is :-
If some Transaction is getting processed from PartyA's node , then
I want to store part of the transaction's data i.e. custom data ONLY at partyA's Ledger.* level . i.e. off-Ledger of partA only.
It should not be shared with partyB.
In simple case , how to store Only node specific off ledger custom data ?
Awaiting for some reply...
Thanks.

There's a number of ways to achieve this:
Don't use Corda at all! If the data is truly off-ledger then why are you using Corda? Instead, store it in a separate database. Of course you can "JOIN" it with on-ledger data if required, as the on-ledger data is stored in a SQL database.
Similar to point one except you can use the jdbcSession() functionality of the ServiceHub to create a custom table in the node's database. This table can easily be accessed from within your flows.
Create a ContractState object that only has one participant: the node that wants to store the data. I call this a "unilateral" state, i.e. a state that only one party ever stores.
Most importantly, if you don't want to share some data with a counter-party then it should never be disclosed inside a corda state object or attachment that another party might see. Instead:
inside your flows, you can use the data encapsulated within the shared state object (e.g. the IOU) to derive the private data
alternatively if the data is supplied when the flow begins then store the private data locally using one of the methods above

Related

How to spend UTXO in corda

I learned how to create output state by corda.
However, I can't find documentation about how to consume those created outputs.
How can I specify outputs I want to consume as inputs in Flow code?
Usually it's like this:
Your state is a LinearState that has some UUID attribute as its linearId.
The flow that wants to consume that state has a constructor that takes as an input parameter that linearId.
Inside the flow you query the vault of the node to get that state by its linearId; the query returns a StateAndRef of your state.
You add that StateAndRef as an input to your transaction.
Let's say you're trying to update that state, so you add to the transaction an output; that output has the same value for linearId; but you can modify any other attribute. So this way you mimic an update, because states in Corda are final; so to update one, you consume it, then you create an output that has the same linearId but different values for the remaining attributes. This allows you to track the history of that state by its linearId.
This example shows the above steps, you'll see that the flow constructor takes the Id of the proposal, queries the vault for that proposal; then updates its amount by creating a new proposal with the same Id but different amount.

Symfony axios pass only id or entire object?

I have a Booking entity which has a ManyToOne relationship with my Car entity. I use axios to post my data for creating a Booking. I'm not sure if it's better practice to pass my whole Car object to my create function inside my Controller or to only pass the Car's id to the route of the function (which then fetches the Car from my database thanks to Symfonys param converter). Or is there another way which is considered "best practice"?
It depends on your scenario and the way you want to use.
Whenever you have to create an object / row inside the database then you will have to pass the whole object. assuming that the cars has already been created inside the database and you only have to link the booking object with the car than i will prefer you to bind it using ids rather than placing the whole object.
If you place the whole car object than it will increase the retrieval performance but if someday the information of car is changed than you will have to change the information on every booking object in which you placed the car object but if you just bind it with the Car Id than it will always give user the latest information even if the info of Car has been changed.
I thought that it will reduce the performance of the application if we used Id but that is not the case the DBMS use indexing to manage the search and search through id takes not time. It performance is not an issue and yes if you pass a whole object than it will also consume more data (since a large amount of data will be uploaded).

Fetch the process instances by passing the multiple business key[processBusinessKey] values

I have one process which has task and form fields. And I have one field "location" which I am considering as business key. For example, I have 2 locations as: India and UK. I want to fetch the process instances of these two locations. Means I need to pass the multiple business key values. Is it possible to pass the multiple business key values and fetch the process instances of these 2 business key values [multiple business key values]?
Thanks & Regards
Shilpa Kulkarni
There's no out of the box functionality for this. but you can always query process instances based on variable values. e.g. create a service which takes multiple keys as argument and query them separately with runtimeService.createProcessInstanceQuery().variableValueLike("location", "yourKey").list(); this will return all process instances with having location as yourKey entered.
An Activiti process instance can only have a single associated Business key. However you can retrieve a list of instaces based on a list of buisiness keys and other properties by using a process instance query.

to get data from table without using reference of state

am trying to get the value from db without using serviceHub and vault.but i couldn't. what my logic is, when i pass the country name, it should return the id's(PK)of that country which is in one table.using those id's, it should return the values related to those id's from other table.it could be possible in flow class.but am trying to do in api class where servicehub couldn't import. Please help me out.
Only the node has access to the ServiceHub. The API runs outside of the node in a separate process, so it is limited to interacting with the node via the operations offered by CordaRPCOps.
Either you need to store the data you want to access in a separate database outside of the node, or you need to find some way to programatically log into the node's database from the API, using JDBC as described here: https://docs.corda.net/node-database.html.

How to not generate unique ID when using push method in Firebase?

I'm trying to push new data into Firebase but it keeps generating an unique ID and an extra child node for me. How can I stop generating the ID and extra node or is there another way to push data into Firbase? My dataset is given and I just need to dump the dataset into the db. (But I'm slowly updating this given dataset.)
Firease always generates the unique id when using the push method. You can use it as a key or as a parent node. This post describes push in more detail.
https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html
You should use set to publish new data to firebase if push doesn't fit your use case. There is also an update method as set will overwrite any data in the given path.
https://firebase.google.com/docs/database/web/save-data
I generally use set for new data, or if I change how I have my data structured, or if I am appending new data in a path, update to make changes to fields for a dataset, and push for sets of data that I want organized in a list by time( i.e. Chat message log ).

Resources