Skip to content

Instantly share code, notes, and snippets.

@davidawad
Created March 18, 2021 18:31
Show Gist options
  • Save davidawad/dbea53608866f0e22204b0de1748699e to your computer and use it in GitHub Desktop.
Save davidawad/dbea53608866f0e22204b0de1748699e to your computer and use it in GitHub Desktop.
class CarContract : Contract {
@Throws(IllegalArgumentException::class)
override fun verify(tx: LedgerTransaction) {
val (signers, _, value) = tx.commands.requireSingleCommand(Commands::class.java)
val inputs = tx.inputStates
val outputs = tx.outputStates
if (value is Commands.Issue) {
requireThat {
"Transaction must have no input states.".using(inputs.isEmpty())
"Transaction must have exactly one output.".using(outputs.size == 1)
"Output must be a CarState.".using(outputs[0] is CarState)
// retrieve the CarState for the transaction
val outputState = outputs[0] as CarState
"The license plate number must be seven characters long.".using(outputState.getLicensePlateNumber().length() === 7)
"Manufacturer must be required singer.".using(signers.contains(outputState.getManufacturer().getOwningKey()))
}
} else {
throw IllegalArgumentException("Unrecognized command")
}
}
interface Commands : CommandData {
class Issue : Commands
}
companion object {
var ID = "Sample.CarContract"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment