LedgerTransaction

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

  • Downloading and locally storing all the dependencies of the transaction.

  • Resolving the input states and loading them into memory.

  • Doing some basic key lookups on the Commands to see if any keys are from a recognised party, thus converting the Command objects into CommandWithParties.

  • Deserialising the output states.

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

Constructors

Link copied to clipboard
constructor(inputs: List<StateAndRef<ContractState>>, outputs: List<TransactionState<ContractState>>, commands: List<CommandWithParties<CommandData>>, attachments: List<Attachment>, id: SecureHash, notary: Party?, timeWindow: TimeWindow?, privacySalt: PrivacySalt)
constructor(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)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
data class InOutGroup<out T : ContractState, out K : Any>(val inputs: List<T>, val outputs: List<T>, val groupingKey: K)

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.

Properties

Link copied to clipboard

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

Link copied to clipboard

Arbitrary data passed to the program of each input state.

Link copied to clipboard
Link copied to clipboard
open override val id: SecureHash

The hash of the original serialised WireTransaction.

Link copied to clipboard
open override val inputs: List<StateAndRef<ContractState>>

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

Link copied to clipboard
Link copied to clipboard

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.

Link copied to clipboard
open override 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.

Link copied to clipboard

The outputs created by the transaction.

Link copied to clipboard

Helper property to return a list of ContractState objects, rather than the often less convenient TransactionState

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard
Link copied to clipboard

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

Functions

Link copied to clipboard

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

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
operator fun component4(): List<Attachment>
Link copied to clipboard
operator fun component5(): SecureHash
Link copied to clipboard
operator fun component6(): Party?
Link copied to clipboard
operator fun component7(): TimeWindow?
Link copied to clipboard
operator fun component8(): PrivacySalt
Link copied to clipboard
operator fun component9(): NetworkParameters?
Link copied to clipboard
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
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
inline fun <T : CommandData> filterCommands(crossinline predicate: (T) -> Boolean): List<Command<T>>

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

Helper to simplify filtering Command items according to a Predicate.

Link copied to clipboard
inline fun <T : ContractState> filterInputs(crossinline predicate: (T) -> Boolean): List<T>

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

Helper to simplify filtering inputs according to a Predicate.

Link copied to clipboard
inline fun <T : ContractState> filterInRefs(crossinline predicate: (T) -> Boolean): List<StateAndRef<T>>

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

Helper to simplify filtering inputs according to a Predicate.

Link copied to clipboard
inline fun <T : ContractState> filterOutputs(crossinline predicate: (T) -> Boolean): List<T>

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

Helper to simplify filtering outputs according to a Predicate.

Link copied to clipboard
inline fun <T : ContractState> filterOutRefs(crossinline predicate: (T) -> Boolean): List<StateAndRef<T>>

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

Helper to simplify filtering output StateAndRef items according to a Predicate.

Link copied to clipboard
inline fun <T : ContractState> filterReferenceInputRefs(crossinline predicate: (T) -> Boolean): List<StateAndRef<T>>

Helper to simplify filtering reference inputs according to a Predicate.

Link copied to clipboard
inline fun <T : ContractState> filterReferenceInputs(crossinline predicate: (T) -> Boolean): List<T>

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

Helper to simplify filtering reference inputs according to a Predicate.

Link copied to clipboard
inline fun <T : CommandData> findCommand(crossinline predicate: (T) -> Boolean): Command<T>

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

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

Link copied to clipboard
inline fun <T : ContractState> findInput(crossinline predicate: (T) -> Boolean): T

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

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

Link copied to clipboard
inline fun <T : ContractState> findInRef(crossinline predicate: (T) -> Boolean): StateAndRef<T>

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

Helper to simplify finding a single input matching a Predicate.

Link copied to clipboard
inline fun <T : ContractState> findOutput(crossinline predicate: (T) -> Boolean): T

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

Helper to simplify finding a single output matching a Predicate.

Link copied to clipboard
inline fun <T : ContractState> findOutRef(crossinline predicate: (T) -> Boolean): StateAndRef<T>

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

Helper to simplify finding a single output StateAndRef matching a Predicate.

Link copied to clipboard
inline fun <T : ContractState> findReference(crossinline predicate: (T) -> Boolean): T

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

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

Link copied to clipboard
inline fun <T : ContractState> findReferenceInputRef(crossinline predicate: (T) -> Boolean): StateAndRef<T>

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

Link copied to clipboard

Helper to simplify getting an indexed attachment.

Link copied to clipboard
fun <T : CommandData> getCommand(index: Int): Command<T>

Helper to simplify getting an indexed command.

Link copied to clipboard

Helper to simplify getting an indexed input ContractState.

Link copied to clipboard

Helper to simplify getting an indexed output.

Link copied to clipboard

Helper to simplify getting an indexed reference input ContractState.

Link copied to clipboard
inline fun <T : ContractState, K : Any> groupStates(noinline selector: (T) -> K): List<LedgerTransaction.InOutGroup<T, K>>

See the documentation for the reflection-based version of groupStates

fun <T : ContractState, K : Any> groupStates(ofType: Class<T>, selector: (T) -> K): List<LedgerTransaction.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).

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
inline fun <T : ContractState> inputsOfType(): List<T>

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

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

Link copied to clipboard
fun <T : ContractState> inRef(index: Int): StateAndRef<T>

Returns the typed input StateAndRef at the specified index

Link copied to clipboard

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

Link copied to clipboard
inline fun <T : ContractState> outputsOfType(): List<T>

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

Link copied to clipboard

Returns a StateAndRef for the given output index.

Returns a StateAndRef for the requested output state, or throws IllegalArgumentException if not found.

Link copied to clipboard

Helper to simplify getting all output StateAndRef items of a particular state class, interface, or base class.

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard

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

Link copied to clipboard
fun verify()

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