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 package net.corda.client.jfx.model
import javafx.beans.value.ObservableValue import javafx.beans.value.ObservableValue
import javafx.collections.FXCollections import net.corda.client.jfx.utils.distinctBy
import javafx.collections.ObservableMap import net.corda.client.jfx.utils.lift
import net.corda.client.jfx.utils.* 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.ContractState
import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef import net.corda.core.contracts.StateRef
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.WireTransaction 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 * [PartiallyResolvedTransaction] holds a [SignedTransaction] that has zero or more inputs resolved. The intent is
@ -43,38 +43,36 @@ data class PartiallyResolvedTransaction(
companion object { companion object {
fun fromSignedTransaction( fun fromSignedTransaction(
transaction: SignedTransaction, transaction: SignedTransaction,
stateMap: ObservableMap<StateRef, StateAndRef<ContractState>> inputTransactions: Map<StateRef, SignedTransaction?>
) = PartiallyResolvedTransaction( ): PartiallyResolvedTransaction {
transaction = transaction, return PartiallyResolvedTransaction(
inputs = transaction.inputs.map { stateRef -> transaction = transaction,
EasyBind.map(stateMap.getObservableValue(stateRef)) { inputs = transaction.inputs.map { stateRef ->
if (it == null) { val tx = inputTransactions.get(stateRef)
if (tx == null) {
InputResolution.Unresolved(stateRef) InputResolution.Unresolved(stateRef)
} else { } 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()
} }
} } else {
}, // Transaction will have the same number of outputs as inputs
outputs = if (transaction.coreTransaction is WireTransaction) { val outputCount = transaction.coreTransaction.inputs.size
transaction.tx.outRefsOfType<ContractState>().map { val stateRefs = (0 until outputCount).map { StateRef(transaction.id, it) }
OutputResolution.Resolved(it).lift() stateRefs.map { stateRef ->
} val tx = inputTransactions.get(stateRef)
} else { if (tx == null) {
// 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) {
OutputResolution.Unresolved(stateRef) OutputResolution.Unresolved(stateRef)
} else { } else {
OutputResolution.Resolved(it) OutputResolution.Resolved(tx.coreTransaction.outRef(stateRef.index))
} }.lift()
} }
} })
} }
)
} }
} }
@ -84,13 +82,12 @@ data class PartiallyResolvedTransaction(
class TransactionDataModel { class TransactionDataModel {
private val transactions by observable(NodeMonitorModel::transactions) private val transactions by observable(NodeMonitorModel::transactions)
private val collectedTransactions = transactions.recordInSequence().distinctBy { it.id } private val collectedTransactions = transactions.recordInSequence().distinctBy { it.id }
private val vaultUpdates by observable(NodeMonitorModel::vaultUpdates) private val rpcProxy by observableValue(NodeMonitorModel::proxyObservable)
private val stateMap = vaultUpdates.fold(FXCollections.observableHashMap<StateRef, StateAndRef<ContractState>>()) { map, (consumed, produced) ->
val states = consumed + produced
states.forEach { map[it.ref] = it }
}
val partiallyResolvedTransactions = collectedTransactions.map { 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.") @Deprecated("This method is intended only for internal use and will be removed from the public API soon.")
fun internalVerifiedTransactionsSnapshot(): List<SignedTransaction> 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. * @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 return snapshot
} }
override fun internalFindVerifiedTransaction(txnId: SecureHash): SignedTransaction? = services.validatedTransactions.getTransaction(txnId)
@Suppress("OverridingDeprecatedMember") @Suppress("OverridingDeprecatedMember")
override fun internalVerifiedTransactionsFeed(): DataFeed<List<SignedTransaction>, SignedTransaction> { override fun internalVerifiedTransactionsFeed(): DataFeed<List<SignedTransaction>, SignedTransaction> {
return services.validatedTransactions.track() return services.validatedTransactions.track()