Created
March 18, 2021 18:31
-
-
Save davidawad/dbea53608866f0e22204b0de1748699e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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