首页 > 解决方案 > 无法使用 Corda 4.0 创建带有自身节点的 Corda 事务

问题描述

我想使用 corda 4.0 创建与 self 节点的事务。

我为此使用了示例 IOU 示例,并在 ExampleFlow 中添加了我的更改,如下面的代码所示。 https://github.com/corda/cordapp-example/tree/release-V4/java-source

但它不允许使用自身节点创建交易。

我也遵循/实施了这个Corda 4 - Single Party Transaction Failed to Commit to Ledger的答案

但它没有成功。

我只在 ExampleFlow 中进行了更改,如下所示/iOU 示例中的其余代码相同。

请帮忙。

@Suspendable
override fun call(): SignedTransaction {
// Obtain a reference to the notary we want to use.
val notary = serviceHub.networkMapCache.notaryIdentities[0]

// Stage 1.
progressTracker.currentStep = GENERATING_TRANSACTION
// Generate an unsigned transaction.
val iouState = IOUState(iouValue, serviceHub.myInfo.legalIdentities.first(), otherParty)
val txCommand = Command(IOUContract.Commands.Create(), listOf(ourIdentity.owningKey))
val txBuilder = TransactionBuilder(notary)
        .addOutputState(iouState, IOU_CONTRACT_ID)
        .addCommand(txCommand)

// Stage 2.
progressTracker.currentStep = VERIFYING_TRANSACTION
// Verify that the transaction is valid.
txBuilder.verify(serviceHub)

// Stage 3.
progressTracker.currentStep = SIGNING_TRANSACTION
// Sign the transaction.
val partSignedTx = serviceHub.signInitialTransaction(txBuilder)

// Stage 5.
progressTracker.currentStep = FINALISING_TRANSACTION
// Notarise and record the transaction in both parties' vaults.
return subFlow(FinalityFlow(partSignedTx,emptyList()))
}

标签: corda

解决方案


我认为问题是因为您在该州使用对方:

val iouState = IOUState(iouValue, serviceHub.myInfo.legalIdentities.first(), otherParty)

Corda 4 要求所有参与者 flowsession 必须在 中提供FinalityFlow,以便状态信息可以正确分发。

请参阅此处了解 我们未为以下交易参与者提供的更多流会话 - Corda 4


推荐阅读