Мой вариант использования аналогичен сценарию использования векселя. При написании контракта я получаю следующую ошибку.
> 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())
Я не могу понять, почему я Я получаю эту ошибку.