From e546b554fcfd737c0f1744bc78be5d4d382fbe80 Mon Sep 17 00:00:00 2001 From: Matthew Nesbit Date: Mon, 14 Aug 2017 13:55:09 +0100 Subject: [PATCH] Remove DealState dependency inside Vault. Use the linearId.externalId for all ref data uses. Rename as per PR comments Correct a comment --- .../core/node/services/vault/QueryCriteria.kt | 5 +-- .../node/services/vault/QueryCriteriaUtils.kt | 3 +- .../WorkflowTransactionBuildTutorialTest.kt | 7 ++-- .../net/corda/contracts/FinanceTypes.kt | 6 +-- .../net/corda/flows/TwoPartyDealFlow.kt | 2 +- .../node/services/schema/NodeSchemaService.kt | 11 +---- .../vault/HibernateQueryCriteriaParser.kt | 28 ++++++------- .../node/services/vault/NodeVaultService.kt | 2 - .../corda/node/services/vault/VaultSchema.kt | 14 ++----- .../services/vault/VaultQueryJavaTests.java | 4 +- .../node/services/vault/VaultQueryTests.kt | 42 +++++++++---------- .../node/services/vault/VaultWithCashTest.kt | 7 +--- .../net/corda/irs/api/InterestRateSwapAPI.kt | 4 +- .../main/kotlin/net/corda/irs/contract/IRS.kt | 4 +- .../net/corda/vega/contracts/IRSState.kt | 2 +- .../corda/vega/contracts/PortfolioState.kt | 2 +- .../testing/contracts/DummyDealContract.kt | 14 ++++--- .../testing/schemas/DummyDealStateSchemaV1.kt | 5 --- 18 files changed, 62 insertions(+), 100 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/node/services/vault/QueryCriteria.kt b/core/src/main/kotlin/net/corda/core/node/services/vault/QueryCriteria.kt index 086afd34cb..0be25265f6 100644 --- a/core/src/main/kotlin/net/corda/core/node/services/vault/QueryCriteria.kt +++ b/core/src/main/kotlin/net/corda/core/node/services/vault/QueryCriteria.kt @@ -4,7 +4,6 @@ package net.corda.core.node.services.vault import net.corda.core.contracts.ContractState import net.corda.core.contracts.StateRef -import net.corda.core.contracts.UniqueIdentifier import net.corda.core.identity.AbstractParty import net.corda.core.node.services.Vault import net.corda.core.schemas.PersistentState @@ -64,8 +63,8 @@ sealed class QueryCriteria { * LinearStateQueryCriteria: provides query by attributes defined in [VaultSchema.VaultLinearState] */ data class LinearStateQueryCriteria @JvmOverloads constructor(val participants: List? = null, - val linearId: List? = null, - val dealRef: List? = null, + val uuid: List? = null, + val externalId: List? = null, override val status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED) : CommonQueryCriteria() { override fun visit(parser: IQueryCriteriaParser): Collection { return parser.parseCriteria(this as CommonQueryCriteria).plus(parser.parseCriteria(this)) diff --git a/core/src/main/kotlin/net/corda/core/node/services/vault/QueryCriteriaUtils.kt b/core/src/main/kotlin/net/corda/core/node/services/vault/QueryCriteriaUtils.kt index 44de37183f..88364f3bb2 100644 --- a/core/src/main/kotlin/net/corda/core/node/services/vault/QueryCriteriaUtils.kt +++ b/core/src/main/kotlin/net/corda/core/node/services/vault/QueryCriteriaUtils.kt @@ -162,8 +162,7 @@ data class Sort(val columns: Collection) { enum class LinearStateAttribute(val attributeName: String) : Attribute { /** Vault Linear States */ UUID("uuid"), - EXTERNAL_ID("externalId"), - DEAL_REFERENCE("dealReference") + EXTERNAL_ID("externalId") } enum class FungibleStateAttribute(val attributeName: String) : Attribute { diff --git a/docs/source/example-code/src/test/kotlin/net/corda/docs/WorkflowTransactionBuildTutorialTest.kt b/docs/source/example-code/src/test/kotlin/net/corda/docs/WorkflowTransactionBuildTutorialTest.kt index f9565854b6..91bca876cc 100644 --- a/docs/source/example-code/src/test/kotlin/net/corda/docs/WorkflowTransactionBuildTutorialTest.kt +++ b/docs/source/example-code/src/test/kotlin/net/corda/docs/WorkflowTransactionBuildTutorialTest.kt @@ -5,15 +5,14 @@ import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.UniqueIdentifier import net.corda.core.node.ServiceHub import net.corda.core.node.services.ServiceInfo -import net.corda.core.node.services.Vault import net.corda.core.node.services.queryBy import net.corda.core.node.services.vault.QueryCriteria import net.corda.core.toFuture import net.corda.core.utilities.getOrThrow -import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.DUMMY_NOTARY_KEY import net.corda.node.services.network.NetworkMapService import net.corda.node.services.transactions.ValidatingNotaryService +import net.corda.testing.DUMMY_NOTARY +import net.corda.testing.DUMMY_NOTARY_KEY import net.corda.testing.node.MockNetwork import org.junit.After import org.junit.Before @@ -28,7 +27,7 @@ class WorkflowTransactionBuildTutorialTest { // Helper method to locate the latest Vault version of a LinearState private inline fun ServiceHub.latest(ref: UniqueIdentifier): StateAndRef { - val linearHeads = vaultQueryService.queryBy(QueryCriteria.LinearStateQueryCriteria(linearId = listOf(ref))) + val linearHeads = vaultQueryService.queryBy(QueryCriteria.LinearStateQueryCriteria(uuid = listOf(ref.id))) return linearHeads.states.single() } diff --git a/finance/src/main/kotlin/net/corda/contracts/FinanceTypes.kt b/finance/src/main/kotlin/net/corda/contracts/FinanceTypes.kt index 253c5ee664..c4f4fe6546 100644 --- a/finance/src/main/kotlin/net/corda/contracts/FinanceTypes.kt +++ b/finance/src/main/kotlin/net/corda/contracts/FinanceTypes.kt @@ -13,9 +13,8 @@ import net.corda.core.contracts.CommandData import net.corda.core.contracts.LinearState import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.TokenizableAssetInfo -import net.corda.core.identity.AbstractParty import net.corda.core.identity.Party -import net.corda.core.node.services.* +import net.corda.core.node.services.ServiceType import net.corda.core.serialization.CordaSerializable import net.corda.core.transactions.TransactionBuilder import java.math.BigDecimal @@ -391,9 +390,6 @@ data class Commodity(val commodityCode: String, * implementation of general flows that manipulate many agreement types. */ interface DealState : LinearState { - /** Human readable well known reference (e.g. trade reference) */ - val ref: String - /** * Generate a partial transaction representing an agreement (command) to this deal, allowing a general * deal/agreement flow to generate the necessary transaction for potential implementations. diff --git a/finance/src/main/kotlin/net/corda/flows/TwoPartyDealFlow.kt b/finance/src/main/kotlin/net/corda/flows/TwoPartyDealFlow.kt index 6c91bb4a78..358de91328 100644 --- a/finance/src/main/kotlin/net/corda/flows/TwoPartyDealFlow.kt +++ b/finance/src/main/kotlin/net/corda/flows/TwoPartyDealFlow.kt @@ -174,7 +174,7 @@ object TwoPartyDealFlow { // What is the seller trying to sell us? val autoOffer = handshake.payload val deal = autoOffer.dealBeingOffered - logger.trace { "Got deal request for: ${deal.ref}" } + logger.trace { "Got deal request for: ${deal.linearId.externalId!!}" } return handshake.copy(payload = autoOffer.copy(dealBeingOffered = deal)) } diff --git a/node/src/main/kotlin/net/corda/node/services/schema/NodeSchemaService.kt b/node/src/main/kotlin/net/corda/node/services/schema/NodeSchemaService.kt index 731b82df36..4c8e128fbb 100644 --- a/node/src/main/kotlin/net/corda/node/services/schema/NodeSchemaService.kt +++ b/node/src/main/kotlin/net/corda/node/services/schema/NodeSchemaService.kt @@ -1,15 +1,14 @@ package net.corda.node.services.schema -import net.corda.contracts.DealState import net.corda.core.contracts.ContractState import net.corda.core.contracts.FungibleAsset import net.corda.core.contracts.LinearState +import net.corda.core.schemas.CommonSchemaV1 import net.corda.core.schemas.MappedSchema import net.corda.core.schemas.PersistentState import net.corda.core.schemas.QueryableState import net.corda.core.serialization.SingletonSerializeAsToken import net.corda.node.services.api.SchemaService -import net.corda.core.schemas.CommonSchemaV1 import net.corda.node.services.keys.PersistentKeyManagementService import net.corda.node.services.persistence.DBCheckpointStorage import net.corda.node.services.persistence.DBTransactionMappingStorage @@ -59,9 +58,6 @@ class NodeSchemaService(customSchemas: Set = emptySet()) : SchemaS schemas += state.supportedSchemas() if (state is LinearState) schemas += VaultSchemaV1 // VaultLinearStates - // TODO: DealState to be deprecated (collapsed into LinearState) - if (state is DealState) - schemas += VaultSchemaV1 // VaultLinearStates if (state is FungibleAsset<*>) schemas += VaultSchemaV1 // VaultFungibleStates @@ -70,11 +66,8 @@ class NodeSchemaService(customSchemas: Set = emptySet()) : SchemaS // Because schema is always one supported by the state, just delegate. override fun generateMappedObject(state: ContractState, schema: MappedSchema): PersistentState { - // TODO: DealState to be deprecated (collapsed into LinearState) - if ((schema is VaultSchemaV1) && (state is DealState)) - return VaultSchemaV1.VaultLinearStates(state.linearId, state.ref, state.participants) if ((schema is VaultSchemaV1) && (state is LinearState)) - return VaultSchemaV1.VaultLinearStates(state.linearId, "", state.participants) + return VaultSchemaV1.VaultLinearStates(state.linearId, state.participants) if ((schema is VaultSchemaV1) && (state is FungibleAsset<*>)) return VaultSchemaV1.VaultFungibleStates(state.owner, state.amount.quantity, state.amount.token.issuer.party, state.amount.token.issuer.reference, state.participants) return (state as QueryableState).generateMappedObject(schema) diff --git a/node/src/main/kotlin/net/corda/node/services/vault/HibernateQueryCriteriaParser.kt b/node/src/main/kotlin/net/corda/node/services/vault/HibernateQueryCriteriaParser.kt index 934193dc3c..2ee2218160 100644 --- a/node/src/main/kotlin/net/corda/node/services/vault/HibernateQueryCriteriaParser.kt +++ b/node/src/main/kotlin/net/corda/node/services/vault/HibernateQueryCriteriaParser.kt @@ -2,7 +2,6 @@ package net.corda.node.services.vault import net.corda.core.contracts.ContractState import net.corda.core.contracts.StateRef -import net.corda.core.contracts.UniqueIdentifier import net.corda.core.identity.AbstractParty import net.corda.core.node.services.Vault import net.corda.core.node.services.VaultQueryException @@ -229,7 +228,7 @@ class HibernateQueryCriteriaParser(val contractType: Class, override fun parseCriteria(criteria: QueryCriteria.FungibleAssetQueryCriteria) : Collection { log.trace { "Parsing FungibleAssetQueryCriteria: $criteria" } - var predicateSet = mutableSetOf() + val predicateSet = mutableSetOf() val vaultFungibleStates = criteriaQuery.from(VaultSchemaV1.VaultFungibleStates::class.java) rootEntities.putIfAbsent(VaultSchemaV1.VaultFungibleStates::class.java, vaultFungibleStates) @@ -296,19 +295,16 @@ class HibernateQueryCriteriaParser(val contractType: Class, if (contractTypes.isNotEmpty()) predicateSet.add(criteriaBuilder.and(vaultStates.get("contractStateClassName").`in`(contractTypes))) - // linear ids - criteria.linearId?.let { - val uniqueIdentifiers = criteria.linearId as List - val externalIds = uniqueIdentifiers.mapNotNull { it.externalId } - if (externalIds.isNotEmpty()) - predicateSet.add(criteriaBuilder.and(vaultLinearStates.get("externalId").`in`(externalIds))) - predicateSet.add(criteriaBuilder.and(vaultLinearStates.get("uuid").`in`(uniqueIdentifiers.map { it.id }))) + // linear ids UUID + criteria.uuid?.let { + val uuids = criteria.uuid as List + predicateSet.add(criteriaBuilder.and(vaultLinearStates.get("uuid").`in`(uuids))) } - // deal refs - criteria.dealRef?.let { - val dealRefs = criteria.dealRef as List - predicateSet.add(criteriaBuilder.and(vaultLinearStates.get("dealReference").`in`(dealRefs))) + // linear ids externalId + criteria.externalId?.let { + val externalIds = criteria.externalId as List + predicateSet.add(criteriaBuilder.and(vaultLinearStates.get("externalId").`in`(externalIds))) } // deal participants @@ -359,7 +355,7 @@ class HibernateQueryCriteriaParser(val contractType: Class, override fun parseOr(left: QueryCriteria, right: QueryCriteria): Collection { log.trace { "Parsing OR QueryCriteria composition: $left OR $right" } - var predicateSet = mutableSetOf() + val predicateSet = mutableSetOf() val leftPredicates = parse(left) val rightPredicates = parse(right) @@ -372,7 +368,7 @@ class HibernateQueryCriteriaParser(val contractType: Class, override fun parseAnd(left: QueryCriteria, right: QueryCriteria): Collection { log.trace { "Parsing AND QueryCriteria composition: $left AND $right" } - var predicateSet = mutableSetOf() + val predicateSet = mutableSetOf() val leftPredicates = parse(left) val rightPredicates = parse(right) @@ -417,7 +413,7 @@ class HibernateQueryCriteriaParser(val contractType: Class, private fun parse(sorting: Sort) { log.trace { "Parsing sorting specification: $sorting" } - var orderCriteria = mutableListOf() + val orderCriteria = mutableListOf() sorting.columns.map { (sortAttribute, direction) -> val (entityStateClass, entityStateAttributeParent, entityStateAttributeChild) = 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 c173b55925..04e98b5e75 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 @@ -5,9 +5,7 @@ import co.paralleluniverse.strands.Strand import com.google.common.annotations.VisibleForTesting import io.requery.PersistenceException import io.requery.kotlin.eq -import io.requery.kotlin.notNull import io.requery.query.RowExpression -import net.corda.contracts.asset.Cash import net.corda.core.contracts.* import net.corda.core.crypto.SecureHash import net.corda.core.crypto.containsAny diff --git a/node/src/main/kotlin/net/corda/node/services/vault/VaultSchema.kt b/node/src/main/kotlin/net/corda/node/services/vault/VaultSchema.kt index abf2e44c99..9ead62d2c9 100644 --- a/node/src/main/kotlin/net/corda/node/services/vault/VaultSchema.kt +++ b/node/src/main/kotlin/net/corda/node/services/vault/VaultSchema.kt @@ -68,8 +68,7 @@ object VaultSchemaV1 : MappedSchema(schemaFamily = VaultSchema.javaClass, versio @Entity @Table(name = "vault_linear_states", indexes = arrayOf(Index(name = "external_id_index", columnList = "external_id"), - Index(name = "uuid_index", columnList = "uuid"), - Index(name = "deal_reference_index", columnList = "deal_reference"))) + Index(name = "uuid_index", columnList = "uuid"))) class VaultLinearStates( /** [ContractState] attributes */ @OneToMany(cascade = arrayOf(CascadeType.ALL)) @@ -82,18 +81,11 @@ object VaultSchemaV1 : MappedSchema(schemaFamily = VaultSchema.javaClass, versio var externalId: String?, @Column(name = "uuid", nullable = false) - var uuid: UUID, - - // TODO: DealState to be deprecated (collapsed into LinearState) - - /** Deal State attributes **/ - @Column(name = "deal_reference") - var dealReference: String + var uuid: UUID ) : PersistentState() { - constructor(uid: UniqueIdentifier, _dealReference: String, _participants: List) : + constructor(uid: UniqueIdentifier, _participants: List) : this(externalId = uid.externalId, uuid = uid.id, - dealReference = _dealReference, participants = _participants.map{ CommonSchemaV1.Party(it) }.toSet() ) } 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 ab0d2a1206..1d2cbb9995 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 @@ -171,7 +171,7 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { QueryCriteria vaultCriteria = new VaultQueryCriteria(status, contractStateTypes); - List linearIds = Collections.singletonList(uid); + List linearIds = Collections.singletonList(uid.getId()); QueryCriteria linearCriteriaAll = new LinearStateQueryCriteria(null, linearIds); QueryCriteria dealCriteriaAll = new LinearStateQueryCriteria(null, null, dealIds); @@ -281,7 +281,7 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { Set> contractStateTypes = new HashSet(Arrays.asList(DealState.class, LinearState.class)); QueryCriteria vaultCriteria = new VaultQueryCriteria(Vault.StateStatus.UNCONSUMED, contractStateTypes); - List linearIds = Collections.singletonList(uid); + List linearIds = Collections.singletonList(uid.getId()); List dealParty = Collections.singletonList(getMEGA_CORP()); QueryCriteria dealCriteria = new LinearStateQueryCriteria(dealParty, null, dealIds); QueryCriteria linearCriteria = new LinearStateQueryCriteria(dealParty, linearIds, null); 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 1c8c3dfab2..47ece34c00 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 @@ -14,10 +14,6 @@ import net.corda.core.identity.Party import net.corda.core.node.services.* import net.corda.core.node.services.vault.* import net.corda.core.node.services.vault.QueryCriteria.* -import net.corda.core.utilities.seconds -import net.corda.core.utilities.NonEmptySet -import net.corda.core.utilities.OpaqueBytes -import net.corda.core.utilities.toHexString import net.corda.core.utilities.* import net.corda.node.utilities.CordaPersistence import net.corda.node.utilities.configureDatabase @@ -99,7 +95,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { // consume some states services.consumeLinearStates(linearStatesXYZ.states.toList(), DUMMY_NOTARY) services.consumeLinearStates(linearStatesJKL.states.toList(), DUMMY_NOTARY) - services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }, DUMMY_NOTARY) + services.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // Total unconsumed states = 4 + 3 + 2 + 1 (new cash change) = 10 @@ -328,7 +324,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")) services.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) - services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }, DUMMY_NOTARY) + services.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) @@ -370,7 +366,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")) services.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) - services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }, DUMMY_NOTARY) + services.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // generates a new change state! val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) @@ -883,7 +879,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { // consume some states services.consumeLinearStates(linearStatesXYZ.states.toList(), DUMMY_NOTARY) services.consumeLinearStates(linearStatesJKL.states.toList(), DUMMY_NOTARY) - services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }, DUMMY_NOTARY) + services.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) val cashUpdates = services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // UNCONSUMED states (default) @@ -1171,7 +1167,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")) services.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) - services.consumeDeals(dealStates.states.filter { it.state.data.ref == "456" }, DUMMY_NOTARY) + services.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) @@ -1189,8 +1185,8 @@ class VaultQueryTests : TestDependencyInjectionBase() { val issuedStates = services.fillWithSomeTestLinearStates(10) // DOCSTART VaultQueryExample8 - val linearIds = issuedStates.states.map { it.state.data.linearId }.toList() - val criteria = LinearStateQueryCriteria(linearId = listOf(linearIds.first(), linearIds.last())) + val linearIds = issuedStates.states.map { it.state.data.linearId.id }.toList() + val criteria = LinearStateQueryCriteria(uuid = listOf(linearIds.first(), linearIds.last())) val results = vaultQuerySvc.queryBy(criteria) // DOCEND VaultQueryExample8 assertThat(results.states).hasSize(2) @@ -1205,8 +1201,8 @@ class VaultQueryTests : TestDependencyInjectionBase() { services.fillWithSomeTestLinearStates(1, "ID2") val linearState3 = services.fillWithSomeTestLinearStates(1, "ID3") - val linearIds = listOf(linearState1.states.first().state.data.linearId, linearState3.states.first().state.data.linearId) - val criteria = LinearStateQueryCriteria(linearId = linearIds) + val linearIds = listOf(linearState1.states.first().state.data.linearId.id, linearState3.states.first().state.data.linearId.id) + val criteria = LinearStateQueryCriteria(uuid = linearIds) val results = vaultQuerySvc.queryBy(criteria) assertThat(results.states).hasSize(2) } @@ -1225,7 +1221,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" // DOCSTART VaultQueryExample9 - val linearStateCriteria = LinearStateQueryCriteria(linearId = listOf(linearId), status = Vault.StateStatus.ALL) + val linearStateCriteria = LinearStateQueryCriteria(uuid = listOf(linearId.id), status = Vault.StateStatus.ALL) val vaultCriteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val results = vaultQuerySvc.queryBy(linearStateCriteria and vaultCriteria) // DOCEND VaultQueryExample9 @@ -1244,7 +1240,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { services.evolveLinearStates(linearStates, DUMMY_NOTARY) // consume current and produce new state reference // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" - val linearStateCriteria = LinearStateQueryCriteria(linearId = linearStates.map { it.state.data.linearId }, status = Vault.StateStatus.ALL) + val linearStateCriteria = LinearStateQueryCriteria(uuid = linearStates.map { it.state.data.linearId.id }, status = Vault.StateStatus.ALL) val vaultCriteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val sorting = Sort(setOf(Sort.SortColumn(SortAttribute.Standard(Sort.LinearStateAttribute.UUID), Sort.Direction.DESC))) @@ -1266,7 +1262,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { val sorting = Sort(setOf(Sort.SortColumn(SortAttribute.Standard(Sort.LinearStateAttribute.EXTERNAL_ID), Sort.Direction.DESC))) val results = vaultQuerySvc.queryBy((vaultCriteria), sorting = sorting) - results.states.forEach { println("${it.state.data.linearString}") } + results.states.forEach { println(it.state.data.linearString) } assertThat(results.states).hasSize(6) } } @@ -1276,14 +1272,14 @@ class VaultQueryTests : TestDependencyInjectionBase() { database.transaction { val linearStates = services.fillWithSomeTestLinearStates(10) - val uid = linearStates.states.first().state.data.linearId + val uid = linearStates.states.first().state.data.linearId.id services.fillWithSomeTestDeals(listOf("123", "456", "789")) - val linearStateCriteria = LinearStateQueryCriteria(linearId = listOf(uid)) - val dealStateCriteria = LinearStateQueryCriteria(dealRef = listOf("123", "456", "789")) + val linearStateCriteria = LinearStateQueryCriteria(uuid = listOf(uid)) + val dealStateCriteria = LinearStateQueryCriteria(externalId = listOf("123", "456", "789")) val compositeCriteria = linearStateCriteria or dealStateCriteria - val sorting = Sort(setOf(Sort.SortColumn(SortAttribute.Standard(Sort.LinearStateAttribute.DEAL_REFERENCE), Sort.Direction.DESC))) + val sorting = Sort(setOf(Sort.SortColumn(SortAttribute.Standard(Sort.LinearStateAttribute.EXTERNAL_ID), Sort.Direction.DESC))) val results = vaultQuerySvc.queryBy(compositeCriteria, sorting = sorting) assertThat(results.statesMetadata).hasSize(13) @@ -1319,7 +1315,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { services.evolveLinearState(linearState3, DUMMY_NOTARY) // consume current and produce new state reference // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" - val linearStateCriteria = LinearStateQueryCriteria(linearId = txns.states.map { it.state.data.linearId }, status = Vault.StateStatus.CONSUMED) + val linearStateCriteria = LinearStateQueryCriteria(uuid = txns.states.map { it.state.data.linearId.id }, status = Vault.StateStatus.CONSUMED) val vaultCriteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val sorting = Sort(setOf(Sort.SortColumn(SortAttribute.Standard(Sort.LinearStateAttribute.UUID), Sort.Direction.DESC))) val results = vaultQuerySvc.queryBy(linearStateCriteria.and(vaultCriteria), sorting = sorting) @@ -1348,7 +1344,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { services.fillWithSomeTestDeals(listOf("123", "456", "789")) // DOCSTART VaultQueryExample10 - val criteria = LinearStateQueryCriteria(dealRef = listOf("456", "789")) + val criteria = LinearStateQueryCriteria(externalId = listOf("456", "789")) val results = vaultQuerySvc.queryBy(criteria) // DOCEND VaultQueryExample10 @@ -1367,7 +1363,7 @@ class VaultQueryTests : TestDependencyInjectionBase() { val all = vaultQuerySvc.queryBy() all.states.forEach { println(it.state) } - val criteria = LinearStateQueryCriteria(dealRef = listOf("456")) + val criteria = LinearStateQueryCriteria(externalId = listOf("456")) val results = vaultQuerySvc.queryBy(criteria) assertThat(results.states).hasSize(1) } diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt index ac5c358897..0b35c7a775 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt @@ -13,9 +13,6 @@ import net.corda.core.node.services.queryBy import net.corda.core.node.services.vault.QueryCriteria import net.corda.core.node.services.vault.QueryCriteria.VaultQueryCriteria import net.corda.core.transactions.TransactionBuilder -import net.corda.node.services.database.HibernateConfiguration -import net.corda.node.services.identity.InMemoryIdentityService -import net.corda.node.services.schema.NodeSchemaService import net.corda.node.utilities.CordaPersistence import net.corda.testing.* import net.corda.testing.contracts.* @@ -278,7 +275,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() { services.fillWithSomeTestDeals(listOf("123", "456", "789")) val deals = vaultQuery.queryBy().states - deals.forEach { println(it.state.data.ref) } + deals.forEach { println(it.state.data.linearId.externalId!!) } } database.transaction { @@ -306,7 +303,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() { services.fillWithSomeTestDeals(listOf("123", "456", "789")) val deals = vaultQuery.queryBy().states - deals.forEach { println(it.state.data.ref) } + deals.forEach { println(it.state.data.linearId.externalId!!) } services.fillWithSomeTestLinearStates(3) val linearStates = vaultQuery.queryBy().states diff --git a/samples/irs-demo/src/main/kotlin/net/corda/irs/api/InterestRateSwapAPI.kt b/samples/irs-demo/src/main/kotlin/net/corda/irs/api/InterestRateSwapAPI.kt index 76035ed2be..2377a9c86a 100644 --- a/samples/irs-demo/src/main/kotlin/net/corda/irs/api/InterestRateSwapAPI.kt +++ b/samples/irs-demo/src/main/kotlin/net/corda/irs/api/InterestRateSwapAPI.kt @@ -3,8 +3,8 @@ package net.corda.irs.api import net.corda.core.contracts.filterStatesOfType import net.corda.core.messaging.CordaRPCOps import net.corda.core.messaging.startFlow -import net.corda.core.utilities.getOrThrow import net.corda.core.messaging.vaultQueryBy +import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.loggerFor import net.corda.irs.contract.InterestRateSwap import net.corda.irs.flows.AutoOfferFlow @@ -37,7 +37,7 @@ class InterestRateSwapAPI(val rpc: CordaRPCOps) { private fun getDealByRef(ref: String): InterestRateSwap.State? { val vault = rpc.vaultQueryBy().states - val states = vault.filterStatesOfType().filter { it.state.data.ref == ref } + val states = vault.filterStatesOfType().filter { it.state.data.linearId.externalId == ref } return if (states.isEmpty()) null else { val deals = states.map { it.state.data } return if (deals.isEmpty()) null else deals[0] diff --git a/samples/irs-demo/src/main/kotlin/net/corda/irs/contract/IRS.kt b/samples/irs-demo/src/main/kotlin/net/corda/irs/contract/IRS.kt index 2c45c805c7..8c032f695d 100644 --- a/samples/irs-demo/src/main/kotlin/net/corda/irs/contract/IRS.kt +++ b/samples/irs-demo/src/main/kotlin/net/corda/irs/contract/IRS.kt @@ -567,7 +567,7 @@ class InterestRateSwap : Contract { requireNotNull(tx.timeWindow) { "must be have a time-window)" } val groups: List> = tx.groupStates { state -> state.linearId } var atLeastOneCommandProcessed = false - for ((inputs, outputs, key) in groups) { + for ((inputs, outputs, _) in groups) { val agreeCommand = tx.commands.select().firstOrNull() if (agreeCommand != null) { verifyAgreeCommand(inputs, outputs) @@ -616,7 +616,7 @@ class InterestRateSwap : Contract { override val oracleType: ServiceType get() = NodeInterestRates.Oracle.type - override val ref = common.tradeID + val ref: String get() = linearId.externalId ?: "" override val participants: List get() = listOf(fixedLeg.fixedRatePayer, floatingLeg.floatingRatePayer) diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/contracts/IRSState.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/contracts/IRSState.kt index 606d987096..8d40347f27 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/contracts/IRSState.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/contracts/IRSState.kt @@ -19,7 +19,7 @@ data class IRSState(val swap: SwapData, val seller: AbstractParty, override val contract: OGTrade, override val linearId: UniqueIdentifier = UniqueIdentifier(swap.id.first + swap.id.second)) : DealState { - override val ref: String = linearId.externalId!! // Same as the constructor for UniqueIdentified + val ref: String get() = linearId.externalId!! // Same as the constructor for UniqueIdentified override val participants: List get() = listOf(buyer, seller) override fun isRelevant(ourKeys: Set): Boolean { diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/contracts/PortfolioState.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/contracts/PortfolioState.kt index a2d7ef2bef..5fb811f26e 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/contracts/PortfolioState.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/contracts/PortfolioState.kt @@ -29,7 +29,7 @@ data class PortfolioState(val portfolio: List, data class Update(val portfolio: List? = null, val valuation: PortfolioValuation? = null) override val participants: List get() = _parties.toList() - override val ref: String = linearId.toString() + val ref: String get() = linearId.toString() val valuer: AbstractParty get() = participants[0] override fun nextScheduledActivity(thisStateRef: StateRef, flowLogicRefFactory: FlowLogicRefFactory): ScheduledActivity { diff --git a/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyDealContract.kt b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyDealContract.kt index acc724e83f..421de71ba6 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyDealContract.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/contracts/DummyDealContract.kt @@ -21,11 +21,14 @@ class DummyDealContract : Contract { override fun verify(tx: LedgerTransaction) {} data class State( - override val contract: Contract = DummyDealContract(), - override val participants: List = listOf(), - override val linearId: UniqueIdentifier = UniqueIdentifier(), - override val ref: String) : DealState, QueryableState + override val contract: Contract, + override val participants: List, + override val linearId: UniqueIdentifier) : DealState, QueryableState { + constructor(contract: Contract = DummyDealContract(), + participants: List = listOf(), + ref: String) : this(contract, participants, UniqueIdentifier(ref)) + override fun isRelevant(ourKeys: Set): Boolean { return participants.any { it.owningKey.containsAny(ourKeys) } } @@ -39,8 +42,7 @@ class DummyDealContract : Contract { override fun generateMappedObject(schema: MappedSchema): PersistentState { return when (schema) { is DummyDealStateSchemaV1 -> DummyDealStateSchemaV1.PersistentDummyDealState( - uid = linearId, - dealReference = ref + uid = linearId ) else -> throw IllegalArgumentException("Unrecognised schema $schema") } diff --git a/test-utils/src/main/kotlin/net/corda/testing/schemas/DummyDealStateSchemaV1.kt b/test-utils/src/main/kotlin/net/corda/testing/schemas/DummyDealStateSchemaV1.kt index c59a09b192..7bf754473c 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/schemas/DummyDealStateSchemaV1.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/schemas/DummyDealStateSchemaV1.kt @@ -3,7 +3,6 @@ package net.corda.testing.schemas import net.corda.core.contracts.UniqueIdentifier import net.corda.core.schemas.CommonSchemaV1 import net.corda.core.schemas.MappedSchema -import javax.persistence.Column import javax.persistence.Entity import javax.persistence.Table import javax.persistence.Transient @@ -21,10 +20,6 @@ object DummyDealStateSchemaV1 : MappedSchema(schemaFamily = DummyDealStateSchema @Entity @Table(name = "dummy_deal_states") class PersistentDummyDealState( - - @Column(name = "deal_reference") - var dealReference: String, - /** parent attributes */ @Transient val uid: UniqueIdentifier