Add StateMachine -> Recorded TX mapping stream and emit events on transaction records

This commit is contained in:
Andras Slemmer
2016-09-22 15:26:59 +01:00
parent 6c96517f6f
commit 5b10c207e0
28 changed files with 230 additions and 43 deletions

View File

@ -36,14 +36,6 @@ interface ServiceHub {
*/
fun recordTransactions(txs: Iterable<SignedTransaction>)
/**
* Given some [SignedTransaction]s, writes them to the local storage for validated transactions and then
* sends them to the vault for further processing.
*
* @param txs The transactions to record.
*/
fun recordTransactions(vararg txs: SignedTransaction) = recordTransactions(txs.toList())
/**
* Given a [StateRef] loads the referenced transaction and looks up the specified output [ContractState].
*
@ -60,4 +52,11 @@ interface ServiceHub {
* @throws IllegalProtocolLogicException or IllegalArgumentException if there are problems with the [logicType] or [args].
*/
fun <T : Any> invokeProtocolAsync(logicType: Class<out ProtocolLogic<T>>, vararg args: Any?): ListenableFuture<T>
}
}
/**
* Given some [SignedTransaction]s, writes them to the local storage for validated transactions and then
* sends them to the vault for further processing.
*
* @param txs The transactions to record.
*/
fun ServiceHub.recordTransactions(vararg txs: SignedTransaction) = recordTransactions(txs.toList())

View File

@ -186,6 +186,8 @@ interface StorageService {
/** Provides access to storage of arbitrary JAR files (which may contain only data, no code). */
val attachments: AttachmentStorage
val stateMachineRecordedTransactionMapping: StateMachineRecordedTransactionMappingStorage
/**
* Returns the legal identity that this node is configured with. Assumed to be initialised when the node is
* first installed.

View File

@ -0,0 +1,16 @@
package com.r3corda.core.node.services
import com.r3corda.core.crypto.SecureHash
import com.r3corda.core.protocols.StateMachineRunId
import rx.Observable
data class StateMachineTransactionMapping(val stateMachineRunId: StateMachineRunId, val transactionId: SecureHash)
/**
* This is the interface to storage storing state machine -> recorded tx mappings. Any time a transaction is recorded
* during a protocol run [addMapping] should be called.
*/
interface StateMachineRecordedTransactionMappingStorage {
fun addMapping(stateMachineRunId: StateMachineRunId, transactionId: SecureHash)
fun track(): Pair<List<StateMachineTransactionMapping>, Observable<StateMachineTransactionMapping>>
}

View File

@ -1,6 +1,7 @@
package com.r3corda.core.protocols
import co.paralleluniverse.fibers.Suspendable
import co.paralleluniverse.strands.Strand
import com.google.common.util.concurrent.ListenableFuture
import com.r3corda.core.crypto.Party
import com.r3corda.core.node.ServiceHub
@ -10,7 +11,7 @@ import java.util.*
data class StateMachineRunId private constructor(val uuid: UUID) {
companion object {
fun createRandom() = StateMachineRunId(UUID.randomUUID())
fun createRandom(): StateMachineRunId = StateMachineRunId(UUID.randomUUID())
}
}

View File

@ -7,6 +7,7 @@ import com.r3corda.core.contracts.StateRef
import com.r3corda.core.crypto.DigitalSignature
import com.r3corda.core.crypto.Party
import com.r3corda.core.crypto.signWithECDSA
import com.r3corda.core.node.recordTransactions
import com.r3corda.core.protocols.ProtocolLogic
import com.r3corda.core.random63BitValue
import com.r3corda.core.transactions.SignedTransaction
@ -66,7 +67,7 @@ abstract class AbstractStateReplacementProtocol<T> {
}
val finalTx = stx + signatures
serviceHub.recordTransactions(listOf(finalTx))
serviceHub.recordTransactions(finalTx)
return finalTx.tx.outRef(0)
}
@ -164,7 +165,7 @@ abstract class AbstractStateReplacementProtocol<T> {
val finalTx = stx + allSignatures
finalTx.verifySignatures()
serviceHub.recordTransactions(listOf(finalTx))
serviceHub.recordTransactions(finalTx)
}
@Suspendable
@ -219,4 +220,4 @@ class StateReplacementRefused(val identity: Party, val state: StateRef, val deta
override fun toString() = "A participant $identity refused to change state $state: " + (detail ?: "no reason provided")
}
class StateReplacementException(val error: StateReplacementRefused) : Exception("State change failed - $error")
class StateReplacementException(val error: StateReplacementRefused) : Exception("State change failed - $error")

View File

@ -3,6 +3,7 @@ package com.r3corda.protocols
import co.paralleluniverse.fibers.Suspendable
import com.r3corda.core.contracts.ClientToServiceCommand
import com.r3corda.core.crypto.Party
import com.r3corda.core.node.recordTransactions
import com.r3corda.core.protocols.ProtocolLogic
import com.r3corda.core.random63BitValue
import com.r3corda.core.transactions.SignedTransaction

View File

@ -4,6 +4,7 @@ import co.paralleluniverse.fibers.Suspendable
import com.r3corda.core.checkedAdd
import com.r3corda.core.crypto.Party
import com.r3corda.core.crypto.SecureHash
import com.r3corda.core.node.recordTransactions
import com.r3corda.core.protocols.ProtocolLogic
import com.r3corda.core.transactions.LedgerTransaction
import com.r3corda.core.transactions.SignedTransaction

View File

@ -7,6 +7,7 @@ import com.r3corda.core.crypto.DigitalSignature
import com.r3corda.core.crypto.Party
import com.r3corda.core.crypto.signWithECDSA
import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.recordTransactions
import com.r3corda.core.node.services.ServiceType
import com.r3corda.core.protocols.ProtocolLogic
import com.r3corda.core.random63BitValue
@ -139,7 +140,7 @@ object TwoPartyDealProtocol {
progressTracker.currentStep = RECORDING
serviceHub.recordTransactions(listOf(fullySigned))
serviceHub.recordTransactions(fullySigned)
logger.trace { "Deal stored" }
@ -219,7 +220,7 @@ object TwoPartyDealProtocol {
logger.trace { "Signatures received are valid. Deal transaction complete! :-)" }
progressTracker.currentStep = RECORDING
serviceHub.recordTransactions(listOf(fullySigned))
serviceHub.recordTransactions(fullySigned)
logger.trace { "Deal transaction stored" }
return fullySigned

View File

@ -5,6 +5,7 @@ import com.r3corda.core.transactions.SignedTransaction
import com.r3corda.core.crypto.NullSignature
import com.r3corda.core.crypto.Party
import com.r3corda.core.crypto.SecureHash
import com.r3corda.core.node.recordTransactions
import com.r3corda.core.serialization.opaque
import com.r3corda.core.utilities.DUMMY_NOTARY_KEY
import com.r3corda.testing.node.MockNetwork