mirror of
https://github.com/corda/corda.git
synced 2025-01-29 15:43:55 +00:00
Minor: a few misc cleanups
This commit is contained in:
parent
a4aef06e41
commit
7f13b8ab4a
@ -44,14 +44,8 @@ class TransactionGroup(val transactions: Set<LedgerTransaction>, val nonVerified
|
||||
resolved.add(TransactionForVerification(inputs, tx.outStates, tx.commands, tx.time, tx.hash))
|
||||
}
|
||||
|
||||
for (tx in resolved) {
|
||||
try {
|
||||
tx.verify(programMap)
|
||||
} catch(e: Exception) {
|
||||
println(tx)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
for (tx in resolved)
|
||||
tx.verify(programMap)
|
||||
return resolved
|
||||
}
|
||||
|
||||
|
@ -194,10 +194,10 @@ data class TransactionForVerification(val inStates: List<ContractState>,
|
||||
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(VerificationException::class, IllegalStateException::class)
|
||||
@Throws(TransactionVerificationException::class, IllegalStateException::class)
|
||||
fun verify(programMap: Map<SecureHash, Contract>) {
|
||||
// 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.
|
||||
@ -207,11 +207,11 @@ data class TransactionForVerification(val inStates: List<ContractState>,
|
||||
try {
|
||||
program.verify(this)
|
||||
} catch(e: Throwable) {
|
||||
throw VerificationException(this, program, e)
|
||||
throw TransactionVerificationException(this, program, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 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)
|
@ -164,15 +164,15 @@ fun transaction(body: TransactionForTest.() -> Unit) = TransactionForTest().appl
|
||||
|
||||
class TransactionGroupForTest {
|
||||
open inner class LedgerTransactionForTest : AbstractTransactionForTest() {
|
||||
private val inputs = ArrayList<ContractStateRef>()
|
||||
private val inStates = ArrayList<ContractStateRef>()
|
||||
|
||||
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 {
|
||||
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)
|
||||
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() }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user