Expand details provided when erroring due to missing signatures in notary flow

Signed-off-by: Ross Nicoll <ross.nicoll@r3.com>
This commit is contained in:
Ross Nicoll
2017-01-23 13:28:36 +00:00
parent a4254ac695
commit 1362a305c9
3 changed files with 14 additions and 11 deletions

View File

@ -1,8 +1,10 @@
package net.corda.flows package net.corda.flows
import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.fibers.Suspendable
import net.corda.core.contracts.StateRef import net.corda.core.crypto.DigitalSignature
import net.corda.core.crypto.* import net.corda.core.crypto.Party
import net.corda.core.crypto.SignedData
import net.corda.core.crypto.signWithECDSA
import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowLogic
import net.corda.core.node.services.TimestampChecker import net.corda.core.node.services.TimestampChecker
import net.corda.core.node.services.UniquenessException import net.corda.core.node.services.UniquenessException
@ -48,7 +50,7 @@ object NotaryFlow {
try { try {
stx.verifySignatures(notaryParty.owningKey) stx.verifySignatures(notaryParty.owningKey)
} catch (ex: SignedTransaction.SignaturesMissingException) { } catch (ex: SignedTransaction.SignaturesMissingException) {
throw NotaryException(NotaryError.SignaturesMissing(ex.missing)) throw NotaryException(NotaryError.SignaturesMissing(ex))
} }
val response = sendAndReceive<Result>(notaryParty, SignRequest(stx)) val response = sendAndReceive<Result>(notaryParty, SignRequest(stx))
@ -182,9 +184,10 @@ sealed class NotaryError {
/** Thrown if the time specified in the timestamp command is outside the allowed tolerance */ /** Thrown if the time specified in the timestamp command is outside the allowed tolerance */
class TimestampInvalid : NotaryError() class TimestampInvalid : NotaryError()
class TransactionInvalid : NotaryError() class TransactionInvalid(val msg: String) : NotaryError()
class SignaturesInvalid(val msg: String): NotaryError()
class SignaturesMissing(val missingSigners: Set<CompositeKey>) : NotaryError() { class SignaturesMissing(val cause: SignedTransaction.SignaturesMissingException) : NotaryError() {
override fun toString() = "Missing signatures from: ${missingSigners.map { it.toBase58String() }}" override fun toString() = cause.toString()
} }
} }

View File

@ -29,8 +29,8 @@ class ValidatingNotaryFlow(otherSide: Party,
wtx.toLedgerTransaction(serviceHub).verify() wtx.toLedgerTransaction(serviceHub).verify()
} catch (e: Exception) { } catch (e: Exception) {
when (e) { when (e) {
is TransactionVerificationException, is TransactionVerificationException -> NotaryException(NotaryError.TransactionInvalid(e.toString()))
is SignatureException -> throw NotaryException(NotaryError.TransactionInvalid()) is SignatureException -> throw NotaryException(NotaryError.SignaturesInvalid(e.toString()))
else -> throw e else -> throw e
} }
} }
@ -40,7 +40,7 @@ class ValidatingNotaryFlow(otherSide: Party,
try { try {
stx.verifySignatures(serviceHub.myInfo.notaryIdentity.owningKey) stx.verifySignatures(serviceHub.myInfo.notaryIdentity.owningKey)
} catch(e: SignedTransaction.SignaturesMissingException) { } catch(e: SignedTransaction.SignaturesMissingException) {
throw NotaryException(NotaryError.SignaturesMissing(e.missing)) throw NotaryException(NotaryError.SignaturesMissing(e))
} }
} }

View File

@ -52,7 +52,7 @@ class ValidatingNotaryServiceTests {
val future = runClient(stx) val future = runClient(stx)
val ex = assertFailsWith(NotaryException::class) { future.getOrThrow() } val ex = assertFailsWith(NotaryException::class) { future.getOrThrow() }
assertThat(ex.error).isInstanceOf(NotaryError.TransactionInvalid::class.java) assertThat(ex.error).isInstanceOf(NotaryError.SignaturesInvalid::class.java)
} }
@Test fun `should report error for missing signatures`() { @Test fun `should report error for missing signatures`() {
@ -73,7 +73,7 @@ class ValidatingNotaryServiceTests {
val notaryError = ex.error val notaryError = ex.error
assertThat(notaryError).isInstanceOf(NotaryError.SignaturesMissing::class.java) assertThat(notaryError).isInstanceOf(NotaryError.SignaturesMissing::class.java)
val missingKeys = (notaryError as NotaryError.SignaturesMissing).missingSigners val missingKeys = (notaryError as NotaryError.SignaturesMissing).cause.missing
assertEquals(setOf(expectedMissingKey), missingKeys) assertEquals(setOf(expectedMissingKey), missingKeys)
} }