diff --git a/src/main/kotlin/contracts/Cash.kt b/src/main/kotlin/contracts/Cash.kt index f02f78b9ff..10b7869542 100644 --- a/src/main/kotlin/contracts/Cash.kt +++ b/src/main/kotlin/contracts/Cash.kt @@ -234,8 +234,13 @@ class Cash : Contract { } // Small DSL extensions. + +/** Sums the cash states in the list that are owned by the given key, throwing an exception if there are none. */ fun Iterable.sumCashBy(owner: PublicKey) = filterIsInstance().filter { it.owner == owner }.map { it.amount }.sumOrThrow() +/** Sums the cash states in the list, throwing an exception if there are none. */ fun Iterable.sumCash() = filterIsInstance().map { it.amount }.sumOrThrow() +/** Sums the cash states in the list, returning null if there are none. */ fun Iterable.sumCashOrNull() = filterIsInstance().map { it.amount }.sumOrNull() +/** Sums the cash states in the list, returning zero of the given currency if there are none. */ fun Iterable.sumCashOrZero(currency: Currency) = filterIsInstance().map { it.amount }.sumOrZero(currency)