33import co .paralleluniverse .fibers .Suspendable ;
44import com .google .common .collect .ImmutableList ;
55
6+ import net .corda .core .crypto .keyrotation .crossprovider .PartyIdentityResolver ;
67import net .corda .samples .negotiation .contracts .ProposalAndTradeContract ;
78import net .corda .samples .negotiation .states .ProposalState ;
89import net .corda .samples .negotiation .states .TradeState ;
1718import net .corda .core .transactions .LedgerTransaction ;
1819import net .corda .core .transactions .SignedTransaction ;
1920import net .corda .core .transactions .TransactionBuilder ;
20- import net .corda .core .utilities .ProgressTracker ;
2121import org .jetbrains .annotations .NotNull ;
2222
2323import java .security .PublicKey ;
@@ -31,7 +31,6 @@ public class AcceptanceFlow {
3131 public static class Initiator extends FlowLogic <SignedTransaction > {
3232
3333 private UniqueIdentifier proposalId ;
34- private ProgressTracker progressTracker = new ProgressTracker ();
3534
3635 public Initiator (UniqueIdentifier proposalId ) {
3736 this .proposalId = proposalId ;
@@ -47,25 +46,28 @@ public SignedTransaction call() throws FlowException {
4746
4847 ProposalState input = (ProposalState ) inputStateAndRef .getState ().getData ();
4948
50- //Creating the output
49+ // Creating the output
5150 TradeState output = new TradeState (input .getAmount (), input .getBuyer (), input .getSeller (), input .getLinearId ());
5251
53- //Creating the command
52+ // Creating the command
5453 List <PublicKey > requiredSigners = ImmutableList .of (input .getProposee ().getOwningKey (), input .getProposer ().getOwningKey ());
5554 Command command = new Command (new ProposalAndTradeContract .Commands .Accept (), requiredSigners );
5655
57- // Building the transaction
56+ // Building the transaction
5857 Party notary = inputStateAndRef .getState ().getNotary ();
5958 TransactionBuilder txBuilder = new TransactionBuilder (notary )
6059 .addInputState (inputStateAndRef )
6160 .addOutputState (output , ProposalAndTradeContract .ID )
6261 .addCommand (command );
6362
64- //Signing the transaction ourselves
63+ // Signing the transaction ourselves
6564 SignedTransaction partStx = getServiceHub ().signInitialTransaction (txBuilder );
6665
67- //Gathering the counterparty's signature
68- Party counterparty = (getOurIdentity ().equals (input .getProposer ()))? input .getProposee () : input .getProposer ();
66+ // Gathering the counterparty's signature
67+ //
68+ // The proposer must be resolved to its latest identity before it can be compared with the party returned by `getOurIdentity`.
69+ Party proposer = PartyIdentityResolver .Companion .resolveToCurrentParty (input .getProposer (), getServiceHub ().getIdentityService ());
70+ Party counterparty = (getOurIdentity ().equals (proposer ))? input .getProposee () : input .getProposer ();
6971 FlowSession counterpartySession = initiateFlow (counterparty );
7072 SignedTransaction fullyStx = subFlow (new CollectSignaturesFlow (partStx , ImmutableList .of (counterpartySession )));
7173
@@ -92,7 +94,10 @@ public SignedTransaction call() throws FlowException {
9294 protected void checkTransaction (@ NotNull SignedTransaction stx ) throws FlowException {
9395 try {
9496 LedgerTransaction ledgerTx = stx .toLedgerTransaction (getServiceHub (), false );
95- Party proposee = ledgerTx .inputsOfType (ProposalState .class ).get (0 ).getProposee ();
97+
98+ // The proposee must be resolved to its latest identity before it can be compared with the party returned by `counterpartySession`.
99+ // `counterpartySession` always returns the most up-to-date identity of the counterparty.
100+ Party proposee = PartyIdentityResolver .Companion .resolveToCurrentParty (ledgerTx .inputsOfType (ProposalState .class ).get (0 ).getProposee (), getServiceHub ().getIdentityService ());
96101 if (!proposee .equals (counterpartySession .getCounterparty ())){
97102 throw new FlowException ("Only the proposee can accept a proposal." );
98103 }
0 commit comments