ENT-10122: Add consuming transaction id to vault states table.

This commit is contained in:
Adel El-Beik
2023-07-17 17:58:31 +01:00
parent 6af6af4a80
commit 669d6590af
4 changed files with 34 additions and 6 deletions

View File

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