From 1362a305c91d56b9d609e31d3e394f3cab2c0842 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Mon, 23 Jan 2017 13:28:36 +0000 Subject: [PATCH] Expand details provided when erroring due to missing signatures in notary flow Signed-off-by: Ross Nicoll --- .../src/main/kotlin/net/corda/flows/NotaryFlow.kt | 15 +++++++++------ .../net/corda/flows/ValidatingNotaryFlow.kt | 6 +++--- .../node/services/ValidatingNotaryServiceTests.kt | 4 ++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/src/main/kotlin/net/corda/flows/NotaryFlow.kt b/core/src/main/kotlin/net/corda/flows/NotaryFlow.kt index 6f02ddeb10..ce3ec4bd19 100644 --- a/core/src/main/kotlin/net/corda/flows/NotaryFlow.kt +++ b/core/src/main/kotlin/net/corda/flows/NotaryFlow.kt @@ -1,8 +1,10 @@ package net.corda.flows import co.paralleluniverse.fibers.Suspendable -import net.corda.core.contracts.StateRef -import net.corda.core.crypto.* +import net.corda.core.crypto.DigitalSignature +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.node.services.TimestampChecker import net.corda.core.node.services.UniquenessException @@ -48,7 +50,7 @@ object NotaryFlow { try { stx.verifySignatures(notaryParty.owningKey) } catch (ex: SignedTransaction.SignaturesMissingException) { - throw NotaryException(NotaryError.SignaturesMissing(ex.missing)) + throw NotaryException(NotaryError.SignaturesMissing(ex)) } val response = sendAndReceive(notaryParty, SignRequest(stx)) @@ -182,9 +184,10 @@ sealed class NotaryError { /** Thrown if the time specified in the timestamp command is outside the allowed tolerance */ class TimestampInvalid : NotaryError() - class TransactionInvalid : NotaryError() + class TransactionInvalid(val msg: String) : NotaryError() + class SignaturesInvalid(val msg: String): NotaryError() - class SignaturesMissing(val missingSigners: Set) : NotaryError() { - override fun toString() = "Missing signatures from: ${missingSigners.map { it.toBase58String() }}" + class SignaturesMissing(val cause: SignedTransaction.SignaturesMissingException) : NotaryError() { + override fun toString() = cause.toString() } } diff --git a/core/src/main/kotlin/net/corda/flows/ValidatingNotaryFlow.kt b/core/src/main/kotlin/net/corda/flows/ValidatingNotaryFlow.kt index 4db4f65075..41897c40b7 100644 --- a/core/src/main/kotlin/net/corda/flows/ValidatingNotaryFlow.kt +++ b/core/src/main/kotlin/net/corda/flows/ValidatingNotaryFlow.kt @@ -29,8 +29,8 @@ class ValidatingNotaryFlow(otherSide: Party, wtx.toLedgerTransaction(serviceHub).verify() } catch (e: Exception) { when (e) { - is TransactionVerificationException, - is SignatureException -> throw NotaryException(NotaryError.TransactionInvalid()) + is TransactionVerificationException -> NotaryException(NotaryError.TransactionInvalid(e.toString())) + is SignatureException -> throw NotaryException(NotaryError.SignaturesInvalid(e.toString())) else -> throw e } } @@ -40,7 +40,7 @@ class ValidatingNotaryFlow(otherSide: Party, try { stx.verifySignatures(serviceHub.myInfo.notaryIdentity.owningKey) } catch(e: SignedTransaction.SignaturesMissingException) { - throw NotaryException(NotaryError.SignaturesMissing(e.missing)) + throw NotaryException(NotaryError.SignaturesMissing(e)) } } diff --git a/node/src/test/kotlin/net/corda/node/services/ValidatingNotaryServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/ValidatingNotaryServiceTests.kt index daddcb47bf..ee2c1f5c3b 100644 --- a/node/src/test/kotlin/net/corda/node/services/ValidatingNotaryServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/ValidatingNotaryServiceTests.kt @@ -52,7 +52,7 @@ class ValidatingNotaryServiceTests { val future = runClient(stx) 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`() { @@ -73,7 +73,7 @@ class ValidatingNotaryServiceTests { val notaryError = ex.error 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) }