Minor: a few misc cleanups

This commit is contained in:
Mike Hearn 2015-11-19 11:56:07 +01:00
parent a4aef06e41
commit 7f13b8ab4a
3 changed files with 11 additions and 15 deletions

View File

@ -44,14 +44,8 @@ class TransactionGroup(val transactions: Set<LedgerTransaction>, val nonVerified
resolved.add(TransactionForVerification(inputs, tx.outStates, tx.commands, tx.time, tx.hash)) resolved.add(TransactionForVerification(inputs, tx.outStates, tx.commands, tx.time, tx.hash))
} }
for (tx in resolved) { for (tx in resolved)
try { tx.verify(programMap)
tx.verify(programMap)
} catch(e: Exception) {
println(tx)
throw e
}
}
return resolved return resolved
} }

View File

@ -194,10 +194,10 @@ data class TransactionForVerification(val inStates: List<ContractState>,
override fun equals(other: Any?) = other is TransactionForVerification && other.origHash == origHash override fun equals(other: Any?) = other is TransactionForVerification && other.origHash == origHash
/** /**
* @throws VerificationException if a contract throws an exception, the original is in the cause field * @throws TransactionVerificationException if a contract throws an exception, the original is in the cause field
* @throws IllegalStateException if a state refers to an unknown contract. * @throws IllegalStateException if a state refers to an unknown contract.
*/ */
@Throws(VerificationException::class, IllegalStateException::class) @Throws(TransactionVerificationException::class, IllegalStateException::class)
fun verify(programMap: Map<SecureHash, Contract>) { fun verify(programMap: Map<SecureHash, Contract>) {
// For each input and output state, locate the program to run. Then execute the verification function. If any // For each input and output state, locate the program to run. Then execute the verification function. If any
// throws an exception, the entire transaction is invalid. // throws an exception, the entire transaction is invalid.
@ -207,11 +207,11 @@ data class TransactionForVerification(val inStates: List<ContractState>,
try { try {
program.verify(this) program.verify(this)
} catch(e: Throwable) { } catch(e: Throwable) {
throw VerificationException(this, program, e) throw TransactionVerificationException(this, program, e)
} }
} }
} }
} }
/** Thrown if a verification fails due to a contract rejection. */ /** Thrown if a verification fails due to a contract rejection. */
class VerificationException(val tx: TransactionForVerification, val contract: Contract, cause: Throwable?) : Exception(cause) class TransactionVerificationException(val tx: TransactionForVerification, val contract: Contract, cause: Throwable?) : Exception(cause)

View File

@ -164,15 +164,15 @@ fun transaction(body: TransactionForTest.() -> Unit) = TransactionForTest().appl
class TransactionGroupForTest { class TransactionGroupForTest {
open inner class LedgerTransactionForTest : AbstractTransactionForTest() { open inner class LedgerTransactionForTest : AbstractTransactionForTest() {
private val inputs = ArrayList<ContractStateRef>() private val inStates = ArrayList<ContractStateRef>()
fun input(label: String) { fun input(label: String) {
inputs.add(labelToRefs[label] ?: throw IllegalArgumentException("Unknown label \"$label\"")) inStates.add(labelToRefs[label] ?: throw IllegalArgumentException("Unknown label \"$label\""))
} }
fun toLedgerTransaction(time: Instant): LedgerTransaction { fun toLedgerTransaction(time: Instant): LedgerTransaction {
val wireCmds = commands.map { WireCommand(it.value, it.signers) } val wireCmds = commands.map { WireCommand(it.value, it.signers) }
return WireTransaction(inputs, outStates.map { it.state }, wireCmds).toLedgerTransaction(time, TEST_KEYS_TO_CORP_MAP) return WireTransaction(inStates, outStates.map { it.state }, wireCmds).toLedgerTransaction(time, TEST_KEYS_TO_CORP_MAP)
} }
} }
@ -200,6 +200,8 @@ class TransactionGroupForTest {
@Deprecated("Does not nest ", level = DeprecationLevel.ERROR) @Deprecated("Does not nest ", level = DeprecationLevel.ERROR)
fun roots(body: Roots.() -> Unit) {} fun roots(body: Roots.() -> Unit) {}
@Deprecated("Use the vararg form of transaction inside roots", level = DeprecationLevel.ERROR)
fun transaction(time: Instant = TEST_TX_TIME, body: LedgerTransactionForTest.() -> Unit) {}
} }
fun roots(body: Roots.() -> Unit) = Roots().apply { body() } fun roots(body: Roots.() -> Unit) = Roots().apply { body() }