【问题标题】:Cannot find contract attachment for flow找不到流量的合同附件
【发布时间】:2019-08-27 23:07:00
【问题描述】:

将 corda 升级到版本 4 后,我收到 net.corda.core.transactions.MissingContractAttachments: Cannot find contract attachments for com.template.contract.ServiceContractnull。

此流程在本地工作,但在部署到 Azure 时会引发错误消息。

我有

  • 检查了我所有的 cordapps 都位于 /opt/corda/cordapps -folder

  • 我的合同 ID 是“com.template.contract.ServiceContract”

  • 我没有运行任何测试

我尝试更改 SERVICE_CONTRACT_ID="com.template.contract" 但这也没有用

创建服务流

@InitiatingFlow
@StartableByRPC
class CreateServiceFlow(val serviceState: ServiceState) : FlowLogic<SignedTransaction>() {
    override val progressTracker = ProgressTracker()
    @Suspendable
    override fun call(): SignedTransaction {

        serviceHub.vaultService.queryBy<ServiceState>().states.forEach{
            if (it.state.data.serviceName == serviceState.serviceName) {
                throw Exception("There can be only one ${serviceState.serviceName} service per service " +
                    "provider")
            }
        }

        val notary = serviceHub.networkMapCache.notaryIdentities.first()

        val serviceCommand = Command(
            ServiceContract.Commands.IssueService(),
            serviceState.participants.map { it.owningKey }
        )

        val builder = TransactionBuilder(notary = notary)
            .addOutputState(serviceState, ServiceContract.SERVICE_CONTRACT_ID,
                constraint = AlwaysAcceptAttachmentConstraint)
            .addCommand(serviceCommand)

        builder.verify(serviceHub)

        val partSignedTx = serviceHub.signInitialTransaction(builder)

        val otherPartySession = initiateFlow(serviceState.accountOperator)

        val fullySignedTx = subFlow(CollectSignaturesFlow(partSignedTx, setOf(otherPartySession)))


        return subFlow(FinalityFlow(fullySignedTx, setOf(otherPartySession)))
    }
}

@InitiatedBy(CreateServiceFlow::class)
class IssueServiceResponder(val otherPartySession: FlowSession) : FlowLogic<SignedTransaction>() {
    @Suspendable
    override fun call(): SignedTransaction {
        val signTransactionFlow = object : SignTransactionFlow(otherPartySession) {
            override fun checkTransaction(stx: SignedTransaction) = requireThat {
                "there should be no inputs" using(stx.inputs.isEmpty())
                "there should be one output" using(stx.tx.outputStates.size == 1)
                "The state should serviceState" using(stx.tx.outputStates.single() is ServiceState)
            }
        }
        val txId = subFlow(signTransactionFlow).id
        return subFlow(ReceiveFinalityFlow(otherPartySession, expectedTxId = txId))
    }
}

服务合同

package com.template.contract

@LegalProseReference(uri = "<prose_contract_uri>")
class ServiceContract : Contract {
    companion object {
        @JvmStatic
        val SERVICE_CONTRACT_ID = "com.template.contract.ServiceContract"
    }

    val legalContractReference: SecureHash
        get() = SecureHash.randomSHA256()

    interface Commands : CommandData {
        class IssueService : TypeOnlyCommandData(), ServiceContract.Commands
        class AddServiceData : TypeOnlyCommandData(), ServiceContract.Commands
        class AddPartner: TypeOnlyCommandData(), ServiceContract.Commands
        class RemovePartner: TypeOnlyCommandData(), ServiceContract.Commands
        class ExitService : TypeOnlyCommandData(), ServiceContract.Commands
    }

    override fun verify(tx: LedgerTransaction) {....
}

向远程节点网络服务器运行 createService 流 POST 请求时,它会抛出

net.corda.core.transactions.MissingContractAttachments: Cannot find contract attachments for com.template.contract.ServiceContractnull. See https://docs.corda.net/api-contract-constraints.html#debugging
        at net.corda.core.transactions.TransactionBuilder.selectAttachmentThatSatisfiesConstraints(TransactionBuilder.kt:445) ~[corda-core-4.0.jar:?]...

更新:这是我在本地运行相同流程时得到的响应

{
  "wire": {
    "id": "3EDD9204FF70AF2B36D78219690946004C7D5625D347F04EE55980A8600141BF",
    "notary": "O=NetworkMapAndNotary, L=Helsinki, C=FI",
    "inputs": [],
    "outputs": [
      {
        "data": {...},
        "contract": "com.template.contract.ServiceContract",
        "notary": "O=NetworkMapAndNotary, L=Helsinki, C=FI",
        "encumbrance": null,
        "constraint": {
          "@class": "net.corda.core.contracts.AlwaysAcceptAttachmentConstraint"
        }
      }
    ],
    "commands": [
      {
        "value": {
          "@class": "com.template.contract.ServiceContract$Commands$IssueService"
        },
        "signers": [
          "GfHq2tTVk9z4eXgyVMCDbvndZWywoFqaPKbGgxeqVUEVBYgpNTqFTqc7mVqe",
          "GfHq2tTVk9z4eXgyWB97whuGdtsB8c7EByHbsTxkdsNq695JX8PKSwDPq3d9"
        ]
      }
    ],
    "timeWindow": null,
    "attachments": [
      "17B22D590137C675AC1B61B7052CCEF739AA36223865BBFF707E6CB2F933FBF0"
    ],
    "references": [],
    "privacySalt": "0AFC86A1BBF6D897CCC5AA56F0FC0474DE4CD618FF040BAA96293BAA1BCDBCAF",
    "networkParametersHash": "31AF29974115E6BE4418C4080F58DFD77F301E45DC35A05DB855B0D1B25966B2"
  },
  "signatures": [...]
}

【问题讨论】:

    标签: kotlin corda


    【解决方案1】:

    在您的 Azure 部署中,您是否在 node.conf 中使用 devMode=false 运行?

    可能是您的代码由只能在开发模式下使用的 corda dev 密钥签名(因为密钥不安全),这意味着部署的节点没有加载您的 CorDapp。

    为了测试这是否是您的 azure 部署中的问题,您可以尝试将此行添加到您的 node.conf

    cordappSignerKeyFingerprintBlacklist=[]
    

    默认情况下,Corda 开发密钥在该列表中,在列表中清空将导致您的应用程序被加载。请参阅https://docs.corda.net/corda-configuration-file.html#corda-configuration-file-signer-blacklist 了解更多信息。

    您可以在此处阅读有关签署 jar 的更多信息:

    https://docs.corda.net/cordapp-build-systems.html?highlight=signed#signing-the-cordapp-jar

    【讨论】:

    • 是的,在 node.conf 中确实有devMode=false。这解决了,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2019-11-13
    • 1970-01-01
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多