无法从ScheduledFlow启动与另一个节点的流会话 [英] Unable to initiate a flow session with another node from a ScheduledFlow

查看:29
本文介绍了无法从ScheduledFlow启动与另一个节点的流会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试与ScheduledFlow中的另一个节点启动流会话.以下是Scheduledstate的定义:

I am trying to initiate a flow session with another node from a ScheduledFlow. Below is the Scheduledstate definiton:

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的定义:

Below is the StartFlow definiton:

@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对象:

while testing the above flow, State object is created as follows:

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

StartFlow无法启动与对方的会话,并且代码卡在那里.

StartFlow is not able to initiate the session with counter party and the code gets stuck there.

如果国家被构建为

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

StartFlow能够发起与交易对手的会话,并且一切正常.

The StartFlow is able to initiate session with counterparty and everything works fine.

这里可能是什么问题?

推荐答案

据Nitesh报告,条件检查对于决定角色不正确. ourIdentity ==各方[0] 应该是 ourIdentity.owingkey ==各方[0] .owningkey .

As Nitesh reported, the condition check was incorrect for the deciding role. ourIdentity == parties[0] should have been ourIdentity.owingkey == parties[0].owningkey.

这是因为 parties [0] 的类型为 AbstractParty . ourIdentity 的类型为 Party . AbstractParty 覆盖 equals 如下:

This is because parties[0] is of type AbstractParty. ourIdentity is of type Party. AbstractParty overrides equals as follows:

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

因此这两个对象不相等.

Thus the two objects were not considered equal.

这篇关于无法从ScheduledFlow启动与另一个节点的流会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