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