For convenience, creates RPC snapshot methods for feeds.

This commit is contained in:
Joel Dudley 2017-08-15 16:18:15 +01:00 committed by GitHub
parent eb925904ce
commit ccdab6af4d
8 changed files with 53 additions and 14 deletions

View File

@ -65,8 +65,8 @@ public class StandaloneCordaRPCJavaClientTest {
} }
private NodeInfo fetchNotaryIdentity() { private NodeInfo fetchNotaryIdentity() {
DataFeed<List<NodeInfo>, NetworkMapCache.MapChange> nodeDataFeed = rpcProxy.networkMapFeed(); List<NodeInfo> nodeDataSnapshot = rpcProxy.networkMapSnapshot();
return nodeDataFeed.getSnapshot().get(0); return nodeDataSnapshot.get(0);
} }
@Test @Test

View File

@ -202,8 +202,7 @@ class StandaloneCordaRPClientTest {
} }
private fun fetchNotaryIdentity(): NodeInfo { private fun fetchNotaryIdentity(): NodeInfo {
val (nodeInfo, nodeUpdates) = rpcProxy.networkMapFeed() val nodeInfo = rpcProxy.networkMapSnapshot()
nodeUpdates.notUsed()
assertEquals(1, nodeInfo.size) assertEquals(1, nodeInfo.size)
return nodeInfo[0] return nodeInfo[0]
} }

View File

@ -60,6 +60,11 @@ interface CordaRPCOps : RPCOps {
*/ */
override val protocolVersion: Int get() = nodeIdentity().platformVersion override val protocolVersion: Int get() = nodeIdentity().platformVersion
/**
* Returns a list of currently in-progress state machine infos.
*/
fun stateMachinesSnapshot(): List<StateMachineInfo>
/** /**
* Returns a data feed of currently in-progress state machine infos and an observable of future state machine adds/removes. * Returns a data feed of currently in-progress state machine infos and an observable of future state machine adds/removes.
*/ */
@ -151,12 +156,22 @@ interface CordaRPCOps : RPCOps {
} }
// DOCEND VaultTrackAPIHelpers // DOCEND VaultTrackAPIHelpers
/**
* Returns a list of all recorded transactions.
*/
fun verifiedTransactionsSnapshot(): List<SignedTransaction>
/** /**
* Returns a data feed of all recorded transactions and an observable of future recorded ones. * Returns a data feed of all recorded transactions and an observable of future recorded ones.
*/ */
@RPCReturnsObservables @RPCReturnsObservables
fun verifiedTransactionsFeed(): DataFeed<List<SignedTransaction>, SignedTransaction> fun verifiedTransactionsFeed(): DataFeed<List<SignedTransaction>, SignedTransaction>
/**
* Returns a snapshot list of existing state machine id - recorded transaction hash mappings.
*/
fun stateMachineRecordedTransactionMappingSnapshot(): List<StateMachineTransactionMapping>
/** /**
* Returns a snapshot list of existing state machine id - recorded transaction hash mappings, and a stream of future * Returns a snapshot list of existing state machine id - recorded transaction hash mappings, and a stream of future
* such mappings as well. * such mappings as well.
@ -164,6 +179,11 @@ interface CordaRPCOps : RPCOps {
@RPCReturnsObservables @RPCReturnsObservables
fun stateMachineRecordedTransactionMappingFeed(): DataFeed<List<StateMachineTransactionMapping>, StateMachineTransactionMapping> fun stateMachineRecordedTransactionMappingFeed(): DataFeed<List<StateMachineTransactionMapping>, StateMachineTransactionMapping>
/**
* Returns all parties currently visible on the network with their advertised services.
*/
fun networkMapSnapshot(): List<NodeInfo>
/** /**
* Returns all parties currently visible on the network with their advertised services and an observable of future updates to the network. * Returns all parties currently visible on the network with their advertised services and an observable of future updates to the network.
*/ */

View File

