Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Hearn committed Nov 30, 2016
1 parent 7b40be8 commit d500bf8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
10 changes: 6 additions & 4 deletions core/src/main/kotlin/net/corda/core/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,12 @@ data class ErrorOr<out A> private constructor(val value: A?, val error: Throwabl

companion object {
/** Runs the given lambda and wraps the result. */
inline fun <T : Any> catch(body: () -> T): ErrorOr<T> = try {
ErrorOr(body())
} catch (t: Throwable) {
ErrorOr.of(t)
inline fun <T : Any> catch(body: () -> T): ErrorOr<T> {
return try {
ErrorOr(body())
} catch (t: Throwable) {
ErrorOr.of(t)
}
}

fun of(t: Throwable) = ErrorOr(null, t)
Expand Down
7 changes: 2 additions & 5 deletions core/src/main/kotlin/net/corda/core/contracts/FinanceTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,10 @@ class InterestRateSwap() : Contract {
}

class Group : GroupClauseVerifier<State, Commands, UniqueIdentifier>(AnyComposition(Agree(), Fix(), Pay(), Mature())) {
override fun groupStates(tx: TransactionForContract): List<TransactionForContract.InOutGroup<State, UniqueIdentifier>>
// 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<TransactionForContract.InOutGroup<State, UniqueIdentifier>> {
return tx.groupStates() { state -> state.linearId }
}
}

class Timestamped : Clause<ContractState, Commands, Unit>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ReportingCurrencyModel {
private val exchangeRate: ObservableValue<ExchangeRate> 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
Expand Down

0 comments on commit d500bf8

Please sign in to comment.