问题
How does Corda support parent-child relationship between states ( i.e. one parent state to many child states that serve different purposes ) One-To-Many Relationship. Currently I am only doing it by adding the reference number ( linear id ) of the parent state into each child states.
Elaboration:
The parent states consist of common information shared by each child states, While the child states would consist of information that is only relevant to itself. Each child would evolve or transition to different lifecycles independently, unless if an action is taken upon the parent state, i.e cancellation, early expiration, it would cascade to all the children states linked to the parent. Likewise, if all children states have evolved to their end of lifecycle i.e SETTLED, the parent must be able to collate and transition itself to SETTLED as well.
An example scenario would be a buyer who would issue a purchase contract with a seller, which also consists of different items. So in one purchase contract, there may be different products, and each to be shipped to different locations. But once all items have been shipped and accounted for (SETTLED), the purchase contract is only then SETTLED.
回答1:
Just reference the child states in the parent state by their linearId
, or vice-versa.
You can then impose rules in the contract - for example, you can require that a transaction marking a purchase contract as Settled
is also transferring all the items from the seller to the buyer.
Let me know if the use-case evolves and this model is no longer appropriate.
来源:https://stackoverflow.com/questions/48277289/how-does-corda-support-parent-child-relationship