Created
June 14, 2019 07:54
-
-
Save lankydan/780e2a11a22d80ac459ec715718ed665 to your computer and use it in GitHub Desktop.
Preventing invalid spending of broadcasted states - ReplyToMessageResponder
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
@InitiatedBy(ReplyToMessageFlow::class) | |
class ReplyToMessageResponder(private val session: FlowSession) : FlowLogic<SignedTransaction>() { | |
@Suspendable | |
override fun call(): SignedTransaction { | |
val stx = subFlow(object : SignTransactionFlow(session) { | |
override fun checkTransaction(stx: SignedTransaction) { | |
val message = stx.coreTransaction.outputsOfType<MessageState>().single() | |
require(message.sender != ourIdentity) { | |
"The sender of the new message cannot have my identity when I am not the creator of the transaction" | |
} | |
require(message.sender == session.counterparty) { | |
"The sender of the reply must must be the party creating this transaction" | |
} | |
} | |
}) | |
return subFlow( | |
ReceiveFinalityFlow( | |
otherSideSession = session, | |
expectedTxId = stx.id | |
) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment