corda / net.corda.core.transactions / LedgerTransaction

LedgerTransaction

class LedgerTransaction : FullTransaction

A LedgerTransaction is derived from a WireTransaction. It is the result of doing the following operations:

All the above refer to inputs using a (txhash, output index) pair.

Usage notes:

LedgerTransaction is an abstraction that is meant to be used during the transaction verification stage. It needs full access to input states that might be in transactions that are encrypted and unavailable for code running outside the secure enclave. Also, it might need to deserialize states with code that might not be available on the classpath.

Because of this, trying to create or use a LedgerTransaction for any other purpose then transaction verification can result in unexpected exceptions, which need de be handled.

LedgerTransactions should never be instantiated directly from client code, but rather via WireTransaction.toLedgerTransaction

Types

InOutGroup

data class InOutGroup<out T : ContractState, out K : Any>

A set of related inputs and outputs that are connected by some common attributes. An InOutGroup is calculated using groupStates and is useful for handling cases where a transaction may contain similar but unrelated state evolutions, for example, a transaction that moves cash in two different currencies. The numbers must add up on both sides of the transaction, but the values must be summed independently per currency. Grouping can be used to simplify this logic.

Constructors

<init>

LedgerTransaction(inputs: List<StateAndRef<ContractState>>, outputs: List<TransactionState<ContractState>>, commands: List<CommandWithParties<CommandData>>, attachments: List<Attachment>, id: SecureHash, notary: Party?, timeWindow: TimeWindow?, privacySalt: PrivacySalt)
LedgerTransaction(inputs: List<StateAndRef<ContractState>>, outputs: List<TransactionState<ContractState>>, commands: List<CommandWithParties<CommandData>>, attachments: List<Attachment>, id: SecureHash, notary: Party?, timeWindow: TimeWindow?, privacySalt: PrivacySalt, networkParameters: NetworkParameters)

Properties

attachments

val attachments: List<Attachment>

A list of Attachment objects identified by the transaction that are needed for this transaction to verify.

commands

val commands: List<CommandWithParties<CommandData>>

Arbitrary data passed to the program of each input state.

id

val id: SecureHash

The hash of the original serialised WireTransaction.

inputStates

val inputStates: List<ContractState>

inputs

val inputs: List<StateAndRef<ContractState>>

The resolved input states which will be consumed/invalidated by the execution of this transaction.

networkParameters

val networkParameters: NetworkParameters?

Network parameters that were in force when the transaction was constructed. This is nullable only for backwards compatibility for serialized transactions. In reality this field will always be set when on the normal codepaths.

notary

val notary: Party?

The notary that the tx uses, this must be the same as the notary of all the inputs, or null if there are no inputs.

outputs

val outputs: List<TransactionState<ContractState>>

The outputs created by the transaction.

privacySalt

val privacySalt: PrivacySalt

Random data used to make the transaction hash unpredictable even if the contents can be predicted; needed to avoid some obscure attacks.

referenceStates

val referenceStates: List<ContractState>

references

val references: List<StateAndRef<ContractState>>

Referenced states, which are like inputs but won't be consumed.

timeWindow

val timeWindow: TimeWindow?

The time window within which the tx is valid, will be checked against notary pool member clocks.

Functions

commandsOfType

fun <T : CommandData> commandsOfType(clazz: Class<T>): List<Command<T>>

Helper to simplify getting all Command items with a CommandData of a particular class, interface, or base class.

fun <T : CommandData> commandsOfType(): List<Command<T>>

component1

operator fun component1(): List<StateAndRef<ContractState>>

component10

operator fun component10(): List<StateAndRef<ContractState>>

component2

operator fun component2(): List<TransactionState<ContractState>>

component3

operator fun component3(): List<CommandWithParties<CommandData>>

component4

operator fun component4(): List<Attachment>

component5

operator fun component5(): SecureHash

component6

operator fun component6(): Party?

component7

operator fun component7(): TimeWindow?

component8

operator fun component8(): PrivacySalt

component9

operator fun component9(): NetworkParameters?

copy

fun copy(inputs: List<StateAndRef<ContractState>>, outputs: List<TransactionState<ContractState>>, commands: List<CommandWithParties<CommandData>>, attachments: List<Attachment>, id: SecureHash, notary: Party?, timeWindow: TimeWindow?, privacySalt: PrivacySalt): LedgerTransaction
fun copy(inputs: List<StateAndRef<ContractState>> = this.inputs, outputs: List<TransactionState<ContractState>> = this.outputs, commands: List<CommandWithParties<CommandData>> = this.commands, attachments: List<Attachment> = this.attachments, id: SecureHash = this.id, notary: Party? = this.notary, timeWindow: TimeWindow? = this.timeWindow, privacySalt: PrivacySalt = this.privacySalt, networkParameters: NetworkParameters? = this.networkParameters): LedgerTransaction

equals

fun equals(other: Any?): Boolean

filterCommands

fun <T : CommandData> filterCommands(clazz: Class<T>, predicate: Predicate<T>): List<Command<T>>

Helper to simplify filtering Command items according to a Predicate.

fun <T : CommandData> filterCommands(predicate: (T) -> Boolean): List<Command<T>>

filterInRefs

