mirror of
https://github.com/corda/corda.git
synced 2025-06-22 17:09:00 +00:00
ENT-10122: Add consuming transaction id to vault states table.
This commit is contained in:
@ -68,7 +68,7 @@ class Vault<out T : ContractState>(val states: Iterable<StateAndRef<T>>) {
|
||||
* other transactions observed, then the changes are observed "net" of those.
|
||||
*/
|
||||
@CordaSerializable
|
||||
data class Update<U : ContractState> @JvmOverloads constructor(
|
||||
data class Update<U : ContractState> constructor(
|
||||
val consumed: Set<StateAndRef<U>>,
|
||||
val produced: Set<StateAndRef<U>>,
|
||||
val flowId: UUID? = null,
|
||||
@ -78,8 +78,20 @@ class Vault<out T : ContractState>(val states: Iterable<StateAndRef<T>>) {
|
||||
* differently.
|
||||
*/
|
||||
val type: UpdateType = UpdateType.GENERAL,
|
||||
val references: Set<StateAndRef<U>> = emptySet()
|
||||
val references: Set<StateAndRef<U>> = emptySet(),
|
||||
val consumingTxIds: Map<StateRef, SecureHash> = emptyMap()
|
||||
) {
|
||||
@JvmOverloads constructor( consumed: Set<StateAndRef<U>>,
|
||||
produced: Set<StateAndRef<U>>,
|
||||
flowId: UUID? = null,
|
||||
/**
|
||||
* Specifies the type of update, currently supported types are general and, contract upgrade and notary change.
|
||||
* Notary change transactions only modify the notary field on states, and potentially need to be handled
|
||||
* differently.
|
||||
*/
|
||||
type: UpdateType = UpdateType.GENERAL,
|
||||
references: Set<StateAndRef<U>> = emptySet()) : this(consumed, produced, flowId, type, references, consumingTxIds = emptyMap())
|
||||
|
||||
/** Checks whether the update contains a state of the specified type. */
|
||||
inline fun <reified T : ContractState> containsType() = consumed.any { it.state.data is T } || produced.any { it.state.data is T } || references.any { it.state.data is T }
|
||||
|
||||
@ -105,7 +117,7 @@ class Vault<out T : ContractState>(val states: Iterable<StateAndRef<T>>) {
|
||||
val combinedConsumed = consumed + (rhs.consumed - produced)
|
||||
// The ordering below matters to preserve ordering of consumed/produced Sets when they are insertion order dependent implementations.
|
||||
val combinedProduced = produced.filter { it !in rhs.consumed }.toSet() + rhs.produced
|
||||
return copy(consumed = combinedConsumed, produced = combinedProduced, references = references + rhs.references)
|
||||
return copy(consumed = combinedConsumed, produced = combinedProduced, references = references + rhs.references, consumingTxIds = consumingTxIds + rhs.consumingTxIds)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
@ -138,6 +150,16 @@ class Vault<out T : ContractState>(val states: Iterable<StateAndRef<T>>) {
|
||||
return Update(consumed, produced, flowId, type, references)
|
||||
}
|
||||
|
||||
/** Additional copy method to maintain backwards compatibility. */
|
||||
fun copy(
|
||||
consumed: Set<StateAndRef<U>>,
|
||||
produced: Set<StateAndRef<U>>,
|
||||
flowId: UUID? = null,
|
||||
type: UpdateType = UpdateType.GENERAL,
|
||||
references: Set<StateAndRef<U>> = emptySet()
|
||||
): Update<U> {
|
||||
return Update(consumed, produced, flowId, type, references, consumingTxIds)
|
||||
}
|
||||
}
|
||||
|
||||
@CordaSerializable
|
||||
|
Reference in New Issue
Block a user