Skip to content

Instantly share code, notes, and snippets.

@lankydan
Created June 14, 2019 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lankydan/c8a53ddbb97ee33a9d571662b10b0cea to your computer and use it in GitHub Desktop.
Save lankydan/c8a53ddbb97ee33a9d571662b10b0cea to your computer and use it in GitHub Desktop.
Preventing invalid spending of broadcasted states - General contract validation
override fun verify(tx: LedgerTransaction) {
val commandWithParties: CommandWithParties<Commands> = tx.commands.requireSingleCommand()
when (commandWithParties.value) {
is Commands.Send -> // validation for sending
is Commands.Reply -> requireThat {
val inputPublicKeys = tx.inputs.flatMap { it.state.data.participants.map(AbstractParty::owningKey) }.toSet()
"The input participant keys are a subset of the signing keys" using commandWithParties.signers.containsAll(inputPublicKeys)
val outputPublicKeys = tx.outputStates.flatMap { it.participants.map(AbstractParty::owningKey) }.toSet()
"The output participant keys are a subset of the signing keys" using commandWithParties.signers.containsAll(outputPublicKeys)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment