gpt4 book ai didi

kotlin - 找不到流量的契约(Contract)附件

转载 作者:行者123 更新时间:2023-12-02 13:35:43 27 4
gpt4 key购买 nike

将 corda 升级到版本 4 后,我收到 net.corda.core.transactions.MissingContractAttachments:找不到 com.template.contract.ServiceContractnull 的契约(Contract)附件。

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

我有

  • 检查我所有的 cordapps 是否位于/opt/corda/cordapps -文件夹
  • 我的契约(Contract) 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": [...]
    }

    最佳答案

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

    可能是您的代码由只能在开发模式下使用的 corda dev key 签名(因为 key 不安全),这意味着部署的节点没有加载您的 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

    关于kotlin - 找不到流量的契约(Contract)附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57656140/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com