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/cbeab28264ceb31fedc7bd64070b8a05 to your computer and use it in GitHub Desktop.
Save lankydan/cbeab28264ceb31fedc7bd64070b8a05 to your computer and use it in GitHub Desktop.
Preventing invalid spending of broadcasted states - Specific validation
override fun verify(tx: LedgerTransaction) {
val commandWithParties: CommandWithParties<Commands> = tx.commands.requireSingleCommand()
val command = commandWithParties.value
when (command) {
is Commands.Send -> // validation for sending
is Commands.Reply -> requireThat {
// general requirements from previous snippet
// precise requirements for `MessageState`
"One input should be consumed when replying to a message." using (tx.inputs.size == 1)
"Only one output state should be created when replying to a message." using (tx.outputs.size == 1)
val output = tx.outputsOfType<MessageState>().single()
val input = tx.inputsOfType<MessageState>().single()
"Only the original message's recipient can reply to the message" using (output.sender == input.recipient)
"The reply must be sent to the original sender" using (output.recipient == input.sender)
// covered by the general requirements
"The original sender must be included in the required signers" using commandWithParties.signers.contains(input.sender.owningKey)
"The original recipient must be included in the required signers" using commandWithParties.signers.contains(input.recipient.owningKey)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment