public class LedgerTransaction
extends BaseTransaction
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 AuthenticatedObject
.
Deserialising the output states.
All the above refer to inputs using a (txhash, output index) pair.
Modifier and Type | Class and Description |
---|---|
static class |
LedgerTransaction.InOutGroup<T extends ContractState,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.
|
Constructor and Description |
---|
LedgerTransaction(java.util.List<? extends net.corda.core.contracts.StateAndRef<?>> inputs,
java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs,
java.util.List<? extends net.corda.core.contracts.AuthenticatedObject<? extends net.corda.core.contracts.CommandData>> commands,
java.util.List<? extends net.corda.core.contracts.Attachment> attachments,
SecureHash id,
Party notary,
java.util.List<? extends java.security.PublicKey> signers,
TimeWindow timeWindow,
TransactionType type)
A LedgerTransaction is derived from a
class WireTransaction . It is the result of doing the following operations: |
Modifier and Type | Method and Description |
---|---|
<T extends CommandData> |
commandsOfType(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. |
boolean |
equals(java.lang.Object other) |
<T extends CommandData> |
filterCommands(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify filtering
class Command items according to a Predicate. |
<T extends ContractState> |
filterInRefs(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify filtering inputs according to a Predicate.
|
<T extends ContractState> |
filterInputs(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify filtering inputs according to a Predicate.
|
<T extends CommandData> |
findCommand(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify finding a single
class Command items according to a Predicate. |
<T extends ContractState> |
findInRef(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify finding a single input matching a Predicate.
|
<T extends ContractState> |
findInput(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify finding a single input
interface ContractState matching a Predicate. |
Attachment |
getAttachment(int index)
Helper to simplify getting an indexed attachment.
|
Attachment |
getAttachment(SecureHash id)
Helper to simplify getting an indexed attachment.
|
java.util.List<net.corda.core.contracts.Attachment> |
getAttachments()
A list of
|
<T extends CommandData> |
getCommand(int index)
Helper to simplify getting an indexed command.
|
java.util.List<net.corda.core.contracts.AuthenticatedObject> |
getCommands()
Arbitrary data passed to the program of each input state.
|
SecureHash |
getId()
The hash of the original serialised WireTransaction.
|
ContractState |
getInput(int index)
Helper to simplify getting an indexed input
interface ContractState . |
java.util.List<net.corda.core.contracts.ContractState> |
getInputStates() |
java.util.List<net.corda.core.contracts.StateAndRef> |
getInputs()
The resolved input states which will be consumed/invalidated by the execution of this transaction.
|
<T extends ContractState,K> |
groupStates(java.lang.Class<T> ofType,
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).
|
int |
hashCode() |
<T extends ContractState> |
inRef(int index)
Returns the typed input StateAndRef at the specified index
|
<T extends ContractState> |
inRefsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all inputs states of a particular class, interface, or base class.
|
<T extends ContractState> |
inputsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all inputs states of a particular class, interface, or base class.
|
void |
verify()
Verifies this transaction and throws an exception if not valid, depending on the type. For general transactions:
|
checkInvariants, equals, filterOutRefs, filterOutputs, findOutRef, findOutput, getInputs, getMustSign, getNotary, getOutput, getOutputStates, getOutputs, getTimeWindow, getType, hashCode, outRef, outRef, outRefsOfType, outputsOfType, toString
getId
public LedgerTransaction(java.util.List<? extends net.corda.core.contracts.StateAndRef<?>> inputs, java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs, java.util.List<? extends net.corda.core.contracts.AuthenticatedObject<? extends net.corda.core.contracts.CommandData>> commands, java.util.List<? extends net.corda.core.contracts.Attachment> attachments, SecureHash id, Party notary, java.util.List<? extends java.security.PublicKey> signers, TimeWindow timeWindow, TransactionType type)
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 AuthenticatedObject
.
Deserialising the output states.
All the above refer to inputs using a (txhash, output index) pair.
inputs
- The resolved input states which will be consumed/invalidated by the execution of this transaction.commands
- Arbitrary data passed to the program of each input state.attachments
- A list of interface Attachment
objects identified by the transaction that are needed for this transaction to verify.id
- The hash of the original serialised WireTransaction.class WireTransaction
,
class Command
,
class Command
,
class AuthenticatedObject
public java.util.List<net.corda.core.contracts.ContractState> getInputStates()
public <T extends ContractState> StateAndRef<T> inRef(int index)
Returns the typed input StateAndRef at the specified index
index
- The index into the inputs.class StateAndRef
public void verify()
Verifies this transaction and throws an exception if not valid, depending on the type. For general transactions:
The contracts are run with the transaction as the input.
The list of keys mentioned in commands is compared against the signers list.
public boolean equals(java.lang.Object other)
public int hashCode()
public <T extends ContractState,K> java.util.List<net.corda.core.transactions.LedgerTransaction.InOutGroup> groupStates(java.lang.Class<T> ofType, 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.
public ContractState getInput(int index)
Helper to simplify getting an indexed input interface ContractState
.
index
- the position of the item in the inputs.class StateAndRef
at the requested indexinterface ContractState
public <T extends ContractState> java.util.List<T> inputsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all inputs states of a particular class, interface, or base class.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface ContractState
.public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> inRefsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all inputs states of a particular class, interface, or base class.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface ContractState
.class StateAndRef
matching the clazz restriction.public <T extends ContractState> java.util.List<T> filterInputs(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify filtering inputs according to a Predicate.
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.public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> filterInRefs(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify filtering inputs according to a Predicate.
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.clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface ContractState
.class StateAndRef
matching the predicate and clazz restrictions.public <T extends ContractState> T findInput(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify finding a single input interface ContractState
matching a Predicate.
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.interface ContractState
public <T extends ContractState> StateAndRef<T> findInRef(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify finding a single input matching a Predicate.
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.public <T extends CommandData> Command<T> getCommand(int index)
Helper to simplify getting an indexed command.
index
- the position of the item in the commands.public <T extends CommandData> java.util.List<net.corda.core.contracts.Command> commandsOfType(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.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface CommandData
.interface CommandData
values matching the clazz restriction.class Command
,
interface CommandData
public <T extends CommandData> java.util.List<net.corda.core.contracts.Command> filterCommands(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify filtering class Command
items according to a Predicate.
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.class Command
items with interface CommandData
values matching the predicate and clazz restrictions.class Command
public <T extends CommandData> Command<T> findCommand(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify finding a single class Command
items according to a Predicate.
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.class Command
item with interface CommandData
values matching the predicate and clazz restrictions.class Command
public Attachment getAttachment(int index)
Helper to simplify getting an indexed attachment.
index
- the position of the item in the attachments.public Attachment getAttachment(SecureHash id)
Helper to simplify getting an indexed attachment.
id
- the SecureHash of the desired attachment.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.
public java.util.List<net.corda.core.contracts.AuthenticatedObject> getCommands()
Arbitrary data passed to the program of each input state.
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.
interface Attachment
public SecureHash getId()
The hash of the original serialised WireTransaction.