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 {
/** 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)

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()
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)

View File

@ -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

View File

@ -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()

View File

@ -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>() {

View File

@ -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