Fix not displaying Anonymous issuer name correctly in Explorer

This commit is contained in:
Patrick Kuo 2017-02-23 15:25:17 +00:00 committed by Ross Nicoll
parent 059056de65
commit dab80510f4
4 changed files with 20 additions and 15 deletions

View File

@ -40,6 +40,7 @@ class NetworkIdentityModel {
return advertisedServices.any { it.info.type == NetworkMapService.type || it.info.type.isNotary() }
}
// TODO: Use Identity Service in service hub instead?
fun lookup(compositeKey: CompositeKey): ObservableValue<NodeInfo?> = parties.firstOrDefault(notaries.firstOrNullObservable { it.notaryIdentity.owningKey == compositeKey }) {
it.legalIdentity.owningKey == compositeKey
}

View File

@ -10,7 +10,13 @@ import javafx.scene.layout.GridPane
import javafx.scene.layout.Priority
import javafx.scene.text.TextAlignment
import javafx.util.StringConverter
import net.corda.client.fxutils.map
import net.corda.client.model.Models
import net.corda.client.model.NetworkIdentityModel
import net.corda.contracts.asset.Cash
import net.corda.core.contracts.StateAndRef
import net.corda.core.crypto.AnonymousParty
import net.corda.core.crypto.Party
import tornadofx.*
/**
@ -81,3 +87,7 @@ inline fun <reified M : Any> UIComponent.getModel(): M = Models.get(M::class, th
// Cartesian product of 2 collections.
fun <A, B> Collection<A>.cross(other: Collection<B>) = this.flatMap { a -> other.map { b -> a to b } }
// TODO: This is a temporary fix for the UI to shows the correct issuer identity, this will break when we start randomizing keys. More work is needed here when the identity work is done.
fun StateAndRef<Cash.State>.resolveIssuer(): ObservableValue<Party?> = state.data.amount.token.issuer.party.resolveIssuer()
fun AnonymousParty.resolveIssuer(): ObservableValue<Party?> = Models.get(NetworkIdentityModel::class, javaClass.kotlin).lookup(owningKey).map { it?.legalIdentity }

View File

@ -15,10 +15,7 @@ import javafx.scene.control.TableView
import javafx.scene.control.TitledPane
import javafx.scene.layout.BorderPane
import javafx.scene.layout.VBox
import net.corda.client.fxutils.filterNotNull
import net.corda.client.fxutils.lift
import net.corda.client.fxutils.map
import net.corda.client.fxutils.sequence
import net.corda.client.fxutils.*
import net.corda.client.model.*
import net.corda.contracts.asset.Cash
import net.corda.core.contracts.*
@ -219,7 +216,8 @@ class TransactionViewer : CordaView("Transactions") {
}
row {
label("Issuer :") { gridpaneConstraints { hAlignment = HPos.RIGHT } }
label("${data.amount.token.issuer}") {
val issuer = data.amount.token.issuer.party.resolveIssuer()
label(issuer.map { it?.name }) {
tooltip(data.amount.token.issuer.party.owningKey.toBase58String())
}
}

View File

@ -22,7 +22,6 @@ import net.corda.contracts.asset.Cash
import net.corda.core.contracts.Amount
import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.withoutIssuer
import net.corda.core.crypto.AnonymousParty
import net.corda.core.crypto.Party
import net.corda.explorer.formatters.AmountFormatter
import net.corda.explorer.identicon.identicon
@ -32,10 +31,7 @@ import net.corda.explorer.model.CordaWidget
import net.corda.explorer.model.ReportingCurrencyModel
import net.corda.explorer.model.SettingsModel
import net.corda.explorer.ui.*
import net.corda.explorer.views.SearchField
import net.corda.explorer.views.runInFxApplicationThread
import net.corda.explorer.views.stringConverter
import net.corda.explorer.views.toStringWithSuffix
import net.corda.explorer.views.*
import org.fxmisc.easybind.EasyBind
import tornadofx.*
import java.time.Instant
@ -85,7 +81,7 @@ class CashViewer : CordaView("Cash") {
*/
sealed class ViewerNode(val equivAmount: ObservableValue<out Amount<Currency>>,
val states: ObservableList<StateAndRef<Cash.State>>) {
class IssuerNode(val issuer: AnonymousParty,
class IssuerNode(val issuer: ObservableValue<Party?>,
sumEquivAmount: ObservableValue<out Amount<Currency>>,
states: ObservableList<StateAndRef<Cash.State>>) : ViewerNode(sumEquivAmount, states)
@ -127,7 +123,7 @@ class CashViewer : CordaView("Cash") {
tooltip = identiconToolTip(stateRow.stateAndRef.ref.txhash)
}
equivLabel.textProperty().bind(equivAmount.map { it.token.currencyCode.toString() })
issuerValueLabel.text = stateRow.stateAndRef.state.data.amount.token.issuer.toString()
issuerValueLabel.textProperty().bind(stateRow.stateAndRef.resolveIssuer().map { it?.name })
originatedValueLabel.text = stateRow.originated.toString()
amountValueLabel.text = amountFormatter.format(amountNoIssuer)
equivValueLabel.textProperty().bind(equivAmount.map { equivFormatter.format(it) })
@ -144,7 +140,7 @@ class CashViewer : CordaView("Cash") {
*/
val searchField = SearchField(cashStates,
"Currency" to { state, text -> state.state.data.amount.token.product.toString().contains(text, true) },
"Issuer" to { state, text -> state.state.data.amount.token.issuer.party.toString().contains(text, true) }
"Issuer" to { state, text -> state.resolveIssuer().value?.name?.contains(text, true) ?: false }
)
root.top = hbox(5.0) {
button("New Transaction", FontAwesomeIconView(FontAwesomeIcon.PLUS)) {
@ -201,7 +197,7 @@ class CashViewer : CordaView("Cash") {
/**
* Assemble the Issuer node.
*/
val treeItem = TreeItem(ViewerNode.IssuerNode(issuer, equivSumAmount, memberStates))
val treeItem = TreeItem(ViewerNode.IssuerNode(issuer.resolveIssuer(), equivSumAmount, memberStates))
/**
* Bind the children in the TreeTable structure.
@ -230,7 +226,7 @@ class CashViewer : CordaView("Cash") {
cashViewerTableIssuerCurrency.setCellValueFactory {
val node = it.value.value
when (node) {
is ViewerNode.IssuerNode -> node.issuer.toString().lift()
is ViewerNode.IssuerNode -> node.issuer.map { it?.name }
is ViewerNode.CurrencyNode -> node.amount.map { it.token.toString() }
}
}