Add new RPC operation getCashBalances() to Node.

This commit is contained in:
Chris Rankin 2017-02-02 12:04:10 +00:00
parent cd5dde70e0
commit 4cc377cbf4
4 changed files with 27 additions and 0 deletions

View File

@ -65,4 +65,14 @@ class CordaRPCClientTest : DriverBasedTest() {
}
println("Result: ${flowHandle.returnValue.toBlocking().first()}")
}
@Test
fun `get cash balances`() {
println("Starting client")
client.start(rpcUser.username, rpcUser.password)
println("Creating proxy")
val proxy = client.proxy()
val cash = proxy.getCashBalances()
println("Cash Balances: $cash")
}
}

View File

@ -1,5 +1,6 @@
package net.corda.core.messaging
import net.corda.core.contracts.Amount
import net.corda.core.contracts.ContractState
import net.corda.core.contracts.StateAndRef
import net.corda.core.crypto.CompositeKey
@ -15,6 +16,7 @@ import net.corda.core.transactions.SignedTransaction
import rx.Observable
import java.io.InputStream
import java.time.Instant
import java.util.*
data class StateMachineInfo(
val id: StateMachineRunId,
@ -92,6 +94,12 @@ interface CordaRPCOps : RPCOps {
*/
fun getVaultTransactionNotes(txnId: SecureHash): Iterable<String>
/*
* Returns a map of how much cash we have in each currency, ignoring details like issuer. Note: currencies for
* which we have no cash evaluate to null (not present in map), not 0.
*/
fun getCashBalances(): Map<Currency, Amount<Currency>>
/**
* Checks whether an attachment with the given hash is stored on the node.
*/

View File

@ -1,5 +1,6 @@
package net.corda.node.internal
import net.corda.core.contracts.Amount
import net.corda.core.contracts.ContractState
import net.corda.core.contracts.StateAndRef
import net.corda.core.crypto.CompositeKey
@ -27,6 +28,7 @@ import org.jetbrains.exposed.sql.Database
import rx.Observable
import java.io.InputStream
import java.time.Instant
import java.util.*
/**
* Server side implementations of RPCs available to MQ based client tools. Execution takes place on the server
@ -90,6 +92,12 @@ class CordaRPCOpsImpl(
}
}
override fun getCashBalances(): Map<Currency, Amount<Currency>> {
return databaseTransaction(database) {
services.vaultService.cashBalances
}
}
// TODO: Check that this flow is annotated as being intended for RPC invocation
override fun <T : Any> startFlowDynamic(logicType: Class<out FlowLogic<T>>, vararg args: Any?): FlowHandle<T> {
requirePermission(startFlowPermission(logicType))

View File

@ -175,6 +175,7 @@ private class RPCKryo(observableSerializer: Serializer<Observable<Any>>? = null)
register(UUID::class.java)
register(UniqueIdentifier::class.java)
register(LinkedHashSet::class.java)
register(HashMap::class.java)
register(StateAndRef::class.java)
register(setOf<Unit>().javaClass) // EmptySet
register(StateRef::class.java)