From d500bf8f501939d9e814871729fb1e01ff29693f Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 30 Nov 2016 15:11:35 +0000 Subject: [PATCH] Address review comments. --- core/src/main/kotlin/net/corda/core/Utils.kt | 10 ++++++---- .../kotlin/net/corda/core/contracts/FinanceTypes.kt | 7 ++----- .../net/corda/core/contracts/TransactionTypes.kt | 11 +++++------ .../node/messaging/TwoPartyTradeProtocolTests.kt | 7 ++++--- .../src/main/kotlin/net/corda/irs/contract/IRS.kt | 7 ++++--- .../corda/explorer/model/ReportingCurrencyModel.kt | 1 + 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/Utils.kt b/core/src/main/kotlin/net/corda/core/Utils.kt index 2f73a3238c..ae6f5688fe 100644 --- a/core/src/main/kotlin/net/corda/core/Utils.kt +++ b/core/src/main/kotlin/net/corda/core/Utils.kt @@ -304,10 +304,12 @@ data class ErrorOr private constructor(val value: A?, val error: Throwabl companion object { /** Runs the given lambda and wraps the result. */ - inline fun catch(body: () -> T): ErrorOr = try { - ErrorOr(body()) - } catch (t: Throwable) { - ErrorOr.of(t) + inline fun catch(body: () -> T): ErrorOr { + return try { + ErrorOr(body()) + } catch (t: Throwable) { + ErrorOr.of(t) + } } fun of(t: Throwable) = ErrorOr(null, t) diff --git a/core/src/main/kotlin/net/corda/core/contracts/FinanceTypes.kt b/core/src/main/kotlin/net/corda/core/contracts/FinanceTypes.kt index 8fa86b3aa7..0b66c5e1b6 100644 --- a/core/src/main/kotlin/net/corda/core/contracts/FinanceTypes.kt +++ b/core/src/main/kotlin/net/corda/core/contracts/FinanceTypes.kt @@ -464,12 +464,9 @@ data class UniqueIdentifier(val externalId: String? = null, val id: UUID = UUID. override fun toString(): String = if (externalId != null) "${externalId}_$id" else id.toString() companion object { - /** - * Helper function for unit tests where the UUID needs to be manually initialised for consistency. - */ + /** Helper function for unit tests where the UUID needs to be manually initialised for consistency. */ @VisibleForTesting - fun fromString(name: String): UniqueIdentifier - = UniqueIdentifier(null, UUID.fromString(name)) + fun fromString(name: String): UniqueIdentifier = UniqueIdentifier(null, UUID.fromString(name)) } override fun compareTo(other: UniqueIdentifier): Int = id.compareTo(other.id) diff --git a/core/src/main/kotlin/net/corda/core/contracts/TransactionTypes.kt b/core/src/main/kotlin/net/corda/core/contracts/TransactionTypes.kt index 37935f4257..09d8478185 100644 --- a/core/src/main/kotlin/net/corda/core/contracts/TransactionTypes.kt +++ b/core/src/main/kotlin/net/corda/core/contracts/TransactionTypes.kt @@ -79,12 +79,11 @@ sealed class TransactionType { } // Validate that all encumbrances exist within the set of input states. - tx.inputs.filter { it.state.data.encumbrance != null }.forEach { - encumberedInput -> - if (tx.inputs.none { - it.ref.txhash == encumberedInput.ref.txhash && - it.ref.index == encumberedInput.state.data.encumbrance - }) { + tx.inputs.filter { it.state.data.encumbrance != null }.forEach { encumberedInput -> + val isMissing = tx.inputs.none { + it.ref.txhash == encumberedInput.ref.txhash && it.ref.index == encumberedInput.state.data.encumbrance + } + if (isMissing) { throw TransactionVerificationException.TransactionMissingEncumbranceException( tx, encumberedInput.state.data.encumbrance!!, TransactionVerificationException.Direction.INPUT diff --git a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeProtocolTests.kt b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeProtocolTests.kt index 2bb8723913..49a6ee821a 100644 --- a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeProtocolTests.kt +++ b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeProtocolTests.kt @@ -485,11 +485,12 @@ class TwoPartyTradeFlowTests { // Issued money to itself. output("elbonian money 1", notary = notary) { 800.DOLLARS.CASH `issued by` issuer `owned by` MEGA_CORP_PUBKEY } output("elbonian money 2", notary = notary) { 1000.DOLLARS.CASH `issued by` issuer `owned by` MEGA_CORP_PUBKEY } - if (!withError) + if (!withError) { command(DUMMY_CASH_ISSUER_KEY.public.composite) { Cash.Commands.Issue() } - else - // Put a broken command on so at least a signature is created + } else { + // Put a broken command on so at least a signature is created command(DUMMY_CASH_ISSUER_KEY.public.composite) { Cash.Commands.Move() } + } timestamp(TEST_TX_TIME) if (withError) { this.fails() diff --git a/samples/irs-demo/src/main/kotlin/net/corda/irs/contract/IRS.kt b/samples/irs-demo/src/main/kotlin/net/corda/irs/contract/IRS.kt index 7e0d87356a..60c30dae1f 100644 --- a/samples/irs-demo/src/main/kotlin/net/corda/irs/contract/IRS.kt +++ b/samples/irs-demo/src/main/kotlin/net/corda/irs/contract/IRS.kt @@ -504,9 +504,10 @@ class InterestRateSwap() : Contract { } class Group : GroupClauseVerifier(AnyComposition(Agree(), Fix(), Pay(), Mature())) { - override fun groupStates(tx: TransactionForContract): List> - // Group by Trade ID for in / out states - = tx.groupStates() { state -> state.linearId } + // Group by Trade ID for in / out states + override fun groupStates(tx: TransactionForContract): List> { + return tx.groupStates() { state -> state.linearId } + } } class Timestamped : Clause() { diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/model/ReportingCurrencyModel.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/model/ReportingCurrencyModel.kt index acb446d650..9ae977d5cc 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/model/ReportingCurrencyModel.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/model/ReportingCurrencyModel.kt @@ -17,6 +17,7 @@ class ReportingCurrencyModel { private val exchangeRate: ObservableValue by observableValue(ExchangeRateModel::exchangeRate) val reportingCurrency by observableValue(SettingsModel::reportingCurrencyProperty) val supportedCurrencies = setOf(USD, GBP, CHF).toList().observable() + /** * This stream provides a stream of exchange() functions that updates when either the reporting currency or the * exchange rates change