corda / net.corda.core.contracts

Package net.corda.core.contracts

This package contains the base data types for smarts contracts implemented in Corda. To implement a new contract start with Contract, or see the examples in net.corda.finance.contracts.

Corda smart contracts are a combination of state held on the distributed ledger, and verification logic which defines which transformations of state are valid.

Types

AlwaysAcceptAttachmentConstraint

object AlwaysAcceptAttachmentConstraint : AttachmentConstraint

An AttachmentConstraint where isSatisfiedBy always returns true.

Amount

data class Amount<T : Any> : Comparable<Amount<T>>

Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest representable units. The nominal quantity represented by each individual token is equal to the displayTokenSize. The scale property of the displayTokenSize should correctly reflect the displayed decimal places and is used when rounding conversions from indicative/displayed amounts in BigDecimal to Amount occur via the Amount.fromDecimal method.

AmountTransfer

class AmountTransfer<T : Any, P : Any>

This class represents a possibly negative transfer of tokens from one vault state to another, possibly at a future date.

Attachment

interface Attachment : NamedByHash

An attachment is a ZIP (or an optionally signed JAR) that contains one or more files. Attachments are meant to contain public static data which can be referenced from transactions and utilised from contracts. Good examples of how attachments are meant to be used include:

AttachmentConstraint

interface AttachmentConstraint

Constrain which contract-code-containing attachment can be used with a ContractState.

AutomaticHashConstraint

object AutomaticHashConstraint : AttachmentConstraint

This AttachmentConstraint is a convenience class that will be automatically resolved to a HashAttachmentConstraint. The resolution occurs in TransactionBuilder.toWireTransaction and uses the TransactionState.contract value to find a corresponding loaded Cordapp that contains such a contract, and then uses that Cordapp as the Attachment.

Command

data class Command<T : CommandData>

Command data/content plus pubkey pair: the signature is stored at the end of the serialized bytes

CommandAndState

data class CommandAndState

Return structure for OwnableState.withNewOwner

CommandData

interface CommandData

Marker interface for classes that represent commands

CommandWithParties

data class CommandWithParties<out T : CommandData>

A Command where the signing parties have been looked up if they have a well known/recognised institutional key.

ComponentGroupEnum

enum class ComponentGroupEnum

An enum, for which each property corresponds to a transaction component group. The position in the enum class declaration (ordinal) is used for component-leaf ordering when computing the Merkle tree.

Contract

interface Contract

Implemented by a program that implements business logic on the shared ledger. All participants run this code for every net.corda.core.transactions.LedgerTransaction they see on the network, for every input and output state. All contracts must accept the transaction for it to be accepted: failure of any aborts the entire thing. The time is taken from a trusted time-window attached to the transaction itself i.e. it is NOT necessarily the current time.

ContractAttachment

class ContractAttachment : Attachment

Wrap an attachment in this if it is to be used as an executable contract attachment

ContractState

interface ContractState

A contract state (or just "state") contains opaque data used by a contract program. It can be thought of as a disk file that the program can use to persist data across transactions. States are immutable: once created they are never updated, instead, any changes must generate a new successor state. States can be updated (consumed) only once: the notary is responsible for ensuring there is no "double spending" by only signing a transaction if the input states are all free.

FungibleAsset

interface FungibleAsset<T : Any> : OwnableState

Interface for contract states representing assets which are fungible, countable and issued by a specific party. States contain assets which are equivalent (such as cash of the same currency), so records of their existence can be merged or split as needed where the issuer is the same. For instance, dollars issued by the Fed are fungible and countable (in cents), barrels of West Texas crude are fungible and countable (oil from two small containers can be poured into one large container), shares of the same class in a specific company are fungible and countable, and so on.

HashAttachmentConstraint

data class HashAttachmentConstraint : AttachmentConstraint

An AttachmentConstraint that verifies by hash

Issued

data class Issued<out P : Any>

The Issued data class holds the details of an on ledger digital asset. In particular it gives the public credentials of the entity that created these digital tokens and the particular product represented.

LinearState

interface LinearState : ContractState

A state that evolves by superseding itself, all of which share the common "linearId".

MoveCommand

interface MoveCommand : CommandData

A common move command for contract states which can change owner.

NamedByHash

interface NamedByHash

Implemented by anything that can be named by a secure hash value (e.g. transactions, attachments).

OwnableState

interface OwnableState : ContractState

A contract state that can have a single owner.

PartyAndReference

data class PartyAndReference

