Implement Amend clause in cordapp-template


(Alexandre Makiyama) #1

Dear all,

I intend to implement the Amend Clause in the PurchaseOrder example. What are the steps do I need to follow? I think it’s something like that:

  1. Add the Amend class in the Clauses interface (just uncomment the code that it’s already there);
  2. Add the Amend command in the Commands interface (just uncomment the code that it’s already there);
  3. Create a function, something like a generateAmend in the PurchaseOrderState data class;
  4. Create a new flow for Amend;
  5. Expose a new API, invoking the flow created.

Am I in the right way?

Thank you
Alexandre


(Roger Willis) #2

Hi Alexandre,

Looks like you are on the right track!

  1. Yes. Indeed! You will also have to change the Group clause to reference the newly created Amend clause.
  2. Yup. That should do it.
  3. You don’t have to but I feel it is good form abstract the transaction creation code away from the flow logic. generateAgreement is actually defined in the DealState interface, therefore it must be implemented. You’ll need to take the original PurchaseOrder state ref as input, a new PurchaseOrder state as output (with the amendments) and an Amend command with both CompositeKeys for the buyer and seller as parameters to the command.
  4. Yes. You’ll need two flows, one for the buyer and one for the seller (as with the original flow code included with the cordapp-template). You’ll find that much of the original flow code will be duplicated apart from the generateAmend part. Perhaps you can think about how to create a generalised flow which works both for placing purchase orders and amending purchase orders?
  5. That’s right.

Cheers

Roger


(Alexandre Makiyama) #3

Hi Roger,

Thanks for the reply! As soon as I implement the code, I’ll give you a feedback.

Alexandre


(Alexandre Makiyama) #4

Hi Roger,

For the purpose of testing, I’ve just done the following:

  1. Added this line to the Commands Interface:
    class Amend: TypeOnlyCommandData(), Commands

  2. Added the Amend() clause as a parameter to the AnyComposition(), in the GroupClauseVerifier

  3. Uncommented the Amend Clause

Just after that, I’ve tried to create a purchase order, as I did before these changes, and then I got these message:

java.lang.IllegalStateException: Required com.example.contract.PurchaseOrderContract.Commands.Amend command

Is there some other change that I need to do in order to the “purchase-order” flow work as before?

PS. I tried changing the verifyClause call too, from AllComposition to AnyComposition, but without success.


(Alexandre Makiyama) #5

I’ve just find out. I needed to override the requiredCommands val.

Thanks.


(Srinidhi) #7

" generateAgreement is actually defined in the DealState interface, therefore it must be implemented.You’ll need to take the original PurchaseOrder state ref as input, a new PurchaseOrder state as output (with the amendments) and an Amend command with both CompositeKeys for the buyer and seller as parameters to the command."

Could you pls elaborate where exactly this piece of implementation goes-in if we dont use generateAmend ?

I tried it in class Amend : Clause in contract class, As it overrides verify method, it is expecting a List of PurchaseOrders, not just the purchase order.


(Roger Willis) #8

Good job @amakiyama!

@srinidhi you can implement generateAmend() in the PurchaseOrderState, in fact you can add whatever helper methods you like to that class, or implement some extension functions, etc.