Remove DealState dependency inside Vault. Use the linearId.externalId for all ref data uses.

Rename as per PR comments

Correct a comment
This commit is contained in:
Matthew Nesbit 2017-08-14 13:55:09 +01:00
parent 3ba42b4ccd
commit e546b554fc
18 changed files with 62 additions and 100 deletions

View File

@ -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<AbstractParty>? = null,
val linearId: List<UniqueIdentifier>? = null,
val dealRef: List<String>? = null,
val uuid: List<UUID>? = null,
val externalId: List<String>? = null,
override val status: Vault.StateStatus = Vault.StateStatus.UNCONSUMED) : CommonQueryCriteria() {
override fun visit(parser: IQueryCriteriaParser): Collection<Predicate> {
return parser.parseCriteria(this as CommonQueryCriteria).plus(parser.parseCriteria(this))

View File

@ -162,8 +162,7 @@ data class Sort(val columns: Collection<SortColumn>) {
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 {

View File

@ -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 <reified T : LinearState> ServiceHub.latest(ref: UniqueIdentifier): StateAndRef<T> {
val linearHeads = vaultQueryService.queryBy<T>(QueryCriteria.LinearStateQueryCriteria(linearId = listOf(ref)))
val linearHeads = vaultQueryService.queryBy<T>(QueryCriteria.LinearStateQueryCriteria(uuid = listOf(ref.id)))
return linearHeads.states.single()
}

View File

@ -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.

View File

@ -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))
}

View File

@ -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<MappedSchema> = 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<MappedSchema> = 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)

View File

