From 73f4803b725b68877e5d5b54dd9398460bccbbce Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Thu, 28 Apr 2016 12:08:37 +0100 Subject: [PATCH] Move common move command verification into a shared function --- contracts/src/main/kotlin/contracts/Cash.kt | 9 +-------- core/src/main/kotlin/core/ContractsDSL.kt | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/contracts/src/main/kotlin/contracts/Cash.kt b/contracts/src/main/kotlin/contracts/Cash.kt index abb9ce98d1..8b02e4bb42 100644 --- a/contracts/src/main/kotlin/contracts/Cash.kt +++ b/contracts/src/main/kotlin/contracts/Cash.kt @@ -130,14 +130,7 @@ class Cash : Contract { (inputAmount == outputAmount + amountExitingLedger) } - // Now check the digital signatures on the move command. Every input has an owning public key, and we must - // see a signature from each of those keys. The actual signatures have been verified against the transaction - // data by the platform before execution. - val owningPubKeys = inputs.map { it.owner }.toSet() - val keysThatSigned = tx.commands.requireSingleCommand().signers.toSet() - requireThat { - "the owning keys are the same as the signing keys" by keysThatSigned.containsAll(owningPubKeys) - } + verifyMoveCommand(inputs, tx) } } diff --git a/core/src/main/kotlin/core/ContractsDSL.kt b/core/src/main/kotlin/core/ContractsDSL.kt index f7e23ae858..54e55130cc 100644 --- a/core/src/main/kotlin/core/ContractsDSL.kt +++ b/core/src/main/kotlin/core/ContractsDSL.kt @@ -81,3 +81,20 @@ fun List>.getTimestampByName(vararg names: Stri return null } +/** + * Simple functionality for verifying a move command. Verifies that each input has a signature from its owning key. + * + * @param T the type of the move command + */ +@Throws(IllegalArgumentException::class) +// TODO: Can we have a common Move command for all contracts and avoid the reified type parameter here? +inline fun verifyMoveCommands(inputs: List, tx: TransactionForVerification) { + // Now check the digital signatures on the move command. Every input has an owning public key, and we must + // see a signature from each of those keys. The actual signatures have been verified against the transaction + // data by the platform before execution. + val owningPubKeys = inputs.map { it.owner }.toSet() + val keysThatSigned = tx.commands.requireSingleCommand().signers.toSet() + requireThat { + "the owning keys are the same as the signing keys" by keysThatSigned.containsAll(owningPubKeys) + } +} \ No newline at end of file