mirror of
https://github.com/corda/corda.git
synced 2025-06-17 14:48:16 +00:00
Removed all deprecated Vault Service query code. (#1167)
This commit is contained in:
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user