@ -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<out ContractState>,
override fun parseCriteria(criteria: QueryCriteria.FungibleAssetQueryCriteria) : Collection<Predicate> {
log.trace { "Parsing FungibleAssetQueryCriteria: $criteria" }
var predicateSet = mutableSetOf<Predicate>()
val predicateSet = mutableSetOf<Predicate>()
val vaultFungibleStates = criteriaQuery.from(VaultSchemaV1.VaultFungibleStates::class.java)
rootEntities.putIfAbsent(VaultSchemaV1.VaultFungibleStates::class.java, vaultFungibleStates)
@ -296,19 +295,16 @@ class HibernateQueryCriteriaParser(val contractType: Class<out ContractState>,
if (contractTypes.isNotEmpty())
predicateSet.add(criteriaBuilder.and(vaultStates.get<String>("contractStateClassName").`in`(contractTypes)))
// linear ids
criteria.linearId?.let {
val uniqueIdentifiers = criteria.linearId as List<UniqueIdentifier>
val externalIds = uniqueIdentifiers.mapNotNull { it.externalId }
if (externalIds.isNotEmpty())
predicateSet.add(criteriaBuilder.and(vaultLinearStates.get<String>("externalId").`in`(externalIds)))
predicateSet.add(criteriaBuilder.and(vaultLinearStates.get<UUID>("uuid").`in`(uniqueIdentifiers.map { it.id })))
// linear ids UUID
criteria.uuid?.let {
val uuids = criteria.uuid as List<UUID>
predicateSet.add(criteriaBuilder.and(vaultLinearStates.get<UUID>("uuid").`in`(uuids)))
}
// deal refs
criteria.dealRef?.let {
val dealRefs = criteria.dealRef as List<String>
predicateSet.add(criteriaBuilder.and(vaultLinearStates.get<String>("dealReference").`in`(dealRefs)))
// linear ids externalId
criteria.externalId?.let {
val externalIds = criteria.externalId as List<String>
predicateSet.add(criteriaBuilder.and(vaultLinearStates.get<String>("externalId").`in`(externalIds)))
}
// deal participants
@ -359,7 +355,7 @@ class HibernateQueryCriteriaParser(val contractType: Class<out ContractState>,
override fun parseOr(left: QueryCriteria, right: QueryCriteria): Collection<Predicate> {
log.trace { "Parsing OR QueryCriteria composition: $left OR $right" }
var predicateSet = mutableSetOf<Predicate>()
val predicateSet = mutableSetOf<Predicate>()
val leftPredicates = parse(left)
val rightPredicates = parse(right)
@ -372,7 +368,7 @@ class HibernateQueryCriteriaParser(val contractType: Class<out ContractState>,
override fun parseAnd(left: QueryCriteria, right: QueryCriteria): Collection<Predicate> {
log.trace { "Parsing AND QueryCriteria composition: $left AND $right" }
var predicateSet = mutableSetOf<Predicate>()
val predicateSet = mutableSetOf<Predicate>()
val leftPredicates = parse(left)
val rightPredicates = parse(right)
@ -417,7 +413,7 @@ class HibernateQueryCriteriaParser(val contractType: Class<out ContractState>,
private fun parse(sorting: Sort) {
log.trace { "Parsing sorting specification: $sorting" }
var orderCriteria = mutableListOf<Order>()
val orderCriteria = mutableListOf<Order>()
sorting.columns.map { (sortAttribute, direction) ->
val (entityStateClass, entityStateAttributeParent, entityStateAttributeChild) =

View File

@ -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

View File

@ -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<AbstractParty>) :
constructor(uid: UniqueIdentifier, _participants: List<AbstractParty>) :
this(externalId = uid.externalId,
uuid = uid.id,
dealReference = _dealReference,
participants = _participants.map{ CommonSchemaV1.Party(it) }.toSet() )
}

View File

@ -171,7 +171,7 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase {
QueryCriteria vaultCriteria = new VaultQueryCriteria(status, contractStateTypes);
List<UniqueIdentifier> linearIds = Collections.singletonList(uid);
List<UUID> 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<Class<ContractState>> contractStateTypes = new HashSet(Arrays.asList(DealState.class, LinearState.class));
QueryCriteria vaultCriteria = new VaultQueryCriteria(Vault.StateStatus.UNCONSUMED, contractStateTypes);
List<UniqueIdentifier> linearIds = Collections.singletonList(uid);
List<UUID> linearIds = Collections.singletonList(uid.getId());
List<AbstractParty> dealParty = Collections.singletonList(getMEGA_CORP());
QueryCriteria dealCriteria = new LinearStateQueryCriteria(dealParty, null, dealIds);
QueryCriteria linearCriteria = new LinearStateQueryCriteria(dealParty, linearIds, null);

View File

@ -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<LinearState>(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<LinearState>(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<LinearState>(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<DummyLinearContract.State>((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<LinearState>(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<LinearState>(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<DealState>(criteria)
// DOCEND VaultQueryExample10
@ -1367,7 +1363,7 @@ class VaultQueryTests : TestDependencyInjectionBase() {
val all = vaultQuerySvc.queryBy<DealState>()
all.states.forEach { println(it.state) }
val criteria = LinearStateQueryCriteria(dealRef = listOf("456"))
val criteria = LinearStateQueryCriteria(externalId = listOf("456"))
val results = vaultQuerySvc.queryBy<DealState>(criteria)
assertThat(results.states).hasSize(1)
}

View File

@ -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<DummyDealContract.State>().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<DummyDealContract.State>().states
deals.forEach { println(it.state.data.ref) }
deals.forEach { println(it.state.data.linearId.externalId!!) }
services.fillWithSomeTestLinearStates(3)
val linearStates = vaultQuery.queryBy<DummyLinearContract.State>().states

View File

@ -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<InterestRateSwap.State>().states
val states = vault.filterStatesOfType<InterestRateSwap.State>().filter { it.state.data.ref == ref }
val states = vault.filterStatesOfType<InterestRateSwap.State>().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]

View File

@ -567,7 +567,7 @@ class InterestRateSwap : Contract {
requireNotNull(tx.timeWindow) { "must be have a time-window)" }
val groups: List<LedgerTransaction.InOutGroup<State, UniqueIdentifier>> = tx.groupStates { state -> state.linearId }
var atLeastOneCommandProcessed = false
for ((inputs, outputs, key) in groups) {
for ((inputs, outputs, _) in groups) {
val agreeCommand = tx.commands.select<Commands.Agree>().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<AbstractParty>
get() = listOf(fixedLeg.fixedRatePayer, floatingLeg.floatingRatePayer)

View File

@ -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<AbstractParty> get() = listOf(buyer, seller)
override fun isRelevant(ourKeys: Set<PublicKey>): Boolean {

View File

@ -29,7 +29,7 @@ data class PortfolioState(val portfolio: List<StateRef>,
data class Update(val portfolio: List<StateRef>? = null, val valuation: PortfolioValuation? = null)
override val participants: List<AbstractParty> 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 {

View File

@ -21,11 +21,14 @@ class DummyDealContract : Contract {
override fun verify(tx: LedgerTransaction) {}
data class State(
override val contract: Contract = DummyDealContract(),
override val participants: List<AbstractParty> = listOf(),
override val linearId: UniqueIdentifier = UniqueIdentifier(),
override val ref: String) : DealState, QueryableState
override val contract: Contract,
override val participants: List<AbstractParty>,
override val linearId: UniqueIdentifier) : DealState, QueryableState
{
constructor(contract: Contract = DummyDealContract(),
participants: List<AbstractParty> = listOf(),
ref: String) : this(contract, participants, UniqueIdentifier(ref))
override fun isRelevant(ourKeys: Set<PublicKey>): 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")
}

View File

@ -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