Switched the roles of Instigator and Acceptor in the auto-offer protocol so that they're correctly used according to the classes they inherit

This commit is contained in:
Shams Asari 2016-09-19 12:39:38 +01:00
parent ae4513c8eb
commit b316696360
2 changed files with 15 additions and 15 deletions

View File

@ -381,7 +381,8 @@ object TwoPartyDealProtocol {
* is just the "side" of the protocol run by the party with the floating leg as a way of deciding who
* does what in the protocol.
*/
class Floater(override val payload: StateRef,
class Floater(override val otherParty: Party,
override val payload: StateRef,
override val progressTracker: ProgressTracker = Primary.tracker()) : Primary<StateRef>() {
@Suppress("UNCHECKED_CAST")
internal val dealToFix: StateAndRef<FixableDealState> by TransientProperty {
@ -395,12 +396,6 @@ object TwoPartyDealProtocol {
return serviceHub.keyManagementService.toKeyPair(publicKey)
}
override val otherParty: Party get() {
// TODO otherParty is sortedParties[1] from FixingRoleDecider.call and so can be passed in as a c'tor param
val myName = serviceHub.storageService.myLegalIdentity.name
return dealToFix.state.data.parties.filter { it.name != myName }.single()
}
override val notaryNode: NodeInfo get() =
serviceHub.networkMapCache.notaryNodes.filter { it.identity == dealToFix.state.notary }.single()
}
@ -451,7 +446,7 @@ object TwoPartyDealProtocol {
send(sortedParties[1], initation)
// Then start the other side of the fixing protocol.
subProtocol(Floater(ref), inheritParentSessions = true)
subProtocol(Floater(sortedParties[1], ref), inheritParentSessions = true)
}
}
}

View File

@ -15,6 +15,7 @@ import com.r3corda.protocols.HandshakeMessage
import com.r3corda.protocols.TwoPartyDealProtocol
import com.r3corda.protocols.TwoPartyDealProtocol.Acceptor
import com.r3corda.protocols.TwoPartyDealProtocol.DEAL_TOPIC
import com.r3corda.protocols.TwoPartyDealProtocol.Instigator
/**
* This whole class is really part of a demo just to initiate the agreement of a deal with a simple
@ -40,7 +41,7 @@ object AutoOfferProtocol {
class Service(services: ServiceHubInternal) : AbstractNodeService(services) {
object DEALING : ProgressTracker.Step("Starting the deal protocol") {
override fun childProgressTracker(): ProgressTracker = TwoPartyDealProtocol.Primary.tracker()
override fun childProgressTracker(): ProgressTracker = TwoPartyDealProtocol.Secondary.tracker()
}
fun tracker() = ProgressTracker(DEALING)
@ -60,11 +61,10 @@ object AutoOfferProtocol {
val progressTracker = tracker()
// Put the deal onto the ledger
progressTracker.currentStep = DEALING
TwoPartyDealProtocol.Instigator(
Acceptor(
autoOfferMessage.replyToParty,
autoOfferMessage.notary,
autoOfferMessage.dealBeingOffered,
services.keyManagementService.freshKey(),
progressTracker.getChildProgressTracker(DEALING)!!
)
}
@ -78,7 +78,7 @@ object AutoOfferProtocol {
object RECEIVED : ProgressTracker.Step("Received API call")
object ANNOUNCING : ProgressTracker.Step("Announcing to the peer node")
object DEALING : ProgressTracker.Step("Starting the deal protocol") {
override fun childProgressTracker(): ProgressTracker = TwoPartyDealProtocol.Secondary.tracker()
override fun childProgressTracker(): ProgressTracker = TwoPartyDealProtocol.Primary.tracker()
}
// We vend a progress tracker that already knows there's going to be a TwoPartyTradingProtocol involved at some
@ -103,9 +103,14 @@ object AutoOfferProtocol {
progressTracker.currentStep = ANNOUNCING
send(otherParty, AutoOfferMessage(notary, dealToBeOffered, serviceHub.storageService.myLegalIdentity))
progressTracker.currentStep = DEALING
val stx = subProtocol(
Acceptor(otherParty, notary, dealToBeOffered, progressTracker.getChildProgressTracker(DEALING)!!),
inheritParentSessions = true)
val instigator = Instigator(
otherParty,
notary,
dealToBeOffered,
serviceHub.keyManagementService.freshKey(),
progressTracker.getChildProgressTracker(DEALING)!!
)
val stx = subProtocol(instigator, inheritParentSessions = true)
return stx
}