Невозможно инициировать сеанс потока с другим узлом из ScheduledFlow - PullRequest
0 голосов
/ 26 октября 2018

Я пытаюсь инициировать сеанс потока с другим узлом из ScheduledFlow.Ниже приведено определение запланированного состояния:

data class State(val a: Party,
                         val b: Party,
                         val instant: Instant,
                          val status: Status,
                          override val linearId: UniqueIdentifier = UniqueIdentifier(),
                          override val participants: List<AbstractParty> = listOf(a, b))
: LinearState, SchedulableState {

private val scheduledTime = instant
override fun nextScheduledActivity(thisStateRef: StateRef, flowLogicRefFactory: FlowLogicRefFactory): ScheduledActivity? {
    if (status != Status.COMPLETED) {
        return null
    } else {
        return ScheduledActivity(flowLogicRefFactory.create("com.example.flows.StartFlow", thisStateRef), scheduledTime)
    }
}}

Ниже приведено определение StartFlow:

@InitiatingFlow
@SchedulableFlow
class StartFlow(val ref: StateRef): FlowLogic<SignedTransaction?>(){

    @Suspendable
    override fun call(): SignedTransaction? {
        val notary = serviceHub.networkMapCache.notaryIdentities[0]
        val stateAndRef = serviceHub.loadState(stateRef = ref)
        val state = stateAndRef.data as State
        if (state.status != State.COMPLETED) {
            throw IllegalArgumentException("Cannot initiate transfer of ownership")
        }

        // Role decider:
        val parties = state.participants.sortedBy { it.owningKey.toBase58String() }
        if (ourIdentity == parties[0]) {
            val tx = TransactionBuilder(notary = notary)

            // add input states
            tx.addInputState(stateAndRef)

            // add output states
            tx.addOutputState(state.copy(status = Status.TRANSFERRED), ContractA.CONTRACT_ID)
            val command = Command(ContractA.Commands.Command1(), listOf(state.a.owningKey, state.b.owningKey))
            tx.addCommand(command)

            tx.verify(serviceHub)

            val partSignedTx = serviceHub.signInitialTransaction(tx)
            val counterparty = serviceHub.identityService.wellKnownPartyFromAnonymous(parties[1]) ?: throw IllegalStateException("Cannot resolve responding party")
            val counterPartySession = initiateFlow(counterparty)
            val fullySignedTx = subFlow(CollectSignaturesFlow(partSignedTx, setOf(counterPartySession)))

            return subFlow(FinalityFlow(fullySignedTx))
        }
        return null
    }
}

при тестировании вышеуказанного потока объект состояния создается следующим образом:

State(a, b, Instant.now().plus(10), Status.COMPLETED)

StartFlow не может инициировать сеанс с контрагентом, и код застревает там.

Если состояние построено как

State(a, b, Instant.now(), Status.COMPLETED)

StartFlow может инициировать сеанс с контрагентоми все работает отлично.

В чем здесь проблема?

1 Ответ

0 голосов
/ 30 октября 2018

Как сообщил Нитеш, проверка состояния была неверной для определяющей роли.ourIdentity == parties[0] должно было быть ourIdentity.owingkey == parties[0].owningkey.

Это потому, что parties[0] имеет тип AbstractParty.ourIdentity имеет тип Party.AbstractParty переопределяет equals следующим образом:

override fun equals(other: Any?): Boolean = 
    other === this || 
    other is AbstractParty && other.owningKey == owningKey

Таким образом, два объекта не считались равными.

...