Получение ошибки неразрешенной референции в контракте корда? - PullRequest
0 голосов
/ 01 апреля 2020

Мой вариант использования аналогичен сценарию использования векселя. При написании контракта я получаю следующую ошибку.

> Task :contracts:compileKotlin FAILED
e: D:\Capstone_Tryout\contracts\src\main\kotlin\com\template\contracts\TradeContract.kt: (45, 34): Unresolved reference: signers

Мой код:

package com.template.contracts

import com.template.states.TradeState
import net.corda.core.contracts.CommandData
import net.corda.core.contracts.Contract
import net.corda.core.contracts.requireSingleCommand
import net.corda.core.contracts.requireThat
import net.corda.core.transactions.LedgerTransaction

// ************
// * Contract *
// ************
class TradeContract :Contract {
    companion object {
        // Used to identify our contract when building a transaction.
        const val ID = "com.template.contracts.TradeContract"
    }

    // A transaction is valid if the verify() function of the contract of all the transaction's input and output states
    // does not throw an exception.

    override fun verify(tx: LedgerTransaction) {
        val command = tx.commands.requireSingleCommand<Commands>().value

        when(command) {
            is Commands.Issue -> requireThat {
                "There should be no input state" using (tx.inputs.isEmpty())
                "There should be one output state" using (tx.outputs.size == 1)

                "The output state should be of type TradeState" using (tx.outputs.get(0).data is TradeState)
                val outputState = tx.outputs.get(0).data as TradeState
                "TradeId should be 10 character long" using (outputState.TradeId.length == 10)

                val trade = tx.outputsOfType<TradeState>().single()
                "All of the participants must be signers." using (command.signers.toSet() == trade.participants.map { it.owningKey }.toSet())
                "A newly issued TradeState must have a positive amount." using (trade.Amount > 0)
                "The FromParty and ToParty cannot have the same identity." using (trade.FromParty != trade.ToParty)


            }
        }

        // Verification logic goes here.
    }

    // Used to indicate the transaction's intent.
    interface Commands : CommandData {
        class Issue : Commands
    }
}

Пока похожий код работает в примере с кордой.

val iou = tx.outputsOfType<IOUState>().single()
"Both Parties together only may sign Trade issue transaction." using
                        (command.signers.toSet() == iou.participants.map { it.owningKey }.toSet())

Я не могу понять, почему я Я получаю эту ошибку.

Ответы [ 2 ]

1 голос
/ 01 апреля 2020

Пожалуйста, подтвердите, что вы сделали следующее:

  1. Определите команду в вашем контракте:
public interface Commands extends CommandData {
    class Create implements Commands {}
}
Извлеките команду из транзакции внутри вашего verify() метода:
final CommandWithParties<Commands.Create> command = 
                    requireSingleCommand(tx.getCommands(), Commands.Create.class);
0 голосов
/ 02 апреля 2020

Команда переносит значения и подписи.

  • Значение - это тип команды
  • Подписывающими сторонами являются публичные c ключи требуемых подписавшихся команды.

Проблема в приведенном выше коде:

val command = tx.commands.requireSingleCommand<Commands>().value

Замените вышеприведенное на:

val command = tx.commands.requireSingleCommand<Commands>()
...