Skip to content

Commit d0d5061

Browse files
Updated the AcceptanceFlow and added comments.
1 parent df6fcbd commit d0d5061

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

  • Advanced/negotiation-cordapp/workflows/src/main/java/net/corda/samples/negotiation/flows

Advanced/negotiation-cordapp/workflows/src/main/java/net/corda/samples/negotiation/flows/AcceptanceFlow.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import co.paralleluniverse.fibers.Suspendable;
44
import com.google.common.collect.ImmutableList;
55

6+
import net.corda.core.crypto.keyrotation.crossprovider.PartyIdentityResolver;
67
import net.corda.samples.negotiation.contracts.ProposalAndTradeContract;
78
import net.corda.samples.negotiation.states.ProposalState;
89
import net.corda.samples.negotiation.states.TradeState;
@@ -17,7 +18,6 @@
1718
import net.corda.core.transactions.LedgerTransaction;
1819
import net.corda.core.transactions.SignedTransaction;
1920
import net.corda.core.transactions.TransactionBuilder;
20-
import net.corda.core.utilities.ProgressTracker;
2121
import org.jetbrains.annotations.NotNull;
2222

2323
import 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,31 @@ 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+
//
70+
// The counterparty might be an old key, but the session will be initiated with the most up-to-date identity.
71+
// No need to use the resolved party in this case.
72+
Party proposer = PartyIdentityResolver.Companion.resolveToCurrentParty(input.getProposer(), getServiceHub().getIdentityService());
73+
Party counterparty = (getOurIdentity().equals(proposer))? input.getProposee() : input.getProposer();
6974
FlowSession counterpartySession = initiateFlow(counterparty);
7075
SignedTransaction fullyStx = subFlow(new CollectSignaturesFlow(partStx, ImmutableList.of(counterpartySession)));
7176

@@ -92,7 +97,10 @@ public SignedTransaction call() throws FlowException {
9297
protected void checkTransaction(@NotNull SignedTransaction stx) throws FlowException {
9398
try {
9499
LedgerTransaction ledgerTx = stx.toLedgerTransaction(getServiceHub(), false);
95-
Party proposee = ledgerTx.inputsOfType(ProposalState.class).get(0).getProposee();
100+
101+
// The proposee must be resolved to its latest identity before it can be compared with the party returned by `counterpartySession`.
102+
// `counterpartySession` always returns the most up-to-date identity of the counterparty.
103+
Party proposee = PartyIdentityResolver.Companion.resolveToCurrentParty(ledgerTx.inputsOfType(ProposalState.class).get(0).getProposee(), getServiceHub().getIdentityService());
96104
if(!proposee.equals(counterpartySession.getCounterparty())){
97105
throw new FlowException("Only the proposee can accept a proposal.");
98106
}

0 commit comments

Comments
 (0)