Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.