mirror of
https://github.com/corda/corda.git
synced 2025-06-06 09:21:47 +00:00
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:
parent
ae4513c8eb
commit
b316696360
@ -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
|
* 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.
|
* 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>() {
|
override val progressTracker: ProgressTracker = Primary.tracker()) : Primary<StateRef>() {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
internal val dealToFix: StateAndRef<FixableDealState> by TransientProperty {
|
internal val dealToFix: StateAndRef<FixableDealState> by TransientProperty {
|
||||||
@ -395,12 +396,6 @@ object TwoPartyDealProtocol {
|
|||||||
return serviceHub.keyManagementService.toKeyPair(publicKey)
|
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() =
|
override val notaryNode: NodeInfo get() =
|
||||||
serviceHub.networkMapCache.notaryNodes.filter { it.identity == dealToFix.state.notary }.single()
|
serviceHub.networkMapCache.notaryNodes.filter { it.identity == dealToFix.state.notary }.single()
|
||||||
}
|
}
|
||||||
@ -451,7 +446,7 @@ object TwoPartyDealProtocol {
|
|||||||
send(sortedParties[1], initation)
|
send(sortedParties[1], initation)
|
||||||
|
|
||||||
// Then start the other side of the fixing protocol.
|
// Then start the other side of the fixing protocol.
|
||||||
subProtocol(Floater(ref), inheritParentSessions = true)
|
subProtocol(Floater(sortedParties[1], ref), inheritParentSessions = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import com.r3corda.protocols.HandshakeMessage
|
|||||||
import com.r3corda.protocols.TwoPartyDealProtocol
|
import com.r3corda.protocols.TwoPartyDealProtocol
|
||||||
import com.r3corda.protocols.TwoPartyDealProtocol.Acceptor
|
import com.r3corda.protocols.TwoPartyDealProtocol.Acceptor
|
||||||
import com.r3corda.protocols.TwoPartyDealProtocol.DEAL_TOPIC
|
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
|
* 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) {
|
class Service(services: ServiceHubInternal) : AbstractNodeService(services) {
|
||||||
|
|
||||||
object DEALING : ProgressTracker.Step("Starting the deal protocol") {
|
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)
|
fun tracker() = ProgressTracker(DEALING)
|
||||||
@ -60,11 +61,10 @@ object AutoOfferProtocol {
|
|||||||
val progressTracker = tracker()
|
val progressTracker = tracker()
|
||||||
// Put the deal onto the ledger
|
// Put the deal onto the ledger
|
||||||
progressTracker.currentStep = DEALING
|
progressTracker.currentStep = DEALING
|
||||||
TwoPartyDealProtocol.Instigator(
|
Acceptor(
|
||||||
autoOfferMessage.replyToParty,
|
autoOfferMessage.replyToParty,
|
||||||
autoOfferMessage.notary,
|
autoOfferMessage.notary,
|
||||||
autoOfferMessage.dealBeingOffered,
|
autoOfferMessage.dealBeingOffered,
|
||||||
services.keyManagementService.freshKey(),
|
|
||||||
progressTracker.getChildProgressTracker(DEALING)!!
|
progressTracker.getChildProgressTracker(DEALING)!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ object AutoOfferProtocol {
|
|||||||
object RECEIVED : ProgressTracker.Step("Received API call")
|
object RECEIVED : ProgressTracker.Step("Received API call")
|
||||||
object ANNOUNCING : ProgressTracker.Step("Announcing to the peer node")
|
object ANNOUNCING : ProgressTracker.Step("Announcing to the peer node")
|
||||||
object DEALING : ProgressTracker.Step("Starting the deal protocol") {
|
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
|
// 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
|
progressTracker.currentStep = ANNOUNCING
|
||||||
send(otherParty, AutoOfferMessage(notary, dealToBeOffered, serviceHub.storageService.myLegalIdentity))
|
send(otherParty, AutoOfferMessage(notary, dealToBeOffered, serviceHub.storageService.myLegalIdentity))
|
||||||
progressTracker.currentStep = DEALING
|
progressTracker.currentStep = DEALING
|
||||||
val stx = subProtocol(
|
val instigator = Instigator(
|
||||||
Acceptor(otherParty, notary, dealToBeOffered, progressTracker.getChildProgressTracker(DEALING)!!),
|
otherParty,
|
||||||
inheritParentSessions = true)
|
notary,
|
||||||
|
dealToBeOffered,
|
||||||
|
serviceHub.keyManagementService.freshKey(),
|
||||||
|
progressTracker.getChildProgressTracker(DEALING)!!
|
||||||
|
)
|
||||||
|
val stx = subProtocol(instigator, inheritParentSessions = true)
|
||||||
return stx
|
return stx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user