From 818cbce789ce7f7392475624db3ac875da0b244c Mon Sep 17 00:00:00 2001 From: josecoll Date: Thu, 3 Aug 2017 17:45:53 +0100 Subject: [PATCH] Removed all deprecated Vault Service query code. (#1167) --- .../net/corda/core/messaging/CordaRPCOps.kt | 8 - .../corda/core/node/services/VaultService.kt | 42 ------ docs/source/api-vault-query.rst | 28 ---- .../net/corda/contracts/FinanceTypes.kt | 6 - .../corda/node/internal/CordaRPCOpsImpl.kt | 7 - .../node/services/vault/NodeVaultService.kt | 60 +------- .../services/vault/VaultQueryJavaTests.java | 137 ++++-------------- .../net/corda/node/CordaRPCOpsImplTest.kt | 26 ---- .../node/services/vault/VaultQueryTests.kt | 98 ------------- .../kotlin/net/corda/vega/flows/SimmFlow.kt | 21 ++- 10 files changed, 44 insertions(+), 389 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt b/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt index 1a27cb5786..5ffcbdbe6f 100644 --- a/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt +++ b/core/src/main/kotlin/net/corda/core/messaging/CordaRPCOps.kt @@ -151,14 +151,6 @@ interface CordaRPCOps : RPCOps { } // DOCEND VaultTrackAPIHelpers - /** - * Returns a data feed of head states in the vault and an observable of future updates to the vault. - */ - @RPCReturnsObservables - // TODO: Remove this from the interface - @Deprecated("This function will be removed in a future milestone", ReplaceWith("vaultTrackBy(QueryCriteria())")) - fun vaultAndUpdates(): DataFeed>, Vault.Update> - /** * Returns a data feed of all recorded transactions and an observable of future recorded ones. */ diff --git a/core/src/main/kotlin/net/corda/core/node/services/VaultService.kt b/core/src/main/kotlin/net/corda/core/node/services/VaultService.kt index 50b548ac3d..6a288de9e5 100644 --- a/core/src/main/kotlin/net/corda/core/node/services/VaultService.kt +++ b/core/src/main/kotlin/net/corda/core/node/services/VaultService.kt @@ -178,21 +178,6 @@ interface VaultService { */ val updatesPublisher: PublishSubject> - /** - * Atomically get the current vault and a stream of updates. Note that the Observable buffers updates until the - * first subscriber is registered so as to avoid racing with early updates. - */ - // TODO: Remove this from the interface - @Deprecated("This function will be removed in a future milestone", ReplaceWith("trackBy(QueryCriteria())")) - fun track(): DataFeed, Vault.Update> - - /** - * Return unconsumed [ContractState]s for a given set of [StateRef]s - */ - // TODO: Remove this from the interface - @Deprecated("This function will be removed in a future milestone", ReplaceWith("queryBy(VaultQueryCriteria(stateRefs = listOf()))")) - fun statesForRefs(refs: List): Map?> - /** * Possibly update the vault by marking as spent states that these transactions consume, and adding any relevant * new states that they create. You should only insert transactions that have been successfully verified here! @@ -263,16 +248,6 @@ interface VaultService { to: AbstractParty, onlyFromParties: Set? = null): Pair> - // DOCSTART VaultStatesQuery - /** - * Return [ContractState]s of a given [Contract] type and [Iterable] of [Vault.StateStatus]. - * Optionally may specify whether to include [StateRef] that have been marked as soft locked (default is true) - */ - // TODO: Remove this from the interface - @Deprecated("This function will be removed in a future milestone", ReplaceWith("queryBy(QueryCriteria())")) - fun states(clazzes: Set>, statuses: EnumSet, includeSoftLockedStates: Boolean = true): Iterable> - // DOCEND VaultStatesQuery - /** * Soft locking is used to prevent multiple transactions trying to use the same output simultaneously. * Violation of a soft lock would result in a double spend being created and rejected by the notary. @@ -319,23 +294,6 @@ interface VaultService { withIssuerRefs: Set? = null): List> } -// TODO: Remove this from the interface -@Deprecated("This function will be removed in a future milestone", ReplaceWith("queryBy(VaultQueryCriteria())")) -inline fun VaultService.unconsumedStates(includeSoftLockedStates: Boolean = true): Iterable> = - states(setOf(T::class.java), EnumSet.of(Vault.StateStatus.UNCONSUMED), includeSoftLockedStates) - -// TODO: Remove this from the interface -@Deprecated("This function will be removed in a future milestone", ReplaceWith("queryBy(VaultQueryCriteria(status = Vault.StateStatus.CONSUMED))")) -inline fun VaultService.consumedStates(): Iterable> = - states(setOf(T::class.java), EnumSet.of(Vault.StateStatus.CONSUMED)) - -/** Returns the [linearState] heads only when the type of the state would be considered an 'instanceof' the given type. */ -// TODO: Remove this from the interface -@Deprecated("This function will be removed in a future milestone", ReplaceWith("queryBy(LinearStateQueryCriteria(linearId = listOf()))")) -inline fun VaultService.linearHeadsOfType() = - states(setOf(T::class.java), EnumSet.of(Vault.StateStatus.UNCONSUMED)) - .associateBy { it.state.data.linearId }.mapValues { it.value } - class StatesNotAvailableException(override val message: String?, override val cause: Throwable? = null) : FlowException(message, cause) { override fun toString() = "Soft locking error: $message" } \ No newline at end of file diff --git a/docs/source/api-vault-query.rst b/docs/source/api-vault-query.rst index 099306bc30..abf0ffc760 100644 --- a/docs/source/api-vault-query.rst +++ b/docs/source/api-vault-query.rst @@ -185,13 +185,6 @@ Query for unconsumed linear states for given linear ids: :start-after: DOCSTART VaultQueryExample8 :end-before: DOCEND VaultQueryExample8 -This example was previously executed using the deprecated extension method: - -.. literalinclude:: ../../node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt - :language: kotlin - :start-after: DOCSTART VaultDeprecatedQueryExample1 - :end-before: DOCEND VaultDeprecatedQueryExample1 - Query for all linear states associated with a linear id: .. literalinclude:: ../../node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt @@ -199,13 +192,6 @@ Query for all linear states associated with a linear id: :start-after: DOCSTART VaultQueryExample9 :end-before: DOCEND VaultQueryExample9 -This example was previously executed using the deprecated method: - -.. literalinclude:: ../../node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt - :language: kotlin - :start-after: DOCSTART VaultDeprecatedQueryExample2 - :end-before: DOCEND VaultDeprecatedQueryExample2 - Query for unconsumed deal states with deals references: .. literalinclude:: ../../node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt @@ -313,13 +299,6 @@ Query for all unconsumed linear states: :start-after: DOCSTART VaultJavaQueryExample0 :end-before: DOCEND VaultJavaQueryExample0 -This example was previously executed using the deprecated method: - -.. literalinclude:: ../../node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java - :language: java - :start-after: DOCSTART VaultDeprecatedJavaQueryExample0 - :end-before: DOCEND VaultDeprecatedJavaQueryExample0 - Query for all consumed cash states: .. literalinclude:: ../../node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java @@ -327,13 +306,6 @@ Query for all consumed cash states: :start-after: DOCSTART VaultJavaQueryExample1 :end-before: DOCEND VaultJavaQueryExample1 -This example was previously executed using the deprecated method: - -.. literalinclude:: ../../node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java - :language: java - :start-after: DOCSTART VaultDeprecatedJavaQueryExample1 - :end-before: DOCEND VaultDeprecatedJavaQueryExample1 - Query for consumed deal states or linear ids, specify a paging specification and sort by unique identifier: .. literalinclude:: ../../node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java diff --git a/finance/src/main/kotlin/net/corda/contracts/FinanceTypes.kt b/finance/src/main/kotlin/net/corda/contracts/FinanceTypes.kt index 2de46bb8f2..253c5ee664 100644 --- a/finance/src/main/kotlin/net/corda/contracts/FinanceTypes.kt +++ b/finance/src/main/kotlin/net/corda/contracts/FinanceTypes.kt @@ -406,12 +406,6 @@ interface DealState : LinearState { fun generateAgreement(notary: Party): TransactionBuilder } -// TODO: Remove this from the interface -@Deprecated("This function will be removed in a future milestone", ReplaceWith("queryBy(LinearStateQueryCriteria(dealPartyName = listOf()))")) -inline fun VaultService.dealsWith(party: AbstractParty) = linearHeadsOfType().values.filter { - it.state.data.participants.any { it == party } -} - /** * Interface adding fixing specific methods. */ diff --git a/node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt b/node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt index 37e1694c5f..2bc78e1e2a 100644 --- a/node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt +++ b/node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt @@ -45,13 +45,6 @@ class CordaRPCOpsImpl( } } - override fun vaultAndUpdates(): DataFeed>, Vault.Update> { - return database.transaction { - val (vault, updates) = services.vaultService.track() - DataFeed(vault.states.toList(), updates) - } - } - override fun vaultQueryBy(criteria: QueryCriteria, paging: PageSpecification, sorting: Sort, diff --git a/node/src/main/kotlin/net/corda/node/services/vault/NodeVaultService.kt b/node/src/main/kotlin/net/corda/node/services/vault/NodeVaultService.kt index 58aa05035f..faf117e12d 100644 --- a/node/src/main/kotlin/net/corda/node/services/vault/NodeVaultService.kt +++ b/node/src/main/kotlin/net/corda/node/services/vault/NodeVaultService.kt @@ -4,10 +4,7 @@ import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.strands.Strand import com.google.common.annotations.VisibleForTesting import io.requery.PersistenceException -import io.requery.TransactionIsolation -import io.requery.kotlin.`in` import io.requery.kotlin.eq -import io.requery.kotlin.isNull import io.requery.kotlin.notNull import io.requery.query.RowExpression import net.corda.contracts.asset.Cash @@ -19,19 +16,19 @@ import net.corda.core.crypto.toBase58String import net.corda.core.identity.AbstractParty import net.corda.core.identity.Party import net.corda.core.internal.ThreadBox -import net.corda.core.internal.bufferUntilSubscribed import net.corda.core.internal.tee -import net.corda.core.messaging.DataFeed import net.corda.core.node.ServiceHub import net.corda.core.node.services.StatesNotAvailableException import net.corda.core.node.services.Vault import net.corda.core.node.services.VaultService -import net.corda.core.node.services.unconsumedStates import net.corda.core.serialization.SerializationDefaults.STORAGE_CONTEXT import net.corda.core.serialization.SingletonSerializeAsToken import net.corda.core.serialization.deserialize import net.corda.core.serialization.serialize -import net.corda.core.transactions.* +import net.corda.core.transactions.CoreTransaction +import net.corda.core.transactions.NotaryChangeWireTransaction +import net.corda.core.transactions.TransactionBuilder +import net.corda.core.transactions.WireTransaction import net.corda.core.utilities.* import net.corda.node.services.database.RequeryConfiguration import net.corda.node.services.database.parserTransactionIsolationLevel @@ -136,55 +133,6 @@ class NodeVaultService(private val services: ServiceHub, dataSourceProperties: P override val updatesPublisher: PublishSubject> get() = mutex.locked { _updatesPublisher } - override fun track(): DataFeed, Vault.Update> { - return mutex.locked { - DataFeed(Vault(unconsumedStates()), _updatesPublisher.bufferUntilSubscribed().wrapWithDatabaseTransaction()) - } - } - - override fun states(clazzes: Set>, statuses: EnumSet, includeSoftLockedStates: Boolean): Iterable> { - val stateAndRefs = - session.withTransaction(transactionIsolationLevel) { - val query = select(VaultSchema.VaultStates::class) - .where(VaultSchema.VaultStates::stateStatus `in` statuses) - // TODO: temporary fix to continue supporting track() function (until becomes Typed) - if (!clazzes.map { it.name }.contains(ContractState::class.java.name)) - query.and(VaultSchema.VaultStates::contractStateClassName `in` (clazzes.map { it.name })) - if (!includeSoftLockedStates) - query.and(VaultSchema.VaultStates::lockId.isNull()) - val iterator = query.get().iterator() - Sequence { iterator } - .map { it -> - val stateRef = StateRef(SecureHash.parse(it.txId), it.index) - val state = it.contractState.deserialize>(context = STORAGE_CONTEXT) - Vault.StateMetadata(stateRef, it.contractStateClassName, it.recordedTime, it.consumedTime, it.stateStatus, it.notaryName, it.notaryKey, it.lockId, it.lockUpdateTime) - StateAndRef(state, stateRef) - } - } - return stateAndRefs.asIterable() - } - - override fun statesForRefs(refs: List): Map?> { - val stateAndRefs = - session.withTransaction(transactionIsolationLevel) { - var results: List> = emptyList() - refs.forEach { - val result = select(VaultSchema.VaultStates::class) - .where(VaultSchema.VaultStates::stateStatus eq Vault.StateStatus.UNCONSUMED) - .and(VaultSchema.VaultStates::txId eq it.txhash.toString()) - .and(VaultSchema.VaultStates::index eq it.index) - result.get()?.each { - val stateRef = StateRef(SecureHash.parse(it.txId), it.index) - val state = it.contractState.deserialize>(context = STORAGE_CONTEXT) - results += StateAndRef(state, stateRef) - } - } - results - } - - return stateAndRefs.associateBy({ it.ref }, { it.state }) - } - /** * Splits the provided [txns] into batches of [WireTransaction] and [NotaryChangeWireTransaction]. * This is required because the batches get aggregated into single updates, and we want to be able to diff --git a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java index 6603736f30..3d754b9dcd 100644 --- a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java +++ b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java @@ -1,59 +1,42 @@ package net.corda.node.services.vault; -import com.google.common.collect.ImmutableSet; -import net.corda.contracts.DealState; -import net.corda.contracts.asset.Cash; +import com.google.common.collect.*; +import net.corda.contracts.*; +import net.corda.contracts.asset.*; import net.corda.core.contracts.*; -import net.corda.core.crypto.EncodingUtils; -import net.corda.core.crypto.SecureHash; -import net.corda.core.identity.AbstractParty; -import net.corda.core.messaging.DataFeed; -import net.corda.core.node.services.Vault; -import net.corda.core.node.services.VaultQueryException; -import net.corda.core.node.services.VaultQueryService; -import net.corda.core.node.services.VaultService; +import net.corda.core.crypto.*; +import net.corda.core.identity.*; +import net.corda.core.messaging.*; +import net.corda.core.node.services.*; import net.corda.core.node.services.vault.*; -import net.corda.core.node.services.vault.QueryCriteria.LinearStateQueryCriteria; -import net.corda.core.node.services.vault.QueryCriteria.VaultCustomQueryCriteria; -import net.corda.core.node.services.vault.QueryCriteria.VaultQueryCriteria; -import net.corda.core.schemas.MappedSchema; -import net.corda.core.transactions.SignedTransaction; -import net.corda.core.transactions.WireTransaction; -import net.corda.core.utilities.OpaqueBytes; -import net.corda.node.services.database.HibernateConfiguration; -import net.corda.node.services.schema.NodeSchemaService; -import net.corda.node.utilities.CordaPersistence; -import net.corda.schemas.CashSchemaV1; -import net.corda.testing.TestConstants; -import net.corda.testing.TestDependencyInjectionBase; -import net.corda.testing.contracts.DummyLinearContract; -import net.corda.testing.contracts.VaultFiller; -import net.corda.testing.node.MockServices; -import net.corda.testing.schemas.DummyLinearStateSchemaV1; -import org.jetbrains.annotations.NotNull; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import net.corda.core.node.services.vault.QueryCriteria.*; +import net.corda.core.schemas.*; +import net.corda.core.transactions.*; +import net.corda.core.utilities.*; +import net.corda.node.services.database.*; +import net.corda.node.services.schema.*; +import net.corda.node.utilities.*; +import net.corda.schemas.*; +import net.corda.testing.*; +import net.corda.testing.contracts.*; +import net.corda.testing.node.*; +import net.corda.testing.schemas.*; +import org.jetbrains.annotations.*; +import org.junit.*; import rx.Observable; -import java.io.IOException; -import java.lang.reflect.Field; +import java.io.*; +import java.lang.reflect.*; import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; +import java.util.stream.*; -import static net.corda.contracts.asset.CashKt.getDUMMY_CASH_ISSUER; -import static net.corda.contracts.asset.CashKt.getDUMMY_CASH_ISSUER_KEY; -import static net.corda.core.contracts.ContractsDSL.USD; -import static net.corda.core.node.services.vault.QueryCriteriaUtils.DEFAULT_PAGE_NUM; -import static net.corda.core.node.services.vault.QueryCriteriaUtils.MAX_PAGE_SIZE; -import static net.corda.core.utilities.ByteArrays.toHexString; -import static net.corda.node.utilities.CordaPersistenceKt.configureDatabase; +import static net.corda.contracts.asset.CashKt.*; +import static net.corda.core.node.services.vault.QueryCriteriaUtils.*; +import static net.corda.core.utilities.ByteArrays.*; +import static net.corda.node.utilities.CordaPersistenceKt.*; import static net.corda.testing.CoreTestUtils.*; -import static net.corda.testing.node.MockServicesKt.makeTestDataSourceProperties; -import static net.corda.testing.node.MockServicesKt.makeTestDatabaseProperties; -import static org.assertj.core.api.Assertions.assertThat; +import static net.corda.testing.node.MockServicesKt.*; +import static org.assertj.core.api.Assertions.*; public class VaultQueryJavaTests extends TestDependencyInjectionBase { @@ -338,66 +321,6 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { }); } - /** - * Deprecated usage - */ - - @Test - public void consumedStatesDeprecated() { - database.transaction(tx -> { - Amount amount = new Amount<>(100, USD); - VaultFiller.fillWithSomeTestCash(services, - new Amount<>(100, USD), - TestConstants.getDUMMY_NOTARY(), - 3, - 3, - new Random(), - new OpaqueBytes("1".getBytes()), - null, - getDUMMY_CASH_ISSUER(), - getDUMMY_CASH_ISSUER_KEY() ); - - VaultFiller.consumeCash(services, amount); - - // DOCSTART VaultDeprecatedJavaQueryExample1 - @SuppressWarnings("unchecked") - Set> contractStateTypes = new HashSet(Collections.singletonList(Cash.State.class)); - EnumSet status = EnumSet.of(Vault.StateStatus.CONSUMED); - - // WARNING! unfortunately cannot use inlined reified Kotlin extension methods. - Iterable> results = vaultSvc.states(contractStateTypes, status, true); - // DOCEND VaultDeprecatedJavaQueryExample1 - - assertThat(results).hasSize(3); - - return tx; - }); - } - - @Test - public void consumedStatesForLinearIdDeprecated() { - database.transaction(tx -> { - - Vault linearStates = VaultFiller.fillWithSomeTestLinearStates(services, 4,null); - linearStates.getStates().iterator().next().component1().getData().getLinearId(); - - VaultFiller.consumeLinearStates(services, (List>) linearStates.getStates()); - - // DOCSTART VaultDeprecatedJavaQueryExample0 - @SuppressWarnings("unchecked") - Set> contractStateTypes = new HashSet(Collections.singletonList(DummyLinearContract.State.class)); - EnumSet status = EnumSet.of(Vault.StateStatus.CONSUMED); - - // WARNING! unfortunately cannot use inlined reified Kotlin extension methods. - Iterable> results = vaultSvc.states(contractStateTypes, status, true); - // DOCEND VaultDeprecatedJavaQueryExample0 - - assertThat(results).hasSize(4); - - return tx; - }); - } - /** * Aggregation Functions */ diff --git a/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt b/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt index 368e219c7c..89bc391f29 100644 --- a/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt +++ b/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt @@ -53,7 +53,6 @@ class CordaRPCOpsImplTest { lateinit var rpc: CordaRPCOps lateinit var stateMachineUpdates: Observable lateinit var transactions: Observable - lateinit var vaultUpdates: Observable> // TODO: deprecated lateinit var vaultTrackCash: Observable> @Before @@ -71,7 +70,6 @@ class CordaRPCOpsImplTest { aliceNode.database.transaction { stateMachineUpdates = rpc.stateMachinesFeed().updates transactions = rpc.verifiedTransactionsFeed().updates - vaultUpdates = rpc.vaultAndUpdates().updates vaultTrackCash = rpc.vaultTrackBy().updates } } @@ -119,14 +117,6 @@ class CordaRPCOpsImplTest { val cash = rpc.vaultQueryBy() assertEquals(expectedState, cash.states.first().state.data) - // TODO: deprecated - vaultUpdates.expectEvents { - expect { update -> - val actual = update.produced.single().state.data - assertEquals(expectedState, actual) - } - } - vaultTrackCash.expectEvents { expect { update -> val actual = update.produced.single().state.data @@ -198,22 +188,6 @@ class CordaRPCOpsImplTest { ) } - // TODO: deprecated - vaultUpdates.expectEvents { - sequence( - // ISSUE - expect { (consumed, produced) -> - require(consumed.isEmpty()) { consumed.size } - require(produced.size == 1) { produced.size } - }, - // MOVE - expect { (consumed, produced) -> - require(consumed.size == 1) { consumed.size } - require(produced.size == 1) { produced.size } - } - ) - } - vaultTrackCash.expectEvents { sequence( // ISSUE diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt index 67393ebca1..a86637ed21 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt @@ -1307,104 +1307,6 @@ class VaultQueryTests : TestDependencyInjectionBase() { } } - @Test - fun `DEPRECATED unconsumed linear states for a given id`() { - database.transaction { - - val txns = services.fillWithSomeTestLinearStates(1, "TEST") - val linearState = txns.states.first() - val linearId = linearState.state.data.linearId - val linearState2 = services.evolveLinearState(linearState) // consume current and produce new state reference - val linearState3 = services.evolveLinearState(linearState2) // consume current and produce new state reference - services.evolveLinearState(linearState3) // consume current and produce new state reference - - // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" - - // DOCSTART VaultDeprecatedQueryExample1 - val states = vaultSvc.linearHeadsOfType().filter { it.key == linearId } - // DOCEND VaultDeprecatedQueryExample1 - assertThat(states).hasSize(1) - - // validate against new query api - val results = vaultQuerySvc.queryBy(LinearStateQueryCriteria(linearId = listOf(linearId))) - assertThat(results.statesMetadata).hasSize(1) - assertThat(results.states).hasSize(1) - } - } - - @Test - fun `DEPRECATED consumed linear states for a given id`() { - database.transaction { - - val txns = services.fillWithSomeTestLinearStates(1, "TEST") - val linearState = txns.states.first() - val linearId = linearState.state.data.linearId - val linearState2 = services.evolveLinearState(linearState) // consume current and produce new state reference - val linearState3 = services.evolveLinearState(linearState2) // consume current and produce new state reference - services.evolveLinearState(linearState3) // consume current and produce new state reference - - // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" - - // DOCSTART VaultDeprecatedQueryExample2 - val states = vaultSvc.consumedStates().filter { it.state.data.linearId == linearId } - // DOCEND VaultDeprecatedQueryExample2 - assertThat(states).hasSize(3) - - // validate against new query api - val results = vaultQuerySvc.queryBy(LinearStateQueryCriteria(linearId = listOf(linearId), status = Vault.StateStatus.CONSUMED)) - assertThat(results.statesMetadata).hasSize(3) - assertThat(results.states).hasSize(3) - } - } - - @Test - fun `DEPRECATED all linear states for a given id`() { - database.transaction { - - val txns = services.fillWithSomeTestLinearStates(1, "TEST") - val linearState = txns.states.first() - val linearId = linearState.state.data.linearId - services.evolveLinearState(linearState) // consume current and produce new state reference - services.evolveLinearState(linearState) // consume current and produce new state reference - services.evolveLinearState(linearState) // consume current and produce new state reference - - // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" - - // DOCSTART VaultDeprecatedQueryExample3 - val states = vaultSvc.states(setOf(DummyLinearContract.State::class.java), - EnumSet.of(Vault.StateStatus.CONSUMED, Vault.StateStatus.UNCONSUMED)).filter { it.state.data.linearId == linearId } - // DOCEND VaultDeprecatedQueryExample3 - assertThat(states).hasSize(4) - - // validate against new query api - val results = vaultQuerySvc.queryBy(LinearStateQueryCriteria(linearId = listOf(linearId), status = Vault.StateStatus.ALL)) - assertThat(results.statesMetadata).hasSize(4) - assertThat(results.states).hasSize(4) - } - } - - @Test - fun `DEPRECATED DealState dealsWith helper method`() { - database.transaction { - - // specify a different participant to the node owner (MEGA_CORP) - val parties = listOf(MINI_CORP) - - services.fillWithSomeTestLinearStates(2, "TEST") - services.fillWithSomeTestDeals(listOf("456"), parties) - services.fillWithSomeTestDeals(listOf("123", "789")) - - // DOCSTART VaultQueryExample11 - val criteria = LinearStateQueryCriteria(participants = parties) - val results = vaultQuerySvc.queryBy(criteria) - // DOCEND - assertThat(results.states).hasSize(1) - - val states = vaultSvc.dealsWith(MINI_CORP) - assertThat(states).hasSize(1) - } - } - /** * Deal Contract state to be removed as is duplicate of LinearState */ diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt index 560614187b..f61740a4f0 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt @@ -8,21 +8,17 @@ import com.opengamma.strata.pricer.curve.CalibrationMeasures import com.opengamma.strata.pricer.curve.CurveCalibrator import com.opengamma.strata.pricer.rate.ImmutableRatesProvider import com.opengamma.strata.pricer.swap.DiscountingSwapProductPricer -import net.corda.contracts.dealsWith import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateRef -import net.corda.core.flows.FlowLogic -import net.corda.core.flows.InitiatedBy -import net.corda.core.flows.InitiatingFlow -import net.corda.core.flows.StartableByRPC +import net.corda.core.flows.* +import net.corda.core.flows.AbstractStateReplacementFlow.Proposal import net.corda.core.identity.Party import net.corda.core.node.services.queryBy +import net.corda.core.node.services.vault.QueryCriteria.LinearStateQueryCriteria import net.corda.core.node.services.vault.QueryCriteria.VaultQueryCriteria import net.corda.core.serialization.CordaSerializable import net.corda.core.transactions.SignedTransaction import net.corda.core.utilities.unwrap -import net.corda.core.flows.AbstractStateReplacementFlow.Proposal -import net.corda.core.flows.StateReplacementException import net.corda.flows.TwoPartyDealFlow import net.corda.vega.analytics.* import net.corda.vega.contracts.* @@ -68,7 +64,8 @@ object SimmFlow { notary = serviceHub.networkMapCache.notaryNodes.first().notaryIdentity myIdentity = serviceHub.myInfo.legalIdentity - val trades = serviceHub.vaultService.dealsWith(otherParty) + val criteria = LinearStateQueryCriteria(participants = listOf(otherParty)) + val trades = serviceHub.vaultQueryService.queryBy(criteria).states val portfolio = Portfolio(trades, valuationDate) if (existing == null) { @@ -76,7 +73,7 @@ object SimmFlow { } else { updatePortfolio(portfolio, existing) } - val portfolioStateRef = serviceHub.vaultService.dealsWith(otherParty).first() + val portfolioStateRef = serviceHub.vaultQueryService.queryBy(criteria).states.first() val state = updateValuation(portfolioStateRef) logger.info("SimmFlow done") @@ -194,7 +191,9 @@ object SimmFlow { @Suspendable override fun call() { ownParty = serviceHub.myInfo.legalIdentity - val trades = serviceHub.vaultService.dealsWith(replyToParty) + + val criteria = LinearStateQueryCriteria(participants = listOf(replyToParty)) + val trades = serviceHub.vaultQueryService.queryBy(criteria).states val portfolio = Portfolio(trades) logger.info("SimmFlow receiver started") offer = receive(replyToParty).unwrap { it } @@ -203,7 +202,7 @@ object SimmFlow { } else { updatePortfolio(portfolio) } - val portfolioStateRef = serviceHub.vaultService.dealsWith(replyToParty).first() + val portfolioStateRef = serviceHub.vaultQueryService.queryBy(criteria).states.first() updateValuation(portfolioStateRef) }