22
33import co .paralleluniverse .fibers .Suspendable ;
44import com .r3 .corda .lib .tokens .contracts .types .TokenPointer ;
5+ import com .r3 .corda .lib .tokens .workflows .flows .move .MoveTokensUtilities ;
56import com .r3 .corda .lib .tokens .workflows .flows .rpc .MoveNonFungibleTokens ;
67import com .r3 .corda .lib .tokens .workflows .flows .rpc .MoveNonFungibleTokensHandler ;
8+ import com .r3 .corda .lib .tokens .workflows .internal .flows .distribution .UpdateDistributionListFlow ;
9+ import com .r3 .corda .lib .tokens .workflows .internal .flows .finality .ObserverAwareFinalityFlow ;
710import com .r3 .corda .lib .tokens .workflows .types .PartyAndToken ;
11+ import com .r3 .corda .lib .tokens .workflows .utilities .NotaryUtilities ;
12+ import net .corda .core .transactions .TransactionBuilder ;
813import net .corda .examples .bikemarket .states .FrameTokenState ;
914import net .corda .examples .bikemarket .states .WheelsTokenState ;
1015import net .corda .core .contracts .StateAndRef ;
1116import net .corda .core .flows .*;
1217import net .corda .core .identity .Party ;
1318import net .corda .core .transactions .SignedTransaction ;
1419
20+ import java .util .Collections ;
21+
1522public class TransferPartTokens {
1623
1724 public TransferPartTokens () {
@@ -52,11 +59,20 @@ public String call() throws FlowException {
5259
5360 //get the pointer to the frame
5461 TokenPointer frametokenPointer = frametokentype .toPointer (frametokentype .getClass ());
55- PartyAndToken partyAndFrameToken = new PartyAndToken (holder , frametokenPointer );
5662
57- SignedTransaction stx = (SignedTransaction ) subFlow (new MoveNonFungibleTokens (partyAndFrameToken ));
63+ FlowSession sellerSession = initiateFlow (holder );
64+ TransactionBuilder txBuilder = new TransactionBuilder (NotaryUtilities .getPreferredNotary (getServiceHub ()));
65+ MoveTokensUtilities .addMoveNonFungibleTokens (txBuilder , getServiceHub (), frametokenPointer , holder );
66+
67+ SignedTransaction ptx = getServiceHub ().signInitialTransaction (txBuilder );
68+ SignedTransaction stx = subFlow (new CollectSignaturesFlow (ptx , Collections .singletonList (sellerSession )));
69+
70+ // Update the distribution list
71+ subFlow (new UpdateDistributionListFlow (stx ));
72+ SignedTransaction ftx = subFlow (new ObserverAwareFinalityFlow (stx , Collections .singletonList (sellerSession )));
73+
5874 return "Transfer ownership of the frame (" +this .frameModel +") to" +this .holder .getName ().getOrganisation ()
59- + "\n Transaction ID: " + stx .getId ();
75+ + "\n Transaction ID: " + ftx .getId ();
6076
6177 } else {
6278 //Step 2: Wheels Token
@@ -70,11 +86,18 @@ public String call() throws FlowException {
7086
7187 //get the pointer to the wheel
7288 TokenPointer wheeltokenPointer = wheeltokentype .toPointer (wheeltokentype .getClass ());
73- PartyAndToken partyAndWheelToken = new PartyAndToken (holder , wheeltokenPointer );
89+ FlowSession sellerSession = initiateFlow (holder );
90+ TransactionBuilder txBuilder = new TransactionBuilder (NotaryUtilities .getPreferredNotary (getServiceHub ()));
91+ MoveTokensUtilities .addMoveNonFungibleTokens (txBuilder , getServiceHub (), wheeltokenPointer , holder );
92+
93+ SignedTransaction ptx = getServiceHub ().signInitialTransaction (txBuilder );
94+ SignedTransaction stx = subFlow (new CollectSignaturesFlow (ptx , Collections .singletonList (sellerSession )));
7495
75- SignedTransaction stx = (SignedTransaction ) subFlow (new MoveNonFungibleTokens (partyAndWheelToken ));
96+ // Update the distribution list
97+ subFlow (new UpdateDistributionListFlow (stx ));
98+ SignedTransaction ftx = subFlow (new ObserverAwareFinalityFlow (stx , Collections .singletonList (sellerSession )));
7699 return "Transfer ownership of the wheels (" +this .wheelModel +") to" +this .holder .getName ().getOrganisation ()
77- + "\n Transaction ID: " + stx .getId ();
100+ + "\n Transaction ID: " + ftx .getId ();
78101 }
79102 }
80103 }
0 commit comments