CORDA-1407 Node Explorer - fix total column (#3395)

This commit is contained in:
Tudor Malene 2018-06-19 09:19:19 +01:00 committed by GitHub
parent 20aca788ce
commit 41776ed374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 36 deletions

View File

@ -1,15 +1,15 @@
package net.corda.client.jfx.model
import javafx.beans.value.ObservableValue
import javafx.collections.FXCollections
import javafx.collections.ObservableMap
import net.corda.client.jfx.utils.*
import net.corda.client.jfx.utils.distinctBy
import net.corda.client.jfx.utils.lift
import net.corda.client.jfx.utils.map
import net.corda.client.jfx.utils.recordInSequence
import net.corda.core.contracts.ContractState
import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.WireTransaction
import org.fxmisc.easybind.EasyBind
/**
* [PartiallyResolvedTransaction] holds a [SignedTransaction] that has zero or more inputs resolved. The intent is
@ -43,38 +43,36 @@ data class PartiallyResolvedTransaction(
companion object {
fun fromSignedTransaction(
transaction: SignedTransaction,
stateMap: ObservableMap<StateRef, StateAndRef<ContractState>>
) = PartiallyResolvedTransaction(
transaction = transaction,
inputs = transaction.inputs.map { stateRef ->
EasyBind.map(stateMap.getObservableValue(stateRef)) {
if (it == null) {
inputTransactions: Map<StateRef, SignedTransaction?>
): PartiallyResolvedTransaction {
return PartiallyResolvedTransaction(
transaction = transaction,
inputs = transaction.inputs.map { stateRef ->
val tx = inputTransactions.get(stateRef)
if (tx == null) {
InputResolution.Unresolved(stateRef)
} else {
InputResolution.Resolved(it)
InputResolution.Resolved(tx.coreTransaction.outRef(stateRef.index))
}.lift()
},
outputs = if (transaction.coreTransaction is WireTransaction) {
transaction.tx.outRefsOfType<ContractState>().map {
OutputResolution.Resolved(it).lift()
}
}
},
outputs = if (transaction.coreTransaction is WireTransaction) {
transaction.tx.outRefsOfType<ContractState>().map {
OutputResolution.Resolved(it).lift()
}
} else {
// Transaction will have the same number of outputs as inputs
val outputCount = transaction.coreTransaction.inputs.size
val stateRefs = (0 until outputCount).map { StateRef(transaction.id, it) }
stateRefs.map { stateRef ->
EasyBind.map(stateMap.getObservableValue(stateRef)) {
if (it == null) {
} else {
// Transaction will have the same number of outputs as inputs
val outputCount = transaction.coreTransaction.inputs.size
val stateRefs = (0 until outputCount).map { StateRef(transaction.id, it) }
stateRefs.map { stateRef ->
val tx = inputTransactions.get(stateRef)
if (tx == null) {
OutputResolution.Unresolved(stateRef)
} else {
OutputResolution.Resolved(it)
}
OutputResolution.Resolved(tx.coreTransaction.outRef(stateRef.index))
}.lift()
}
}
}
)
})
}
}
}
@ -84,13 +82,12 @@ data class PartiallyResolvedTransaction(
class TransactionDataModel {
private val transactions by observable(NodeMonitorModel::transactions)
private val collectedTransactions = transactions.recordInSequence().distinctBy { it.id }
private val vaultUpdates by observable(NodeMonitorModel::vaultUpdates)
private val stateMap = vaultUpdates.fold(FXCollections.observableHashMap<StateRef, StateAndRef<ContractState>>()) { map, (consumed, produced) ->
val states = consumed + produced
states.forEach { map[it.ref] = it }
}
private val rpcProxy by observableValue(NodeMonitorModel::proxyObservable)
val partiallyResolvedTransactions = collectedTransactions.map {
PartiallyResolvedTransaction.fromSignedTransaction(it, stateMap)
PartiallyResolvedTransaction.fromSignedTransaction(it,
it.inputs.map { stateRef ->
stateRef to rpcProxy.value!!.cordaRPCOps.internalFindVerifiedTransaction(stateRef.txhash)
}.toMap())
}
}

View File

@ -194,6 +194,14 @@ interface CordaRPCOps : RPCOps {
@Deprecated("This method is intended only for internal use and will be removed from the public API soon.")
fun internalVerifiedTransactionsSnapshot(): List<SignedTransaction>
/**
* @suppress Returns the full transaction for the provided ID
*
* TODO This method should be removed once SGX work is finalised and the design of the corresponding API using [FilteredTransaction] can be started
*/
@Deprecated("This method is intended only for internal use and will be removed from the public API soon.")
fun internalFindVerifiedTransaction(txnId: SecureHash): SignedTransaction?
/**
* @suppress Returns a data feed of all recorded transactions and an observable of future recorded ones.
*

View File

@ -107,6 +107,8 @@ internal class CordaRPCOpsImpl(
return snapshot
}
override fun internalFindVerifiedTransaction(txnId: SecureHash): SignedTransaction? = services.validatedTransactions.getTransaction(txnId)
@Suppress("OverridingDeprecatedMember")
override fun internalVerifiedTransactionsFeed(): DataFeed<List<SignedTransaction>, SignedTransaction> {
return services.validatedTransactions.track()