node: Expose LedgerTransactions instead of SignedTransactions in WalletMonitor

This commit is contained in:
Andras Slemmer 2016-09-02 17:15:59 +01:00
parent 767077c764
commit eb82e946d0
2 changed files with 20 additions and 8 deletions

View File

@ -10,8 +10,8 @@ import java.util.*
* Events triggered by changes in the node, and sent to monitoring client(s). * Events triggered by changes in the node, and sent to monitoring client(s).
*/ */
sealed class ServiceToClientEvent(val time: Instant) { sealed class ServiceToClientEvent(val time: Instant) {
class Transaction(time: Instant, val transaction: SignedTransaction) : ServiceToClientEvent(time) { class Transaction(time: Instant, val transaction: LedgerTransaction) : ServiceToClientEvent(time) {
override fun toString() = "Transaction(${transaction.tx.commands})" override fun toString() = "Transaction(${transaction.commands})"
} }
class OutputState( class OutputState(
time: Instant, time: Instant,
@ -46,7 +46,7 @@ sealed class TransactionBuildResult {
* *
* @param transaction the transaction created as a result, in the case where the protocol has completed. * @param transaction the transaction created as a result, in the case where the protocol has completed.
*/ */
class ProtocolStarted(val fiberId: Long, val transaction: SignedTransaction?, val message: String?) : TransactionBuildResult() { class ProtocolStarted(val fiberId: Long, val transaction: LedgerTransaction?, val message: String?) : TransactionBuildResult() {
override fun toString() = "Started($message)" override fun toString() = "Started($message)"
} }

View File

@ -59,7 +59,7 @@ class WalletMonitorService(services: ServiceHubInternal, val smm: StateMachineMa
addMessageHandler(OUT_EVENT_TOPIC) { req: ClientToServiceCommandMessage -> processEventRequest(req) } addMessageHandler(OUT_EVENT_TOPIC) { req: ClientToServiceCommandMessage -> processEventRequest(req) }
// Notify listeners on state changes // Notify listeners on state changes
services.storageService.validatedTransactions.updates.subscribe { tx -> notifyTransaction(tx) } services.storageService.validatedTransactions.updates.subscribe { tx -> notifyTransaction(tx.tx.toLedgerTransaction(services)) }
services.walletService.updates.subscribe { update -> notifyWalletUpdate(update) } services.walletService.updates.subscribe { update -> notifyWalletUpdate(update) }
smm.changes.subscribe { change -> smm.changes.subscribe { change ->
val fiberId: Long = change.third val fiberId: Long = change.third
@ -85,7 +85,7 @@ class WalletMonitorService(services: ServiceHubInternal, val smm: StateMachineMa
= notifyEvent(ServiceToClientEvent.OutputState(Instant.now(), update.consumed, update.produced)) = notifyEvent(ServiceToClientEvent.OutputState(Instant.now(), update.consumed, update.produced))
@VisibleForTesting @VisibleForTesting
internal fun notifyTransaction(transaction: SignedTransaction) internal fun notifyTransaction(transaction: LedgerTransaction)
= notifyEvent(ServiceToClientEvent.Transaction(Instant.now(), transaction)) = notifyEvent(ServiceToClientEvent.Transaction(Instant.now(), transaction))
private fun processEventRequest(reqMessage: ClientToServiceCommandMessage) { private fun processEventRequest(reqMessage: ClientToServiceCommandMessage) {
@ -165,7 +165,11 @@ class WalletMonitorService(services: ServiceHubInternal, val smm: StateMachineMa
} }
val tx = builder.toSignedTransaction(checkSufficientSignatures = false) val tx = builder.toSignedTransaction(checkSufficientSignatures = false)
val protocol = FinalityProtocol(tx, setOf(req), setOf(req.recipient)) val protocol = FinalityProtocol(tx, setOf(req), setOf(req.recipient))
return TransactionBuildResult.ProtocolStarted(smm.add(BroadcastTransactionProtocol.TOPIC, protocol).machineId, tx, "Cash payment transaction generated") return TransactionBuildResult.ProtocolStarted(
smm.add(BroadcastTransactionProtocol.TOPIC, protocol).machineId,
tx.tx.toLedgerTransaction(services),
"Cash payment transaction generated"
)
} catch(ex: InsufficientBalanceException) { } catch(ex: InsufficientBalanceException) {
return TransactionBuildResult.Failed(ex.message ?: "Insufficient balance") return TransactionBuildResult.Failed(ex.message ?: "Insufficient balance")
} }
@ -194,7 +198,11 @@ class WalletMonitorService(services: ServiceHubInternal, val smm: StateMachineMa
// Commit the transaction // Commit the transaction
val tx = builder.toSignedTransaction(checkSufficientSignatures = false) val tx = builder.toSignedTransaction(checkSufficientSignatures = false)
val protocol = FinalityProtocol(tx, setOf(req), participants) val protocol = FinalityProtocol(tx, setOf(req), participants)
return TransactionBuildResult.ProtocolStarted(smm.add(BroadcastTransactionProtocol.TOPIC, protocol).machineId, tx, "Cash destruction transaction generated") return TransactionBuildResult.ProtocolStarted(
smm.add(BroadcastTransactionProtocol.TOPIC, protocol).machineId,
tx.tx.toLedgerTransaction(services),
"Cash destruction transaction generated"
)
} }
// TODO: Make a lightweight protocol that manages this workflow, rather than embedding it directly in the service // TODO: Make a lightweight protocol that manages this workflow, rather than embedding it directly in the service
@ -206,7 +214,11 @@ class WalletMonitorService(services: ServiceHubInternal, val smm: StateMachineMa
val tx = builder.toSignedTransaction(checkSufficientSignatures = true) val tx = builder.toSignedTransaction(checkSufficientSignatures = true)
// Issuance transactions do not need to be notarised, so we can skip directly to broadcasting it // Issuance transactions do not need to be notarised, so we can skip directly to broadcasting it
val protocol = BroadcastTransactionProtocol(tx, setOf(req), setOf(req.recipient)) val protocol = BroadcastTransactionProtocol(tx, setOf(req), setOf(req.recipient))
return TransactionBuildResult.ProtocolStarted(smm.add(BroadcastTransactionProtocol.TOPIC, protocol).machineId, tx, "Cash issuance completed") return TransactionBuildResult.ProtocolStarted(
smm.add(BroadcastTransactionProtocol.TOPIC, protocol).machineId,
tx.tx.toLedgerTransaction(services),
"Cash issuance completed"
)
} }
class InputStateRefResolveFailed(stateRefs: List<StateRef>) : class InputStateRefResolveFailed(stateRefs: List<StateRef>) :