fun <T : ContractState> filterInRefs(clazz: Class<T>, predicate: Predicate<T>): List<StateAndRef<T>>

Helper to simplify filtering inputs according to a Predicate.

fun <T : ContractState> filterInRefs(predicate: (T) -> Boolean): List<StateAndRef<T>>

filterInputs

fun <T : ContractState> filterInputs(clazz: Class<T>, predicate: Predicate<T>): List<T>

Helper to simplify filtering inputs according to a Predicate.

fun <T : ContractState> filterInputs(predicate: (T) -> Boolean): List<T>

filterReferenceInputRefs

fun <T : ContractState> filterReferenceInputRefs(clazz: Class<T>, predicate: Predicate<T>): List<StateAndRef<T>>

Helper to simplify filtering reference inputs according to a Predicate.

fun <T : ContractState> filterReferenceInputRefs(predicate: (T) -> Boolean): List<StateAndRef<T>>

filterReferenceInputs

fun <T : ContractState> filterReferenceInputs(clazz: Class<T>, predicate: Predicate<T>): List<T>

Helper to simplify filtering reference inputs according to a Predicate.

fun <T : ContractState> filterReferenceInputs(predicate: (T) -> Boolean): List<T>

findCommand

fun <T : CommandData> findCommand(clazz: Class<T>, predicate: Predicate<T>): Command<T>

Helper to simplify finding a single Command items according to a Predicate.

fun <T : CommandData> findCommand(predicate: (T) -> Boolean): Command<T>

findInRef

fun <T : ContractState> findInRef(clazz: Class<T>, predicate: Predicate<T>): StateAndRef<T>

Helper to simplify finding a single input matching a Predicate.

fun <T : ContractState> findInRef(predicate: (T) -> Boolean): StateAndRef<T>

findInput

fun <T : ContractState> findInput(clazz: Class<T>, predicate: Predicate<T>): T

Helper to simplify finding a single input ContractState matching a Predicate.

fun <T : ContractState> findInput(predicate: (T) -> Boolean): T

findReference

fun <T : ContractState> findReference(clazz: Class<T>, predicate: Predicate<T>): T

Helper to simplify finding a single reference inputs ContractState matching a Predicate.

fun <T : ContractState> findReference(predicate: (T) -> Boolean): T

findReferenceInputRef

fun <T : ContractState> findReferenceInputRef(clazz: Class<T>, predicate: Predicate<T>): StateAndRef<T>

Helper to simplify finding a single reference input matching a Predicate.

fun <T : ContractState> findReferenceInputRef(predicate: (T) -> Boolean): StateAndRef<T>

getAttachment

fun getAttachment(index: Int): Attachment
fun getAttachment(id: SecureHash): Attachment

Helper to simplify getting an indexed attachment.

getCommand

fun <T : CommandData> getCommand(index: Int): Command<T>

Helper to simplify getting an indexed command.

getInput

fun getInput(index: Int): ContractState

Helper to simplify getting an indexed input ContractState.

getReferenceInput

fun getReferenceInput(index: Int): ContractState

Helper to simplify getting an indexed reference input ContractState.

groupStates

fun <T : ContractState, K : Any> groupStates(ofType: Class<T>, selector: (T) -> K): List<InOutGroup<T, K>>

Given a type and a function that returns a grouping key, associates inputs and outputs together so that they can be processed as one. The grouping key is any arbitrary object that can act as a map key (so must implement equals and hashCode).

fun <T : ContractState, K : Any> groupStates(selector: (T) -> K): List<InOutGroup<T, K>>

See the documentation for the reflection-based version of groupStates

hashCode

fun hashCode(): Int

inRef

fun <T : ContractState> inRef(index: Int): StateAndRef<T>

Returns the typed input StateAndRef at the specified index

inRefsOfType

fun <T : ContractState> inRefsOfType(clazz: Class<T>): List<StateAndRef<T>>

Helper to simplify getting all inputs states of a particular class, interface, or base class.

fun <T : ContractState> inRefsOfType(): List<StateAndRef<T>>

inputsOfType

fun <T : ContractState> inputsOfType(clazz: Class<T>): List<T>

Helper to simplify getting all inputs states of a particular class, interface, or base class.

fun <T : ContractState> inputsOfType(): List<T>

referenceInputRefsOfType

fun <T : ContractState> referenceInputRefsOfType(clazz: Class<T>): List<StateAndRef<T>>

Helper to simplify getting all reference input states of a particular class, interface, or base class.

fun <T : ContractState> referenceInputRefsOfType(): List<StateAndRef<T>>

referenceInputsOfType

fun <T : ContractState> referenceInputsOfType(clazz: Class<T>): List<T>

Helper to simplify getting all reference input states of a particular class, interface, or base class.

fun <T : ContractState> referenceInputsOfType(): List<T>

toString

fun toString(): String

verify

fun verify(): Unit

Verifies this transaction and runs contract code. At this stage it is assumed that signatures have already been verified.

Inherited Functions

checkBaseInvariants

open fun checkBaseInvariants(): Unit

checkNotaryWhitelisted

fun checkNotaryWhitelisted(): Unit

Make sure the assigned notary is part of the network parameter whitelist.

Extension Functions

contextLogger

fun Any.contextLogger(): Logger

When called from a companion object, returns the logger for the enclosing class.