LedgerTransaction
Keywords: net.corda.core.transactions.LedgerTransaction class
Date: 2023-09-18

net.corda.core.transactions

## Class LedgerTransaction

- net.corda.core.transactions.BaseTransaction
- - FullTransaction
  - - net.corda.core.transactions.LedgerTransaction

- All Implemented Interfaces:
    NamedByHash

      public class LedgerTransaction
      extends FullTransaction

  A LedgerTransaction is derived from a `class 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 `class Command`s to see if any keys are from a recognised party, thus converting the `class Command` objects into `class CommandWithParties`.

  - Deserialising the output states.

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

  Usage notes:

  `class 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 `class LedgerTransaction` for any other purpose then transaction verification can result in unexpected exceptions, which need de be handled.

  `class LedgerTransaction`s should never be instantiated directly from client code, but rather via WireTransaction.toLedgerTransaction

  See Also:
    `class WireTransaction`, `class Command`, `class Command`, `class CommandWithParties`, `class LedgerTransaction`, `class LedgerTransaction`, `class LedgerTransaction`

- - ### Field Detail

    - #### Companion

          public static net.corda.core.transactions.LedgerTransaction.Companion Companion

  - ### Constructor Detail

    - #### LedgerTransaction

          @Deprecated
          public LedgerTransaction(@NotNull
                                               java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs,
                                               @NotNull
                                               java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs,
                                               @NotNull
                                               java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands,
                                               @NotNull
                                               java.util.List<? extends net.corda.core.contracts.Attachment> attachments,
                                               @NotNull
                                               SecureHash id,
                                               @Nullable
                                               Party notary,
                                               @Nullable
                                               TimeWindow timeWindow,
                                               @NotNull
                                               PrivacySalt privacySalt)

      Deprecated.

    - #### LedgerTransaction

          @Deprecated
          public LedgerTransaction(@NotNull
                                               java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs,
                                               @NotNull
                                               java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs,
                                               @NotNull
                                               java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands,
                                               @NotNull
                                               java.util.List<? extends net.corda.core.contracts.Attachment> attachments,
                                               @NotNull
                                               SecureHash id,
                                               @Nullable
                                               Party notary,
                                               @Nullable
                                               TimeWindow timeWindow,
                                               @NotNull
                                               PrivacySalt privacySalt,
                                               @NotNull
                                               NetworkParameters networkParameters)

      Deprecated.

  - ### Method Detail

    - #### getInputStates

          @NotNull
          public java.util.List<net.corda.core.contracts.ContractState> getInputStates()

    - #### getReferenceStates

          @NotNull
          public java.util.List<net.corda.core.contracts.ContractState> getReferenceStates()

    - #### inRef

          @NotNull
          public <T extends ContractState> StateAndRef<T> inRef(int index)

      Returns the typed input StateAndRef at the specified index

      Parameters:
        `index` - The index into the inputs.
      Returns:
        The `class StateAndRef`

    - #### verify

          public void verify()

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

      The contract verification logic is run in a custom classloader created for the current transaction. This classloader is only used during verification and does not leak to the client code.

      The reason for this is that classes (contract states) deserialized in this classloader would actually be a different type from what the calling code would expect.

      Throws:
        `TransactionVerificationException` - if anything goes wrong.

    - #### transform

          @CordaInternal
          public <T> T transform(@NotNull
                                                kotlin.jvm.functions.Function3<? super java.util.List<? extends net.corda.core.transactions.ComponentGroup>,? super java.util.List<net.corda.core.internal.SerializedStateAndRef>,? super java.util.List<net.corda.core.internal.SerializedStateAndRef>,? extends T> transformer)

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

      See Also:
        `class LedgerTransaction`, `transformer`

    - #### specialise

          @CordaInternal
           @NotNull
          public LedgerTransaction specialise(@NotNull
                                                                       kotlin.jvm.functions.Function2<? super net.corda.core.transactions.LedgerTransaction,? super net.corda.core.serialization.SerializationContext,? extends net.corda.core.internal.Verifier> alternateVerifier)

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

    - #### groupStates

          @NotNull
          public <T extends ContractState,K> java.util.List<net.corda.core.transactions.LedgerTransaction.InOutGroup> groupStates(@NotNull
                                                                                                                                           java.lang.Class<T> ofType,
                                                                                                                                           @NotNull
                                                                                                                                           kotlin.jvm.functions.Function1<? super T,? extends K> selector)

      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).

      The purpose of this function is to simplify the writing of verification logic for transactions that may contain similar but unrelated state evolutions which need to be checked independently. Consider a transaction that simultaneously moves both dollars and euros (e.g. is an atomic FX trade). There may be multiple dollar inputs and multiple dollar outputs, depending on things like how fragmented the owner's vault is and whether various privacy techniques are in use. The quantity of dollars on the output side must sum to the same as on the input side, to ensure no money is being lost track of. This summation and checking must be repeated independently for each currency. To solve this, you would use groupStates with a type of Cash.State and a selector that returns the currency field: the resulting list can then be iterated over to perform the per-currency calculation.

    - #### getInput

          @NotNull
          public ContractState getInput(int index)

      Helper to simplify getting an indexed input `interface ContractState`.

      Parameters:
        `index` - the position of the item in the inputs.
      Returns:
        The `class StateAndRef` at the requested index
      See Also:
        `interface ContractState`

    - #### getReferenceInput

          @NotNull
          public ContractState getReferenceInput(int index)

      Helper to simplify getting an indexed reference input `interface ContractState`.

      Parameters:
        `index` - the position of the item in the references.
      Returns:
        The `class StateAndRef` at the requested index.
      See Also:
        `interface ContractState`

    - #### inputsOfType

          @NotNull
          public <T extends ContractState> java.util.List<T> inputsOfType(@NotNull
                                                                                   java.lang.Class<T> clazz)

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

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of `interface ContractState`.
      Returns:
        the possibly empty list of inputs matching the clazz restriction.

    - #### referenceInputsOfType

          @NotNull
          public <T extends ContractState> java.util.List<T> referenceInputsOfType(@NotNull
                                                                                            java.lang.Class<T> clazz)

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

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of `interface ContractState`.
      Returns:
        the possibly empty list of inputs matching the clazz restriction.

    - #### inRefsOfType

          @NotNull
          public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> inRefsOfType(@NotNull
                                                                                                                      java.lang.Class<T> clazz)

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

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of `interface ContractState`.
      Returns:
        the possibly empty list of inputs `class StateAndRef` matching the clazz restriction.

    - #### referenceInputRefsOfType

          @NotNull
          public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> referenceInputRefsOfType(@NotNull
                                                                                                                                  java.lang.Class<T> clazz)

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

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of `interface ContractState`.
      Returns:
        the possibly empty list of reference inputs `class StateAndRef` matching the clazz restriction.

    - #### filterInputs

          @NotNull
          public <T extends ContractState> java.util.List<T> filterInputs(@NotNull
                                                                                   java.lang.Class<T> clazz,
                                                                                   @NotNull
                                                                                   java.util.function.Predicate<T> predicate)

      Helper to simplify filtering inputs according to a Predicate.

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of `interface ContractState`.
        `predicate` - A filtering function taking a state of type T and returning true if it should be included in the list.The class filtering is applied before the predicate.
      Returns:
        the possibly empty list of input states matching the predicate and clazz restrictions.
      See Also:
        Predicate

    - #### filterReferenceInputs

          @NotNull
          public <T extends ContractState> java.util.List<T> filterReferenceInputs(@NotNull
                                                                                            java.lang.Class<T> clazz,
                                                                                            @NotNull
                                                                                            java.util.function.Predicate<T> predicate)

      Helper to simplify filtering reference inputs according to a Predicate.

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of `interface ContractState`.
        `predicate` - A filtering function taking a state of type T and returning true if it should be included in the list.The class filtering is applied before the predicate.
      Returns:
        the possibly empty list of reference states matching the predicate and clazz restrictions.
      See Also:
        Predicate

    - #### filterInRefs

          @NotNull
          public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> filterInRefs(@NotNull
                                                                                                                      java.lang.Class<T> clazz,
                                                                                                                      @NotNull
                                                                                                                      java.util.function.Predicate<T> predicate)

      Helper to simplify filtering inputs according to a Predicate.

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of `interface ContractState`.
        `predicate` - A filtering function taking a state of type T and returning true if it should be included in the list.The class filtering is applied before the predicate.
      Returns:
        the possibly empty list of inputs `class StateAndRef` matching the predicate and clazz restrictions.
      See Also:
        Predicate

    - #### filterReferenceInputRefs

          @NotNull
          public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> filterReferenceInputRefs(@NotNull
                                                                                                                                  java.lang.Class<T> clazz,
                                                                                                                                  @NotNull
                                                                                                                                  java.util.function.Predicate<T> predicate)

      Helper to simplify filtering reference inputs according to a Predicate.

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of `interface ContractState`.
        `predicate` - A filtering function taking a state of type T and returning true if it should be included in the list.The class filtering is applied before the predicate.
      Returns:
        the possibly empty list of references `class StateAndRef` matching the predicate and clazz restrictions.
      See Also:
        Predicate

    - #### findInput

          @NotNull
          public <T extends ContractState> T findInput(@NotNull
                                                                java.lang.Class<T> clazz,
                                                                @NotNull
                                                                java.util.function.Predicate<T> predicate)

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

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of ContractState.
        `predicate` - A filtering function taking a state of type T and returning true if this is the desired item.The class filtering is applied before the predicate.
      Returns:
        the single item matching the predicate.
      Throws:
        `IllegalArgumentException` - if no item, or multiple items are found matching the requirements.
      See Also:
        `interface ContractState`, Predicate

    - #### findReference

          @NotNull
          public <T extends ContractState> T findReference(@NotNull
                                                                    java.lang.Class<T> clazz,
                                                                    @NotNull
                                                                    java.util.function.Predicate<T> predicate)

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

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of ContractState.
        `predicate` - A filtering function taking a state of type T and returning true if this is the desired item.The class filtering is applied before the predicate.
      Returns:
        the single item matching the predicate.
      Throws:
        `IllegalArgumentException` - if no item, or multiple items are found matching the requirements.
      See Also:
        `interface ContractState`, Predicate

    - #### findInRef

          @NotNull
          public <T extends ContractState> StateAndRef<T> findInRef(@NotNull
                                                                             java.lang.Class<T> clazz,
                                                                             @NotNull
                                                                             java.util.function.Predicate<T> predicate)

      Helper to simplify finding a single input matching a Predicate.

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of ContractState.
        `predicate` - A filtering function taking a state of type T and returning true if this is the desired item.The class filtering is applied before the predicate.
      Returns:
        the single item matching the predicate.
      Throws:
        `IllegalArgumentException` - if no item, or multiple items are found matching the requirements.
      See Also:
        Predicate

    - #### findReferenceInputRef

          @NotNull
          public <T extends ContractState> StateAndRef<T> findReferenceInputRef(@NotNull
                                                                                         java.lang.Class<T> clazz,
                                                                                         @NotNull
                                                                                         java.util.function.Predicate<T> predicate)

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

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of ContractState.
        `predicate` - A filtering function taking a state of type T and returning true if this is the desired item.The class filtering is applied before the predicate.
      Returns:
        the single item matching the predicate.
      Throws:
        `IllegalArgumentException` - if no item, or multiple items are found matching the requirements.
      See Also:
        Predicate

    - #### getCommand

          @NotNull
          public <T extends CommandData> Command<T> getCommand(int index)

      Helper to simplify getting an indexed command.

      Parameters:
        `index` - the position of the item in the commands.
      Returns:
        The Command at the requested index

    - #### commandsOfType

          @NotNull
          public <T extends CommandData> java.util.List<net.corda.core.contracts.Command> commandsOfType(@NotNull
                                                                                                                  java.lang.Class<T> clazz)

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

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of `interface CommandData`.
      Returns:
        the possibly empty list of commands with `interface CommandData` values matching the clazz restriction.
      See Also:
        `class Command`, `interface CommandData`

    - #### filterCommands

          @NotNull
          public <T extends CommandData> java.util.List<net.corda.core.contracts.Command> filterCommands(@NotNull
                                                                                                                  java.lang.Class<T> clazz,
                                                                                                                  @NotNull
                                                                                                                  java.util.function.Predicate<T> predicate)

      Helper to simplify filtering `class Command` items according to a Predicate.

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of `interface CommandData`.
        `predicate` - A filtering function taking a `interface CommandData` item of type T and returning true if it should be included in the list.The class filtering is applied before the predicate.
      Returns:
        the possibly empty list of `class Command` items with `interface CommandData` values matching the predicate and clazz restrictions.
      See Also:
        `class Command`, Predicate

    - #### findCommand

          @NotNull
          public <T extends CommandData> Command<T> findCommand(@NotNull
                                                                         java.lang.Class<T> clazz,
                                                                         @NotNull
                                                                         java.util.function.Predicate<T> predicate)

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

      Parameters:
        `clazz` - The class type used for filtering via an Class.isInstance check.`clazz` must be an extension of `interface CommandData`.
        `predicate` - A filtering function taking a `interface CommandData` item of type T and returning true if it should be included in the list.The class filtering is applied before the predicate.
      Returns:
        the `class Command` item with `interface CommandData` values matching the predicate and clazz restrictions.
      Throws:
        `IllegalArgumentException` - if no items, or multiple items matched the requirements.
      See Also:
        `class Command`, Predicate

    - #### getAttachment

          @NotNull
          public Attachment getAttachment(int index)

      Helper to simplify getting an indexed attachment.

      Parameters:
        `index` - the position of the item in the attachments.
      Returns:
        The Attachment at the requested index.

    - #### getAttachment

          @NotNull
          public Attachment getAttachment(@NotNull
                                                   SecureHash id)

      Helper to simplify getting an indexed attachment.

      Parameters:
        `id` - the SecureHash of the desired attachment.
      Returns:
        The Attachment with the matching id.
      Throws:
        `IllegalArgumentException` - if no item matches the id.

    - #### component1

          @NotNull
          public java.util.List<net.corda.core.contracts.StateAndRef> component1()

    - #### component2

          @NotNull
          public java.util.List<net.corda.core.contracts.TransactionState> component2()

    - #### component3

          @NotNull
          public java.util.List<net.corda.core.contracts.CommandWithParties> component3()

    - #### component4

          @NotNull
          public java.util.List<net.corda.core.contracts.Attachment> component4()

    - #### component5

          @NotNull
          public SecureHash component5()

    - #### component6

          @Nullable
          public Party component6()

    - #### component7

          @Nullable
          public TimeWindow component7()

    - #### component8

          @NotNull
          public PrivacySalt component8()

    - #### component9

          @Nullable
          public NetworkParameters component9()

    - #### component10

          @NotNull
          public java.util.List<net.corda.core.contracts.StateAndRef> component10()

    - #### equals

          public boolean equals(@Nullable
                                java.lang.Object other)

    - #### hashCode

          public int hashCode()

    - #### toString

          @NotNull
          public java.lang.String toString()

    - #### copy

          @Deprecated
           @NotNull
          public LedgerTransaction copy(@NotNull
                                                              java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs,
                                                              @NotNull
                                                              java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs,
                                                              @NotNull
                                                              java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands,
                                                              @NotNull
                                                              java.util.List<? extends net.corda.core.contracts.Attachment> attachments,
                                                              @NotNull
                                                              SecureHash id,
                                                              @Nullable
                                                              Party notary,
                                                              @Nullable
                                                              TimeWindow timeWindow,
                                                              @NotNull
                                                              PrivacySalt privacySalt)

      Deprecated.

    - #### copy

          @Deprecated
           @NotNull
          public LedgerTransaction copy(@NotNull
                                                              java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs,
                                                              @NotNull
                                                              java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs,
                                                              @NotNull
                                                              java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands,
                                                              @NotNull
                                                              java.util.List<? extends net.corda.core.contracts.Attachment> attachments,
                                                              @NotNull
                                                              SecureHash id,
                                                              @Nullable
                                                              Party notary,
                                                              @Nullable
                                                              TimeWindow timeWindow,
                                                              @NotNull
                                                              PrivacySalt privacySalt,
                                                              @Nullable
                                                              NetworkParameters networkParameters)

      Deprecated.

    - #### getInputs

          @NotNull
          public java.util.List<net.corda.core.contracts.StateAndRef> getInputs()

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

    - #### getOutputs

          @NotNull
          public java.util.List<net.corda.core.contracts.TransactionState> getOutputs()

      The outputs created by the transaction.

    - #### getCommands

          @NotNull
          public java.util.List<net.corda.core.contracts.CommandWithParties> getCommands()

      Arbitrary data passed to the program of each input state.

    - #### getAttachments

          @NotNull
          public java.util.List<net.corda.core.contracts.Attachment> getAttachments()

      A list of

      `interface Attachment` objects identified by the transaction that are needed for this transaction to verify.

      See Also:
        `interface Attachment`

    - #### getId

          @NotNull
          public SecureHash getId()

      The hash of the original serialised WireTransaction.

    - #### getNotary

          @Nullable
          public Party getNotary()

      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.

    - #### getTimeWindow

          @Nullable
          public TimeWindow getTimeWindow()

      The time window within which the tx is valid,

      will be checked against notary pool member clocks.

    - #### getPrivacySalt

          @NotNull
          public PrivacySalt getPrivacySalt()

      Random data used to make the transaction hash unpredictable even if the contents can be predicted;

      needed to avoid some obscure attacks.

    - #### getNetworkParameters

          @Nullable
          public NetworkParameters getNetworkParameters()

      Network parameters that were in force when the transaction was constructed.

      This is nullable only for backwardscompatibility for serialized transactions. In reality this field will always be set when on the normal codepaths.

    - #### getReferences

          @NotNull
          public java.util.List<net.corda.core.contracts.StateAndRef> getReferences()

      Referenced states,

      which are like inputs but won't be consumed.

    - #### getDigestService

          @NotNull
          public DigestService getDigestService()