mirror of
https://github.com/corda/corda.git
synced 2025-05-02 16:53:22 +00:00
For convenience, creates RPC snapshot methods for feeds.
This commit is contained in:
parent
eb925904ce
commit
ccdab6af4d
@ -65,8 +65,8 @@ public class StandaloneCordaRPCJavaClientTest {
|
||||
}
|
||||
|
||||
private NodeInfo fetchNotaryIdentity() {
|
||||
DataFeed<List<NodeInfo>, NetworkMapCache.MapChange> nodeDataFeed = rpcProxy.networkMapFeed();
|
||||
return nodeDataFeed.getSnapshot().get(0);
|
||||
List<NodeInfo> nodeDataSnapshot = rpcProxy.networkMapSnapshot();
|
||||
return nodeDataSnapshot.get(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -202,8 +202,7 @@ class StandaloneCordaRPClientTest {
|
||||
}
|
||||
|
||||
private fun fetchNotaryIdentity(): NodeInfo {
|
||||
val (nodeInfo, nodeUpdates) = rpcProxy.networkMapFeed()
|
||||
nodeUpdates.notUsed()
|
||||
val nodeInfo = rpcProxy.networkMapSnapshot()
|
||||
assertEquals(1, nodeInfo.size)
|
||||
return nodeInfo[0]
|
||||
}
|
||||
|
@ -60,6 +60,11 @@ interface CordaRPCOps : RPCOps {
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@ -151,12 +156,22 @@ interface CordaRPCOps : RPCOps {
|
||||
}
|
||||
// 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.
|
||||
*/
|
||||
@RPCReturnsObservables
|
||||
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
|
||||
* such mappings as well.
|
||||
@ -164,6 +179,11 @@ interface CordaRPCOps : RPCOps {
|
||||
@RPCReturnsObservables
|
||||
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.
|
||||
*/
|
||||
|
@ -112,8 +112,7 @@ fun generateTransactions(proxy: CordaRPCOps) {
|
||||
sum + state.state.data.amount.quantity
|
||||
}
|
||||
val issueRef = OpaqueBytes.of(0)
|
||||
val (parties, partyUpdates) = proxy.networkMapFeed()
|
||||
partyUpdates.notUsed()
|
||||
val parties = proxy.networkMapSnapshot()
|
||||
val notary = parties.first { it.advertisedServices.any { it.info.type.isNotary() } }.notaryIdentity
|
||||
val me = proxy.nodeIdentity().legalIdentity
|
||||
while (true) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.corda.node.internal
|
||||
|
||||
import net.corda.client.rpc.notUsed
|
||||
import net.corda.core.contracts.ContractState
|
||||
import net.corda.core.contracts.StateAndRef
|
||||
import net.corda.core.contracts.UpgradedContract
|
||||
@ -39,6 +40,12 @@ class CordaRPCOpsImpl(
|
||||
private val smm: StateMachineManager,
|
||||
private val database: CordaPersistence
|
||||
) : CordaRPCOps {
|
||||
override fun networkMapSnapshot(): List<NodeInfo> {
|
||||
val (snapshot, updates) = networkMapFeed()
|
||||
updates.notUsed()
|
||||
return snapshot
|
||||
}
|
||||
|
||||
override fun networkMapFeed(): DataFeed<List<NodeInfo>, NetworkMapCache.MapChange> {
|
||||
return database.transaction {
|
||||
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> {
|
||||
return database.transaction {
|
||||
services.validatedTransactions.track()
|
||||
}
|
||||
}
|
||||
|
||||
override fun stateMachinesSnapshot(): List<StateMachineInfo> {
|
||||
val (snapshot, updates) = stateMachinesFeed()
|
||||
updates.notUsed()
|
||||
return snapshot
|
||||
}
|
||||
|
||||
override fun stateMachinesFeed(): DataFeed<List<StateMachineInfo>, StateMachineUpdate> {
|
||||
return database.transaction {
|
||||
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> {
|
||||
return database.transaction {
|
||||
services.stateMachineRecordedTransactionMapping.track()
|
||||
|
@ -27,15 +27,13 @@ fun main(args: Array<String>) {
|
||||
/** Interface for using the notary demo API from a client. */
|
||||
private class NotaryDemoClientApi(val rpc: CordaRPCOps) {
|
||||
private val notary by lazy {
|
||||
val (parties, partyUpdates) = rpc.networkMapFeed()
|
||||
partyUpdates.notUsed()
|
||||
val parties = rpc.networkMapSnapshot()
|
||||
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." }
|
||||
}
|
||||
|
||||
private val counterpartyNode by lazy {
|
||||
val (parties, partyUpdates) = rpc.networkMapFeed()
|
||||
partyUpdates.notUsed()
|
||||
val parties = rpc.networkMapSnapshot()
|
||||
parties.single { it.legalIdentity.name == BOB.name }
|
||||
}
|
||||
|
||||
|
@ -253,8 +253,7 @@ class PortfolioApi(val rpc: CordaRPCOps) {
|
||||
@Path("whoami")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
fun getWhoAmI(): AvailableParties {
|
||||
val (parties, partyUpdates) = rpc.networkMapFeed()
|
||||
partyUpdates.notUsed()
|
||||
val parties = rpc.networkMapSnapshot()
|
||||
val counterParties = parties.filterNot {
|
||||
it.advertisedServices.any { it.info.type in setOf(ServiceType.networkMap, ServiceType.notary) }
|
||||
|| it.legalIdentity == ownParty
|
||||
|
@ -181,8 +181,7 @@ fun runLoadTests(configuration: LoadTestConfiguration, tests: List<Pair<LoadTest
|
||||
log.info("Getting node info of ${connection.remoteNode.hostname}")
|
||||
val info = connection.info
|
||||
log.info("Got node info of ${connection.remoteNode.hostname}: $info!")
|
||||
val (otherInfo, infoUpdates) = connection.proxy.networkMapFeed()
|
||||
infoUpdates.notUsed()
|
||||
val otherInfo = connection.proxy.networkMapSnapshot()
|
||||
val pubKeysString = otherInfo.map {
|
||||
" ${it.legalIdentity.name}: ${it.legalIdentity.owningKey.toBase58String()}"
|
||||
}.joinToString("\n")
|
||||
|
Loading…
x
Reference in New Issue
Block a user