Fixed items raised by MH in CRD-CR-58 code review.

This commit is contained in:
Jose Coll
2016-10-20 10:52:51 +01:00
parent ef2ff777a7
commit c7d98b8c6b
4 changed files with 20 additions and 32 deletions

View File

@ -84,16 +84,6 @@ class NodeVaultService(private val services: ServiceHub) : SingletonSerializeAsT
override val updates: Observable<Vault.Update>
get() = mutex.locked { _updatesPublisher }
@Suppress("UNCHECKED_CAST")
override val cashBalances: Map<Currency, Amount<Currency>>
get() = currentVault.states.
// Select the states we own which are cash, ignore the rest, take the amounts.
mapNotNull { (it.state.data as? FungibleAsset<Currency>)?.amount }.
// Turn into a Map<Currency, List<Amount>> like { GBP -> (£100, £500, etc), USD -> ($2000, $50) }
groupBy { it.token.product }.
// Collapse to Map<Currency, Amount> by summing all the amounts of the same currency together.
mapValues { it.value.map { Amount(it.quantity, it.token.product) }.sumOrThrow() }
override fun track(): Pair<Vault, Observable<Vault.Update>> {
return mutex.locked {
Pair(Vault(allUnconsumedStates()), _updatesPublisher.bufferUntilSubscribed())