mirror of
https://github.com/corda/corda.git
synced 2024-12-24 07:06:44 +00:00
Introduce AttachmentConstraint (#1370)
Introduced attachment constraint interface to TransactionState as a base for extension.
This commit is contained in:
parent
67642d1b22
commit
1565b395b6
@ -0,0 +1,15 @@
|
||||
package net.corda.core.contracts
|
||||
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
|
||||
/** Constrain which contract-code-containing attachments can be used with a [ContractState]. */
|
||||
interface AttachmentConstraint {
|
||||
/** Returns whether the given contract attachments can be used with the [ContractState] associated with this constraint object. */
|
||||
fun isSatisfiedBy(attachments: List<Attachment>): Boolean
|
||||
}
|
||||
|
||||
/** An [AttachmentConstraint] where [isSatisfiedBy] always returns true. */
|
||||
@CordaSerializable
|
||||
object AlwaysAcceptAttachmentConstraint : AttachmentConstraint {
|
||||
override fun isSatisfiedBy(attachments: List<Attachment>) = true
|
||||
}
|
@ -71,4 +71,8 @@ data class TransactionState<out T : ContractState> @JvmOverloads constructor(
|
||||
* Note that an encumbered state that is being consumed must have its encumbrance consumed in the same transaction,
|
||||
* otherwise the transaction is not valid.
|
||||
*/
|
||||
val encumbrance: Int? = null)
|
||||
val encumbrance: Int? = null,
|
||||
/**
|
||||
* A validator for the contract attachments on the transaction.
|
||||
*/
|
||||
val constraint: AttachmentConstraint = AlwaysAcceptAttachmentConstraint)
|
@ -1,6 +1,10 @@
|
||||
package net.corda.finance.contracts.asset
|
||||
|
||||
import net.corda.core.contracts.*
|
||||
import net.corda.finance.contracts.NetCommand
|
||||
import net.corda.finance.contracts.NetType
|
||||
import net.corda.finance.contracts.NettableState
|
||||
import net.corda.finance.contracts.asset.Obligation.Lifecycle.NORMAL
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.crypto.entropyToKeyPair
|
||||
import net.corda.core.identity.AbstractParty
|
||||
@ -14,15 +18,10 @@ import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.core.utilities.NonEmptySet
|
||||
import net.corda.core.utilities.getX500Name
|
||||
import net.corda.core.utilities.seconds
|
||||
import net.corda.finance.contracts.NetCommand
|
||||
import net.corda.finance.contracts.NetType
|
||||
import net.corda.finance.contracts.NettableState
|
||||
import net.corda.finance.contracts.asset.Obligation.Lifecycle.NORMAL
|
||||
import net.corda.finance.utils.sumFungibleOrNull
|
||||
import net.corda.finance.utils.sumObligations
|
||||
import net.corda.finance.utils.sumObligationsOrNull
|
||||
import net.corda.finance.utils.sumObligationsOrZero
|
||||
import org.bouncycastle.asn1.x500.X500Name
|
||||
import java.math.BigInteger
|
||||
import java.security.PublicKey
|
||||
import java.time.Duration
|
||||
@ -132,7 +131,7 @@ class Obligation<P : Any> : Contract {
|
||||
val quantity: Long,
|
||||
/** The public key of the entity the contract pays to */
|
||||
val beneficiary: AbstractParty
|
||||
) : FungibleAsset<Obligation.Terms<P>>, NettableState<State<P>, MultilateralNetState<P>> {
|
||||
) : FungibleAsset<Terms<P>>, NettableState<State<P>, MultilateralNetState<P>> {
|
||||
override val amount: Amount<Issued<Terms<P>>> = Amount(quantity, Issued(obligor.ref(0), template))
|
||||
override val exitKeys: Collection<PublicKey> = setOf(beneficiary.owningKey)
|
||||
val dueBefore: Instant = template.dueBefore
|
||||
|
@ -3,7 +3,6 @@ package net.corda.node.services.events
|
||||
import co.paralleluniverse.fibers.Suspendable
|
||||
import net.corda.core.concurrent.CordaFuture
|
||||
import net.corda.core.contracts.*
|
||||
import net.corda.core.crypto.containsAny
|
||||
import net.corda.core.flows.*
|
||||
import net.corda.core.identity.AbstractParty
|
||||
import net.corda.core.identity.Party
|
||||
@ -29,7 +28,6 @@ import org.junit.After
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.security.PublicKey
|
||||
import java.time.Instant
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
@ -3,12 +3,10 @@ package net.corda.vega.contracts
|
||||
import net.corda.core.contracts.Command
|
||||
import net.corda.core.contracts.StateAndContract
|
||||
import net.corda.core.contracts.UniqueIdentifier
|
||||
import net.corda.core.crypto.keys
|
||||
import net.corda.core.identity.AbstractParty
|
||||
import net.corda.core.identity.Party
|
||||
import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.finance.contracts.DealState
|
||||
import java.security.PublicKey
|
||||
|
||||
val IRS_PROGRAM_ID = "net.corda.vega.contracts.OGTrade"
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.corda.vega.contracts
|
||||
|
||||
import net.corda.core.contracts.*
|
||||
import net.corda.core.crypto.keys
|
||||
import net.corda.core.flows.FlowLogicRefFactory
|
||||
import net.corda.core.identity.AbstractParty
|
||||
import net.corda.core.identity.Party
|
||||
@ -9,7 +8,6 @@ import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.finance.contracts.DealState
|
||||
import net.corda.vega.flows.SimmRevaluation
|
||||
import java.security.PublicKey
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneOffset
|
||||
import java.time.temporal.ChronoUnit
|
||||
|
@ -28,7 +28,7 @@ data class DummyContract(val blank: Any? = null) : Contract {
|
||||
* in a different field, however this is a good example of a contract with multiple states.
|
||||
*/
|
||||
data class MultiOwnerState(override val magicNumber: Int = 0,
|
||||
val owners: List<AbstractParty>) : ContractState, State {
|
||||
val owners: List<AbstractParty>) : State {
|
||||
override val participants: List<AbstractParty> get() = owners
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package net.corda.testing.contracts
|
||||
|
||||
import net.corda.core.contracts.Contract
|
||||
import net.corda.core.contracts.UniqueIdentifier
|
||||
import net.corda.core.crypto.containsAny
|
||||
import net.corda.core.identity.AbstractParty
|
||||
import net.corda.core.identity.Party
|
||||
import net.corda.core.schemas.MappedSchema
|
||||
@ -12,7 +11,6 @@ import net.corda.core.transactions.LedgerTransaction
|
||||
import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.finance.contracts.DealState
|
||||
import net.corda.testing.schemas.DummyDealStateSchemaV1
|
||||
import java.security.PublicKey
|
||||
|
||||
val DUMMY_DEAL_PROGRAM_ID = "net.corda.testing.contracts.DummyDealContract"
|
||||
|
||||
|
@ -5,7 +5,6 @@ import net.corda.core.contracts.LinearState
|
||||
import net.corda.core.contracts.UniqueIdentifier
|
||||
import net.corda.core.contracts.requireThat
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.crypto.containsAny
|
||||
import net.corda.core.identity.AbstractParty
|
||||
import net.corda.core.schemas.MappedSchema
|
||||
import net.corda.core.schemas.PersistentState
|
||||
|
Loading…
Reference in New Issue
Block a user