Reference to something being stored or issued by a party e.g. in a vault or (more likely) on their normal ledger. The reference is intended to be encrypted so it's meaningless to anyone other than the party.

PrivacySalt

class PrivacySalt : OpaqueBytes

A privacy salt is required to compute nonces per transaction component in order to ensure that an adversary cannot use brute force techniques and reveal the content of a Merkle-leaf hashed value. Because this salt serves the role of the seed to compute nonces, its size and entropy should be equal to the underlying hash function used for Merkle tree generation, currently SecureHash.SHA256, which has an output of 32 bytes. There are two constructors, one that generates a new 32-bytes random salt, and another that takes a ByteArray input. The latter is required in cases where the salt value needs to be pre-generated (agreed between transacting parties), but it is highlighted that one should always ensure it has sufficient entropy.

Requirements

object Requirements

Defines a simple domain specific language for the specification of financial contracts. Currently covers:

SchedulableState

interface SchedulableState : ContractState

Scheduled

interface Scheduled

Something which is scheduled to happen at a point in time.

ScheduledActivity

data class ScheduledActivity : Scheduled

This class represents the lifecycle activity that a contract state of type LinearState would like to perform at a given point in time. e.g. run a fixing flow.

ScheduledStateRef

data class ScheduledStateRef : Scheduled

Represents a contract state (unconsumed output) of type LinearState and a point in time that a lifecycle event is expected to take place for that contract state.

SourceAndAmount

data class SourceAndAmount<T : Any, out P : Any>

Simple data class to associate the origin, owner, or holder of a particular Amount object.

StateAndContract

data class StateAndContract

A convenience class for passing around a state and it's contract

StateAndRef

data class StateAndRef<out T : ContractState>

A StateAndRef is simply a (state, ref) pair. For instance, a vault (which holds available assets) contains these.

StateRef

data class StateRef

A stateref is a pointer (reference) to a state, this is an equivalent of an "outpoint" in Bitcoin. It records which transaction defined the state and where in that transaction it was.

TimeWindow

abstract class TimeWindow

An interval on the time-line; not a single instantaneous point.

TokenizableAssetInfo

interface TokenizableAssetInfo

This interface is used by Amount to determine the conversion ratio from indicative/displayed asset amounts in BigDecimal to fungible tokens represented by Amount objects.

TransactionState

data class TransactionState<out T : ContractState>

A wrapper for ContractState containing additional platform-level state information and contract information. This is the definitive state that is stored on the ledger and used in transaction outputs.

TypeOnlyCommandData

abstract class TypeOnlyCommandData : CommandData

Commands that inherit from this are intended to have no data items: it's only their presence that matters.

UniqueIdentifier

data class UniqueIdentifier : Comparable<UniqueIdentifier>

This class provides a truly unique identifier of a trade, state, or other business object, bound to any existing external ID. Equality and comparison are based on the unique ID only; if two states somehow have the same UUID but different external IDs, it would indicate a problem with handling of IDs.

UpgradedContract

interface UpgradedContract<in OldState : ContractState, out NewState : ContractState> : Contract

Interface which can upgrade state objects issued by a contract to a new state object issued by a different contract.

Annotations

LegalProseReference

annotation class LegalProseReference

The annotated Contract implements the legal prose identified by the given URI.

Exceptions

AttachmentResolutionException

class AttachmentResolutionException : FlowException

InsufficientBalanceException

class InsufficientBalanceException : FlowException

TransactionResolutionException

class TransactionResolutionException : FlowException

TransactionVerificationException

sealed class TransactionVerificationException : FlowException

Type Aliases

ContractClassName

typealias ContractClassName = String

Extensions for External Classes

kotlin.collections.Collection

kotlin.collections.Iterable

Functions

hash

fun ContractState.hash(): SecureHash

Returns the SHA-256 hash of the serialised contents of this state (not cached!)

requireThat

fun <R> requireThat(body: Requirements.() -> R): R

verifyMoveCommand

fun <T : MoveCommand> verifyMoveCommand(inputs: List<OwnableState>, commands: List<CommandWithParties<CommandData>>): MoveCommand

Simple functionality for verifying a move command. Verifies that each input has a signature from its owning key.

withoutIssuer

fun <T : Any> Amount<Issued<T>>.withoutIssuer(): Amount<T>

Strips the issuer and returns an Amount of the raw token directly. This is useful when you are mixing code that cares about specific issuers with code that will accept any, or which is imposing issuer constraints via some other mechanism and the additional type safety is not wanted.