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

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.

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

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

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

val attachments: List<Attachment>

commands

Arbitrary data passed to the program of each input state.

val commands: List<CommandWithParties<CommandData>>

digestService

val digestService: DigestService

id

The hash of the original serialised WireTransaction.

val id: SecureHash

inputs

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

val inputs: List<StateAndRef<ContractState>>

inputStates

val inputStates: List<ContractState>

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.

val networkParameters: NetworkParameters?

notary

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.

val notary: Party?

outputs

The outputs created by the transaction.

val outputs: List<TransactionState<ContractState>>

privacySalt

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

val privacySalt: PrivacySalt

references

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

val references: List<StateAndRef<ContractState>>

referenceStates

val referenceStates: List<ContractState>

timeWindow

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

val timeWindow: TimeWindow?

Functions

commandsOfType

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

fun <T : CommandData> commandsOfType(clazz: Class<T>): List<Command<T>>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

Helper to simplify filtering Command items according to a Predicate.

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

filterInputs

Helper to simplify filtering inputs according to a Predicate.

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

filterInRefs

Helper to simplify filtering inputs according to a Predicate.

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

filterReferenceInputRefs

Helper to simplify filtering reference inputs according to a Predicate.

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

filterReferenceInputs

Helper to simplify filtering reference inputs according to a Predicate.

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

findCommand

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

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

findInput

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

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

findInRef

Helper to simplify finding a single input matching a Predicate.

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

findReference

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

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

findReferenceInputRef

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

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

getAttachment

Helper to simplify getting an indexed attachment.

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

getCommand

Helper to simplify getting an indexed command.

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

getInput

Helper to simplify getting an indexed input ContractState.

fun getInput(index: Int): ContractState

getReferenceInput

Helper to simplify getting an indexed reference input ContractState.

fun getReferenceInput(index: Int): ContractState

groupStates

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(ofType: Class<T>, selector: (T) -> K): List<InOutGroup<T, K>>

See the documentation for the reflection-based version of groupStates

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

hashCode

fun hashCode(): Int

inputsOfType

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

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

inRef

Returns the typed input StateAndRef at the specified index

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

inRefsOfType

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

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

referenceInputRefsOfType

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

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

referenceInputsOfType

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

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

specialise

We need a way to customise transaction verification inside the Node without changing either the wire format or any public APIs.

fun specialise(alternateVerifier: (LedgerTransaction, SerializationContext) -> Verifier): LedgerTransaction

toString

fun toString(): String

transform

Pass all of this LedgerTransaction object's serialized state to a transformer function.

fun <T> transform(transformer: (List<ComponentGroup>, List<SerializedStateAndRef>, List<SerializedStateAndRef>) -> T): T

verify

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

fun verify(): Unit

Companion Object Functions

createForContractVerify

This factory function will create an instance of LedgerTransaction that will be used for contract verification. See BasicVerifier and DeterministicVerifier.

fun createForContractVerify(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?, references: List<StateAndRef<ContractState>>, digestService: DigestService): LedgerTransaction