@ -112,8 +112,7 @@ fun generateTransactions(proxy: CordaRPCOps) {
sum + state.state.data.amount.quantity sum + state.state.data.amount.quantity
} }
val issueRef = OpaqueBytes.of(0) val issueRef = OpaqueBytes.of(0)
val (parties, partyUpdates) = proxy.networkMapFeed() val parties = proxy.networkMapSnapshot()
partyUpdates.notUsed()
val notary = parties.first { it.advertisedServices.any { it.info.type.isNotary() } }.notaryIdentity val notary = parties.first { it.advertisedServices.any { it.info.type.isNotary() } }.notaryIdentity
val me = proxy.nodeIdentity().legalIdentity val me = proxy.nodeIdentity().legalIdentity
while (true) { while (true) {

View File

@ -1,5 +1,6 @@
package net.corda.node.internal package net.corda.node.internal
import net.corda.client.rpc.notUsed
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.UpgradedContract import net.corda.core.contracts.UpgradedContract
@ -39,6 +40,12 @@ class CordaRPCOpsImpl(
private val smm: StateMachineManager, private val smm: StateMachineManager,
private val database: CordaPersistence private val database: CordaPersistence
) : CordaRPCOps { ) : CordaRPCOps {
override fun networkMapSnapshot(): List<NodeInfo> {
val (snapshot, updates) = networkMapFeed()
updates.notUsed()
return snapshot
}
override fun networkMapFeed(): DataFeed<List<NodeInfo>, NetworkMapCache.MapChange> { override fun networkMapFeed(): DataFeed<List<NodeInfo>, NetworkMapCache.MapChange> {
return database.transaction { return database.transaction {
services.networkMapCache.track() services.networkMapCache.track()
@ -64,12 +71,24 @@ class CordaRPCOpsImpl(
} }
} }
override fun verifiedTransactionsSnapshot(): List<SignedTransaction> {
val (snapshot, updates) = verifiedTransactionsFeed()
updates.notUsed()
return snapshot
}
override fun verifiedTransactionsFeed(): DataFeed<List<SignedTransaction>, SignedTransaction> { override fun verifiedTransactionsFeed(): DataFeed<List<SignedTransaction>, SignedTransaction> {
return database.transaction { return database.transaction {
services.validatedTransactions.track() services.validatedTransactions.track()
} }
} }
override fun stateMachinesSnapshot(): List<StateMachineInfo> {
val (snapshot, updates) = stateMachinesFeed()
updates.notUsed()
return snapshot
}
override fun stateMachinesFeed(): DataFeed<List<StateMachineInfo>, StateMachineUpdate> { override fun stateMachinesFeed(): DataFeed<List<StateMachineInfo>, StateMachineUpdate> {
return database.transaction { return database.transaction {
val (allStateMachines, changes) = smm.track() val (allStateMachines, changes) = smm.track()
@ -80,6 +99,12 @@ class CordaRPCOpsImpl(
} }
} }
override fun stateMachineRecordedTransactionMappingSnapshot(): List<StateMachineTransactionMapping> {
val (snapshot, updates) = stateMachineRecordedTransactionMappingFeed()
updates.notUsed()
return snapshot
}
override fun stateMachineRecordedTransactionMappingFeed(): DataFeed<List<StateMachineTransactionMapping>, StateMachineTransactionMapping> { override fun stateMachineRecordedTransactionMappingFeed(): DataFeed<List<StateMachineTransactionMapping>, StateMachineTransactionMapping> {
return database.transaction { return database.transaction {
services.stateMachineRecordedTransactionMapping.track() services.stateMachineRecordedTransactionMapping.track()

View File

@ -27,15 +27,13 @@ fun main(args: Array<String>) {
/** Interface for using the notary demo API from a client. */ /** Interface for using the notary demo API from a client. */
private class NotaryDemoClientApi(val rpc: CordaRPCOps) { private class NotaryDemoClientApi(val rpc: CordaRPCOps) {
private val notary by lazy { private val notary by lazy {
val (parties, partyUpdates) = rpc.networkMapFeed() val parties = rpc.networkMapSnapshot()
partyUpdates.notUsed()
val id = parties.stream().filter { it.advertisedServices.any { it.info.type.isNotary() } }.map { it.notaryIdentity }.distinct().asSequence().singleOrNull() val id = parties.stream().filter { it.advertisedServices.any { it.info.type.isNotary() } }.map { it.notaryIdentity }.distinct().asSequence().singleOrNull()
checkNotNull(id) { "No unique notary identity, try cleaning the node directories." } checkNotNull(id) { "No unique notary identity, try cleaning the node directories." }
} }
private val counterpartyNode by lazy { private val counterpartyNode by lazy {
val (parties, partyUpdates) = rpc.networkMapFeed() val parties = rpc.networkMapSnapshot()
partyUpdates.notUsed()
parties.single { it.legalIdentity.name == BOB.name } parties.single { it.legalIdentity.name == BOB.name }
} }

View File

@ -253,8 +253,7 @@ class PortfolioApi(val rpc: CordaRPCOps) {
@Path("whoami") @Path("whoami")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
fun getWhoAmI(): AvailableParties { fun getWhoAmI(): AvailableParties {
val (parties, partyUpdates) = rpc.networkMapFeed() val parties = rpc.networkMapSnapshot()
partyUpdates.notUsed()
val counterParties = parties.filterNot { val counterParties = parties.filterNot {
it.advertisedServices.any { it.info.type in setOf(ServiceType.networkMap, ServiceType.notary) } it.advertisedServices.any { it.info.type in setOf(ServiceType.networkMap, ServiceType.notary) }
|| it.legalIdentity == ownParty || it.legalIdentity == ownParty

View File

@ -181,8 +181,7 @@ fun runLoadTests(configuration: LoadTestConfiguration, tests: List<Pair<LoadTest
log.info("Getting node info of ${connection.remoteNode.hostname}") log.info("Getting node info of ${connection.remoteNode.hostname}")
val info = connection.info val info = connection.info
log.info("Got node info of ${connection.remoteNode.hostname}: $info!") log.info("Got node info of ${connection.remoteNode.hostname}: $info!")
val (otherInfo, infoUpdates) = connection.proxy.networkMapFeed() val otherInfo = connection.proxy.networkMapSnapshot()
infoUpdates.notUsed()
val pubKeysString = otherInfo.map { val pubKeysString = otherInfo.map {
" ${it.legalIdentity.name}: ${it.legalIdentity.owningKey.toBase58String()}" " ${it.legalIdentity.name}: ${it.legalIdentity.owningKey.toBase58String()}"
}.joinToString("\n") }.joinToString("\n")