mirror of
https://github.com/corda/corda.git
synced 2025-04-06 19:07:08 +00:00
Removed all deprecated Vault Service query code. (#1167)
This commit is contained in:
parent
2060a81636
commit
818cbce789
@ -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<List<StateAndRef<ContractState>>, Vault.Update<ContractState>>
|
||||
|
||||
/**
|
||||
* Returns a data feed of all recorded transactions and an observable of future recorded ones.
|
||||
*/
|
||||
|
@ -178,21 +178,6 @@ interface VaultService {
|
||||
*/
|
||||
val updatesPublisher: PublishSubject<Vault.Update<ContractState>>
|
||||
|
||||
/**
|
||||
* 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<ContractState>, Vault.Update<ContractState>>
|
||||
|
||||
/**
|
||||
* 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(<StateRef>)))"))
|
||||
fun statesForRefs(refs: List<StateRef>): Map<StateRef, TransactionState<*>?>
|
||||
|
||||
/**
|
||||
* 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<AbstractParty>? = null): Pair<TransactionBuilder, List<PublicKey>>
|
||||
|
||||
// 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 <T : ContractState> states(clazzes: Set<Class<T>>, statuses: EnumSet<Vault.StateStatus>, includeSoftLockedStates: Boolean = true): Iterable<StateAndRef<T>>
|
||||
// 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<OpaqueBytes>? = null): List<StateAndRef<T>>
|
||||
}
|
||||
|
||||
// TODO: Remove this from the interface
|
||||
@Deprecated("This function will be removed in a future milestone", ReplaceWith("queryBy(VaultQueryCriteria())"))
|
||||
inline fun <reified T : ContractState> VaultService.unconsumedStates(includeSoftLockedStates: Boolean = true): Iterable<StateAndRef<T>> =
|
||||
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 <reified T : ContractState> VaultService.consumedStates(): Iterable<StateAndRef<T>> =
|
||||
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(<UniqueIdentifier>)))"))
|
||||
inline fun <reified T : LinearState> 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"
|
||||
}
|
@ -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
|
||||
|
@ -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(<String>)))"))
|
||||
inline fun <reified T : DealState> VaultService.dealsWith(party: AbstractParty) = linearHeadsOfType<T>().values.filter {
|
||||
it.state.data.participants.any { it == party }
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface adding fixing specific methods.
|
||||
*/
|
||||
|
@ -45,13 +45,6 @@ class CordaRPCOpsImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override fun vaultAndUpdates(): DataFeed<List<StateAndRef<ContractState>>, Vault.Update<ContractState>> {
|
||||
return database.transaction {
|
||||
val (vault, updates) = services.vaultService.track()
|
||||
DataFeed(vault.states.toList(), updates)
|
||||
}
|
||||
}
|
||||
|
||||
override fun <T : ContractState> vaultQueryBy(criteria: QueryCriteria,
|
||||
paging: PageSpecification,
|
||||
sorting: Sort,
|
||||
|
@ -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<Vault.Update<ContractState>>
|
||||
get() = mutex.locked { _updatesPublisher }
|
||||
|
||||
override fun track(): DataFeed<Vault<ContractState>, Vault.Update<ContractState>> {
|
||||
return mutex.locked {
|
||||
DataFeed(Vault(unconsumedStates<ContractState>()), _updatesPublisher.bufferUntilSubscribed().wrapWithDatabaseTransaction())
|
||||
}
|
||||
}
|
||||
|
||||
override fun <T : ContractState> states(clazzes: Set<Class<T>>, statuses: EnumSet<Vault.StateStatus>, includeSoftLockedStates: Boolean): Iterable<StateAndRef<T>> {
|
||||
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<TransactionState<T>>(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<StateRef>): Map<StateRef, TransactionState<*>?> {
|
||||
val stateAndRefs =
|
||||
session.withTransaction(transactionIsolationLevel) {
|
||||
var results: List<StateAndRef<*>> = 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<TransactionState<*>>(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
|
||||
|
@ -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<Currency> 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<Class<ContractState>> contractStateTypes = new HashSet(Collections.singletonList(Cash.State.class));
|
||||
EnumSet<Vault.StateStatus> status = EnumSet.of(Vault.StateStatus.CONSUMED);
|
||||
|
||||
// WARNING! unfortunately cannot use inlined reified Kotlin extension methods.
|
||||
Iterable<StateAndRef<ContractState>> results = vaultSvc.states(contractStateTypes, status, true);
|
||||
// DOCEND VaultDeprecatedJavaQueryExample1
|
||||
|
||||
assertThat(results).hasSize(3);
|
||||
|
||||
return tx;
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void consumedStatesForLinearIdDeprecated() {
|
||||
database.transaction(tx -> {
|
||||
|
||||
Vault<LinearState> linearStates = VaultFiller.fillWithSomeTestLinearStates(services, 4,null);
|
||||
linearStates.getStates().iterator().next().component1().getData().getLinearId();
|
||||
|
||||
VaultFiller.consumeLinearStates(services, (List<? extends StateAndRef<? extends LinearState>>) linearStates.getStates());
|
||||
|
||||
// DOCSTART VaultDeprecatedJavaQueryExample0
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<Class<LinearState>> contractStateTypes = new HashSet(Collections.singletonList(DummyLinearContract.State.class));
|
||||
EnumSet<Vault.StateStatus> status = EnumSet.of(Vault.StateStatus.CONSUMED);
|
||||
|
||||
// WARNING! unfortunately cannot use inlined reified Kotlin extension methods.
|
||||
Iterable<StateAndRef<LinearState>> results = vaultSvc.states(contractStateTypes, status, true);
|
||||
// DOCEND VaultDeprecatedJavaQueryExample0
|
||||
|
||||
assertThat(results).hasSize(4);
|
||||
|
||||
return tx;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregation Functions
|
||||
*/
|
||||
|
@ -53,7 +53,6 @@ class CordaRPCOpsImplTest {
|
||||
lateinit var rpc: CordaRPCOps
|
||||
lateinit var stateMachineUpdates: Observable<StateMachineUpdate>
|
||||
lateinit var transactions: Observable<SignedTransaction>
|
||||
lateinit var vaultUpdates: Observable<Vault.Update<ContractState>> // TODO: deprecated
|
||||
lateinit var vaultTrackCash: Observable<Vault.Update<Cash.State>>
|
||||
|
||||
@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<Cash.State>().updates
|
||||
}
|
||||
}
|
||||
@ -119,14 +117,6 @@ class CordaRPCOpsImplTest {
|
||||
val cash = rpc.vaultQueryBy<Cash.State>()
|
||||
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
|
||||
|
@ -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<DummyLinearContract.State>().filter { it.key == linearId }
|
||||
// DOCEND VaultDeprecatedQueryExample1
|
||||
assertThat(states).hasSize(1)
|
||||
|
||||
// validate against new query api
|
||||
val results = vaultQuerySvc.queryBy<LinearState>(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<DummyLinearContract.State>().filter { it.state.data.linearId == linearId }
|
||||
// DOCEND VaultDeprecatedQueryExample2
|
||||
assertThat(states).hasSize(3)
|
||||
|
||||
// validate against new query api
|
||||
val results = vaultQuerySvc.queryBy<LinearState>(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<LinearState>(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<DealState>(criteria)
|
||||
// DOCEND
|
||||
assertThat(results.states).hasSize(1)
|
||||
|
||||
val states = vaultSvc.dealsWith<DummyDealContract.State>(MINI_CORP)
|
||||
assertThat(states).hasSize(1)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal Contract state to be removed as is duplicate of LinearState
|
||||
*/
|
||||
|
@ -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<IRSState>(otherParty)
|
||||
val criteria = LinearStateQueryCriteria(participants = listOf(otherParty))
|
||||
val trades = serviceHub.vaultQueryService.queryBy<IRSState>(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<PortfolioState>(otherParty).first()
|
||||
val portfolioStateRef = serviceHub.vaultQueryService.queryBy<PortfolioState>(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<IRSState>(replyToParty)
|
||||
|
||||
val criteria = LinearStateQueryCriteria(participants = listOf(replyToParty))
|
||||
val trades = serviceHub.vaultQueryService.queryBy<IRSState>(criteria).states
|
||||
val portfolio = Portfolio(trades)
|
||||
logger.info("SimmFlow receiver started")
|
||||
offer = receive<OfferMessage>(replyToParty).unwrap { it }
|
||||
@ -203,7 +202,7 @@ object SimmFlow {
|
||||
} else {
|
||||
updatePortfolio(portfolio)
|
||||
}
|
||||
val portfolioStateRef = serviceHub.vaultService.dealsWith<PortfolioState>(replyToParty).first()
|
||||
val portfolioStateRef = serviceHub.vaultQueryService.queryBy<PortfolioState>(criteria).states.first()
|
||||
updateValuation(portfolioStateRef)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user