Address review comments.

This commit is contained in:
Mike Hearn 2016-11-30 15:11:35 +00:00
parent 7b40be8361
commit d500bf8f50
6 changed files with 22 additions and 21 deletions

View File

@ -304,10 +304,12 @@ data class ErrorOr<out A> private constructor(val value: A?, val error: Throwabl
companion object { companion object {
/** Runs the given lambda and wraps the result. */ /** Runs the given lambda and wraps the result. */
inline fun <T : Any> catch(body: () -> T): ErrorOr<T> = try { inline fun <T : Any> catch(body: () -> T): ErrorOr<T> {
ErrorOr(body()) return try {
} catch (t: Throwable) { ErrorOr(body())
ErrorOr.of(t) } catch (t: Throwable) {
ErrorOr.of(t)
}
} }
fun of(t: Throwable) = ErrorOr(null, t) fun of(t: Throwable) = ErrorOr(null, t)

View File

@ -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() override fun toString(): String = if (externalId != null) "${externalId}_$id" else id.toString()
companion object { 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 @VisibleForTesting
fun fromString(name: String): UniqueIdentifier fun fromString(name: String): UniqueIdentifier = UniqueIdentifier(null, UUID.fromString(name))
= UniqueIdentifier(null, UUID.fromString(name))
} }
override fun compareTo(other: UniqueIdentifier): Int = id.compareTo(other.id) override fun compareTo(other: UniqueIdentifier): Int = id.compareTo(other.id)

View File

@ -79,12 +79,11 @@ sealed class TransactionType {
} }
// Validate that all encumbrances exist within the set of input states. // Validate that all encumbrances exist within the set of input states.
tx.inputs.filter { it.state.data.encumbrance != null }.forEach { tx.inputs.filter { it.state.data.encumbrance != null }.forEach { encumberedInput ->
encumberedInput -> val isMissing = tx.inputs.none {
if (tx.inputs.none { it.ref.txhash == encumberedInput.ref.txhash && it.ref.index == encumberedInput.state.data.encumbrance
it.ref.txhash == encumberedInput.ref.txhash && }
it.ref.index == encumberedInput.state.data.encumbrance if (isMissing) {
}) {
throw TransactionVerificationException.TransactionMissingEncumbranceException( throw TransactionVerificationException.TransactionMissingEncumbranceException(
tx, encumberedInput.state.data.encumbrance!!, tx, encumberedInput.state.data.encumbrance!!,
TransactionVerificationException.Direction.INPUT TransactionVerificationException.Direction.INPUT

View File

@ -485,11 +485,12 @@ class TwoPartyTradeFlowTests {
// Issued money to itself. // Issued money to itself.
output("elbonian money 1", notary = notary) { 800.DOLLARS.CASH `issued by` issuer `owned by` MEGA_CORP_PUBKEY } 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 } 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() } command(DUMMY_CASH_ISSUER_KEY.public.composite) { Cash.Commands.Issue() }
else } else {
// Put a broken command on so at least a signature is created // Put a broken command on so at least a signature is created
command(DUMMY_CASH_ISSUER_KEY.public.composite) { Cash.Commands.Move() } command(DUMMY_CASH_ISSUER_KEY.public.composite) { Cash.Commands.Move() }
}
timestamp(TEST_TX_TIME) timestamp(TEST_TX_TIME)
if (withError) { if (withError) {
this.fails() this.fails()

View File

@ -504,9 +504,10 @@ class InterestRateSwap() : Contract {
} }
class Group : GroupClauseVerifier<State, Commands, UniqueIdentifier>(AnyComposition(Agree(), Fix(), Pay(), Mature())) { 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
// Group by Trade ID for in / out states override fun groupStates(tx: TransactionForContract): List<TransactionForContract.InOutGroup<State, UniqueIdentifier>> {
= tx.groupStates() { state -> state.linearId } return tx.groupStates() { state -> state.linearId }
}
} }
class Timestamped : Clause<ContractState, Commands, Unit>() { class Timestamped : Clause<ContractState, Commands, Unit>() {

View File

@ -17,6 +17,7 @@ class ReportingCurrencyModel {
private val exchangeRate: ObservableValue<ExchangeRate> by observableValue(ExchangeRateModel::exchangeRate) private val exchangeRate: ObservableValue<ExchangeRate> by observableValue(ExchangeRateModel::exchangeRate)
val reportingCurrency by observableValue(SettingsModel::reportingCurrencyProperty) val reportingCurrency by observableValue(SettingsModel::reportingCurrencyProperty)
val supportedCurrencies = setOf(USD, GBP, CHF).toList().observable() 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 * This stream provides a stream of exchange() functions that updates when either the reporting currency or the
* exchange rates change * exchange rates change