mirror of
https://github.com/corda/corda.git
synced 2025-06-13 04:38:19 +00:00
Updated samples and demos to use new Vault Query service. (#924)
* Updated all sample code to use new Vault Query service APIs. * Fix broken Unit test. * Added missing transaction boundary. * Fix broken ScheduledFlow test (caused by assertion on non-ordered collection) * Remove redundant negative test (as new Vault Query no longer returns iterators). * Whitespace formatting fixed following PR review from SA. * Force query to specify a PAGE SIZE equivalent to total states to be exited (RP review comment). * Use single (and fail fast) instead of first - when only expecting a single result. * Demonstrate paging and sorting; failfast on single expected result. * Enhancement: added Sorting by CommonStateAttribute (StateRef txnId and index) * Fix: incorrect total states count. * Fixed incorrect total states counting. * Remove redundant filter (UNCONSUMED). * Updated tutorial code and associated documentation (building transactions). * Updated all vaultAndUpdates to vault[Track|Query]By. * Temporary disable failing Vault Query tests (awaiting pagination PR fix). * Rebase from master to pick up pagination changes/fix. * Fixed criteria filter on track. * Cleanup redundant print output. * Refactor to extract common function for Vault Query paging and sorting. * Identified problem in SimmValuation demo failing test caused by query by single participant in participants list (not yet supported in VaultQuery criteria). * Minor fixes following rebase from master. * Minor updates following rebase. * Removed redundant import. * Fixed type casting error. * Minor fixes following rebase from master. * VQ Fix - applied in other PR. * Removed duplication after rebase and minor fix to failing smoke test.
This commit is contained in:
@ -1,21 +1,23 @@
|
||||
package net.corda.traderdemo
|
||||
|
||||
import com.google.common.util.concurrent.Futures
|
||||
import net.corda.client.rpc.notUsed
|
||||
import net.corda.contracts.CommercialPaper
|
||||
import net.corda.contracts.asset.Cash
|
||||
import net.corda.contracts.getCashBalance
|
||||
import net.corda.core.contracts.Amount
|
||||
import net.corda.core.contracts.DOLLARS
|
||||
import net.corda.core.contracts.USD
|
||||
import net.corda.core.contracts.filterStatesOfType
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.internal.Emoji
|
||||
import net.corda.core.messaging.CordaRPCOps
|
||||
import net.corda.core.messaging.startFlow
|
||||
import net.corda.core.messaging.vaultQueryBy
|
||||
import net.corda.core.node.services.vault.QueryCriteria
|
||||
import net.corda.core.node.services.vault.builder
|
||||
import net.corda.core.utilities.OpaqueBytes
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import net.corda.flows.IssuerFlow.IssuanceRequester
|
||||
import net.corda.node.services.vault.VaultSchemaV1
|
||||
import net.corda.testing.BOC
|
||||
import net.corda.testing.DUMMY_NOTARY
|
||||
import net.corda.testing.contracts.calculateRandomlySizedAmounts
|
||||
@ -31,18 +33,18 @@ class TraderDemoClientApi(val rpc: CordaRPCOps) {
|
||||
val logger = loggerFor<TraderDemoClientApi>()
|
||||
}
|
||||
|
||||
val cashCount: Int get() {
|
||||
val (vault, vaultUpdates) = rpc.vaultAndUpdates()
|
||||
vaultUpdates.notUsed()
|
||||
return vault.filterStatesOfType<Cash.State>().size
|
||||
val cashCount: Long get() {
|
||||
val count = builder { VaultSchemaV1.VaultStates::recordedTime.count() }
|
||||
val countCriteria = QueryCriteria.VaultCustomQueryCriteria(count)
|
||||
return rpc.vaultQueryBy<Cash.State>(countCriteria).otherResults.single() as Long
|
||||
}
|
||||
|
||||
val dollarCashBalance: Amount<Currency> get() = rpc.getCashBalance(USD)
|
||||
|
||||
val commercialPaperCount: Int get() {
|
||||
val (vault, vaultUpdates) = rpc.vaultAndUpdates()
|
||||
vaultUpdates.notUsed()
|
||||
return vault.filterStatesOfType<CommercialPaper.State>().size
|
||||
val commercialPaperCount: Long get() {
|
||||
val count = builder { VaultSchemaV1.VaultStates::recordedTime.count() }
|
||||
val countCriteria = QueryCriteria.VaultCustomQueryCriteria(count)
|
||||
return rpc.vaultQueryBy<CommercialPaper.State>(countCriteria).otherResults.single() as Long
|
||||
}
|
||||
|
||||
fun runBuyer(amount: Amount<Currency> = 30000.DOLLARS, anonymous: Boolean = true) {
|
||||
|
Reference in New Issue
Block a user