mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
Base types and changes required for the Contract Constraints work.
This commit is contained in:
parent
05e94e7425
commit
0de6994ef5
@ -0,0 +1,12 @@
|
||||
package net.corda.core.contracts
|
||||
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
|
||||
/**
|
||||
* Wrap an attachment in this if it is to be used as an executable contract attachment
|
||||
*
|
||||
* @property attachment The attachment representing the contract JAR
|
||||
* @property contract The contract name contained within the JAR
|
||||
*/
|
||||
@CordaSerializable
|
||||
class ContractAttachment(val attachment: Attachment, val contract: ContractClassName) : Attachment by attachment
|
@ -16,6 +16,12 @@ sealed class TransactionVerificationException(val txId: SecureHash, message: Str
|
||||
class ContractRejection(txId: SecureHash, contract: Contract, cause: Throwable)
|
||||
: TransactionVerificationException(txId, "Contract verification failed: ${cause.message}, contract: $contract", cause)
|
||||
|
||||
class ContractConstraintRejection(txId: SecureHash, contractClass: String)
|
||||
: TransactionVerificationException(txId, "Contract constraints failed for $contractClass", null)
|
||||
|
||||
class MissingAttachmentRejection(txId: SecureHash, contractClass: String)
|
||||
: TransactionVerificationException(txId, "Contract constraints failed, could not find attachment for: $contractClass", null)
|
||||
|
||||
class ContractCreationError(txId: SecureHash, contractClass: String, cause: Throwable)
|
||||
: TransactionVerificationException(txId, "Contract verification failed: ${cause.message}, could not create contract class: $contractClass", cause)
|
||||
|
||||
|
@ -6,6 +6,8 @@ import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.nio.file.FileAlreadyExistsException
|
||||
|
||||
typealias AttachmentId = SecureHash
|
||||
|
||||
/**
|
||||
* An attachment store records potentially large binary objects, identified by their hash.
|
||||
*/
|
||||
@ -14,7 +16,7 @@ interface AttachmentStorage {
|
||||
* Returns a handle to a locally stored attachment, or null if it's not known. The handle can be used to open
|
||||
* a stream for the data, which will be a zip/jar file.
|
||||
*/
|
||||
fun openAttachment(id: SecureHash): Attachment?
|
||||
fun openAttachment(id: AttachmentId): Attachment?
|
||||
|
||||
/**
|
||||
* Inserts the given attachment into the store, does *not* close the input stream. This can be an intensive
|
||||
@ -28,6 +30,6 @@ interface AttachmentStorage {
|
||||
* @throws IOException if something went wrong.
|
||||
*/
|
||||
@Throws(FileAlreadyExistsException::class, IOException::class)
|
||||
fun importAttachment(jar: InputStream): SecureHash
|
||||
fun importAttachment(jar: InputStream): AttachmentId
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
package net.corda.core.transactions
|
||||
|
||||
import net.corda.core.contracts.ContractState
|
||||
import net.corda.core.contracts.TransactionState
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
|
||||
/**
|
||||
* A contract attachment was missing when trying to automatically attach all known contract attachments
|
||||
*
|
||||
* @property states States which have contracts that do not have corresponding attachments in the attachment store.
|
||||
*/
|
||||
@CordaSerializable
|
||||
class MissingContractAttachments(val states: List<TransactionState<ContractState>>)
|
||||
: Exception("Cannot find contract attachments for ${states.map { it.contract }.distinct() }")
|
@ -0,0 +1,8 @@
|
||||
package net.corda.nodeapi.internal.serialization
|
||||
|
||||
import net.corda.core.crypto.sha256
|
||||
import net.corda.core.internal.AbstractAttachment
|
||||
|
||||
class GeneratedAttachment(bytes: ByteArray) : AbstractAttachment({ bytes }) {
|
||||
override val id = bytes.sha256()
|
||||
}
|
@ -15,7 +15,7 @@ import net.corda.testing.schemas.DummyLinearStateSchemaV2
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneOffset.UTC
|
||||
|
||||
val DUMMY_LINEAR_CONTRACT_PROGRAM_ID = "net.corda.testing.contracts.DummyLinearContract"
|
||||
const val DUMMY_LINEAR_CONTRACT_PROGRAM_ID = "net.corda.testing.contracts.DummyLinearContract"
|
||||
|
||||
class DummyLinearContract : Contract {
|
||||
override fun verify(tx: LedgerTransaction) {
|
||||
|
@ -0,0 +1,9 @@
|
||||
package net.corda.testing.node
|
||||
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.internal.AbstractAttachment
|
||||
|
||||
/**
|
||||
* An attachment with only an ID and an empty data array
|
||||
*/
|
||||
class MockAttachment(override val id: SecureHash = SecureHash.zeroHash) : AbstractAttachment({ ByteArray(0) })
|
Loading…
Reference in New Issue
Block a user