com.r3corda.core.contracts

Package com.r3corda.core.contracts

Types

AccrualAdjustment enum class AccrualAdjustment

Simple enum for returning accurals adjusted or unadjusted. We dont actually do anything with this yet though, so its ignored for now.

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

Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest representable units. Note that quantity is not necessarily 1/100ths of a currency unit, but are the actual smallest amount used in whatever underlying thing the amount represents.

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:

AuthenticatedObject data class AuthenticatedObject<out T : Any>

Wraps an object that was signed by a public key, which may be a well known/recognised institutional key.

BilateralNettableState interface BilateralNettableState<N : BilateralNettableState<N>>

Interface for state objects that support being netted with other state objects.

BusinessCalendar open class BusinessCalendar

A business calendar performs date calculations that take into account national holidays and weekends. This is a typical feature of financial contracts, in which a business may not want a payment event to fall on a day when no staff are around to handle problems.

Command data class Command

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

CommandData interface CommandData

Marker interface for classes that represent commands

Commodity data class Commodity
Contract interface Contract

Implemented by a program that implements business logic on the shared ledger. All participants run this code for every 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 timestamp attached to the transaction itself i.e. it is NOT necessarily the current time.

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.

DateRollConvention enum class DateRollConvention

This reflects what happens if a date on which a business event is supposed to happen actually falls upon a non-working day. Depending on the accounting requirement, we can move forward until we get to a business day, or backwards. There are some additional rules which are explained in the individual cases below.

DateRollDirection enum class DateRollDirection

This is utilised in the DateRollConvention class to determine which way we should initially step when finding a business day.

DayCountBasisDay enum class DayCountBasisDay

This forms the day part of the "Day Count Basis" used for interest calculation. Note that the first character cannot be a number (enum naming constraints), so we drop that in the toString lest some people get confused.

DayCountBasisYear enum class DayCountBasisYear

This forms the year part of the "Day Count Basis" used for interest calculation.

DealState interface DealState : LinearState

Interface representing an agreement that exposes various attributes that are common. Implementing it simplifies implementation of general protocols that manipulate many agreement types.

DummyContract class DummyContract : Contract
DummyState data class DummyState : ContractState

Dummy state for use in testing. Not part of any real contract.

Expression data class Expression

Represents a textual expression of e.g. a formula

ExpressionDeserializer object ExpressionDeserializer
ExpressionSerializer object ExpressionSerializer
Fix data class Fix : CommandData

A Fix represents a named interest rate, on a given day, for a given duration. It can be embedded in a tx.

FixOf data class FixOf

A FixOf identifies the question side of a fix: what day, tenor and type of fix ("LIBOR", "EURIBOR" etc)

FixableDealState interface FixableDealState : DealState

Interface adding fixing specific methods.

Frequency enum class Frequency

Frequency at which an event occurs - the enumerator also casts to an integer specifying the number of times per year that would divide into (eg annually = 1, semiannual = 2, monthly = 12 etc).

IssuanceDefinition interface IssuanceDefinition

Marker interface for data classes that represent the issuance state for a contract. These are intended as templates from which the state object is initialised.

IssueCommand interface IssueCommand : CommandData

A common issue command, to enforce that issue commands have a nonce value.

Issued data class Issued<out P>

Definition for an issued product, which can be cash, a cash-like thing, assets, or generally anything else thats quantifiable with integer quantities.

LedgerTransaction data class LedgerTransaction : NamedByHash

A LedgerTransaction wraps the data needed to calculate one or more successor states from a set of input states. It is the first step after extraction from a WireTransaction. The signatures at this point have been lined up with the commands from the wire, and verified/looked up.

LinearState interface LinearState : ContractState

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

MoveCommand interface MoveCommand : CommandData

A common move command for contracts which can change owner.

MultilateralNettableState interface MultilateralNettableState<out T : Any>

Interface for state objects that support being netted with other state objects.

NamedByHash interface NamedByHash

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

NetType enum class NetType

Enum for the types of netting that can be applied to state objects. Exact behaviour for each type of netting is left to the contract to determine.

NettableState interface NettableState<N : BilateralNettableState<N>, T : Any> : BilateralNettableState<N>, MultilateralNettableState<T>
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 its meaningless to anyone other than the party.

PaymentRule enum class PaymentRule

Whether the payment should be made before the due date, or after it.

Requirements class Requirements
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 protocol.

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.

SignedTransaction data class SignedTransaction : NamedByHash

Container for a WireTransaction and attached signatures.

