Created
June 14, 2019 07:49
-
-
Save lankydan/c8a53ddbb97ee33a9d571662b10b0cea to your computer and use it in GitHub Desktop.
Preventing invalid spending of broadcasted states - General contract validation
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
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