StateAndRef data class StateAndRef<out T : ContractState>

A StateAndRef is simply a (state, ref) pair. For instance, a wallet (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.

Tenor data class Tenor

Placeholder class for the Tenor datatype - which is a standardised duration of time until maturity

TimestampCommand data class TimestampCommand : CommandData

If present in a transaction, contains a time that was verified by the timestamping authority/authorities whose public keys are identified in the containing Command object. The true time must be between (after, before).

TransactionBuilder open class TransactionBuilder

A TransactionBuilder is a transaction class thats mutable (unlike the others which are all immutable). It is intended to be passed around contracts that may edit it by adding new states/commands. Then once the states and commands are right, this class can be used as a holding bucket to gather signatures from multiple parties.

TransactionForContract data class TransactionForContract

A transaction to be passed as input to a contract verification function. Defines helper methods to simplify verification logic in contracts.

TransactionGraphSearch class TransactionGraphSearch : Callable<List<WireTransaction>>

Given a map of transaction id to SignedTransaction, performs a breadth first search of the dependency graph from the starting point down in order to find transactions that match the given query criteria.

TransactionState data class TransactionState<out T : ContractState>

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

TransactionType sealed class TransactionType

Defines transaction build & validation logic for a specific transaction type

TypeOnlyCommandData abstract class TypeOnlyCommandData : CommandData

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

WireTransaction data class WireTransaction : NamedByHash

Transaction ready for serialisation, without any signatures attached.

Exceptions

TransactionConflictException class TransactionConflictException : Exception
TransactionResolutionException class TransactionResolutionException : Exception
TransactionVerificationException sealed class TransactionVerificationException : Exception

Extensions for External Classes

java.time.LocalDate
java.util.Currency
kotlin.Double
kotlin.Int
kotlin.collections.Collection
kotlin.collections.Iterable
kotlin.collections.List

Properties

CHF val CHF: Currency
DUMMY_PROGRAM_ID val DUMMY_PROGRAM_ID: DummyContract
FCOJ val FCOJ: Commodity
GBP val GBP: Currency
R val R: Requirements
USD val USD: Currency

Functions

DOLLARS fun DOLLARS(amount: Int): Amount<Currency>
fun DOLLARS(amount: Double): Amount<Currency>
FCOJ fun FCOJ(amount: Int): Amount<Commodity>
POUNDS fun POUNDS(amount: Int): Amount<Currency>
SWISS_FRANCS fun SWISS_FRANCS(amount: Int): Amount<Currency>
calculateDaysBetween fun calculateDaysBetween(startDate: LocalDate, endDate: LocalDate, dcbYear: DayCountBasisYear, dcbDay: DayCountBasisDay): Int
commodity fun commodity(code: String): Commodity
currency fun currency(code: String): Currency

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

hash fun ContractState.hash(): SecureHash

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

issued by infix fun Commodity.issued by(deposit: PartyAndReference): Issued<Commodity>
infix fun Amount<Currency>.issued by(deposit: PartyAndReference): Amount<Issued<Currency>>
issuedBy infix fun Commodity.issuedBy(deposit: PartyAndReference): Issued<Commodity>
infix fun Amount<Currency>.issuedBy(deposit: PartyAndReference): Amount<Issued<Currency>>
requireThat fun <R> requireThat(body: Requirements.() -> R): R
toLedgerTransaction fun WireTransaction.toLedgerTransaction(services: ServiceHub): LedgerTransaction

Looks up identities and attachments from storage to generate a LedgerTransaction. A transaction is expected to have been fully resolved using the resolution protocol by this point.

fun SignedTransaction.toLedgerTransaction(services: ServiceHub): LedgerTransaction

Calls verify to check all required signatures are present, and then calls WireTransaction.toLedgerTransaction with the passed in ServiceHub to resolve the dependencies, returning an unverified LedgerTransaction.

verifyMoveCommand fun <T : MoveCommand> verifyMoveCommand(inputs: List<OwnableState>, tx: TransactionForContract): MoveCommand
fun <T : MoveCommand> verifyMoveCommand(inputs: List<OwnableState>, commands: List<AuthenticatedObject<CommandData>>): MoveCommand

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

with notary infix fun <T : ContractState> T.with notary(newNotary: Party): TransactionState<T>

Wraps the ContractState in a TransactionState object

withNotary infix fun <T : ContractState> T.withNotary(newNotary: Party): TransactionState<T>
withoutIssuer fun <T> 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.