public class TransactionBuilder
A TransactionBuilder is a transaction class that's mutable (unlike the others which are all immutable). It is intended to be passed around contracts that may edit it by adding new states/commands. Then once the states and commands are right, this class can be used as a holding bucket to gather signatures from multiple parties.
The builder can be customised for specific transaction types, e.g. where additional processing is needed before adding a state/command.
public static net.corda.core.transactions.TransactionBuilder.Companion Companion
public TransactionBuilder(@Nullable
Party notary,
@NotNull
java.util.UUID lockId,
@NotNull
java.util.List<net.corda.core.contracts.StateRef> inputs,
@NotNull
java.util.List<net.corda.core.crypto.SecureHash> attachments,
@NotNull
java.util.List<net.corda.core.contracts.TransactionState> outputs,
@NotNull
java.util.List<net.corda.core.contracts.Command> commands,
@Nullable
TimeWindow window,
@NotNull
PrivacySalt privacySalt,
@NotNull
java.util.List<net.corda.core.contracts.StateRef> references,
@Nullable
ServiceHub serviceHub)
A TransactionBuilder is a transaction class that's mutable (unlike the others which are all immutable). It is intended to be passed around contracts that may edit it by adding new states/commands. Then once the states and commands are right, this class can be used as a holding bucket to gather signatures from multiple parties.
The builder can be customised for specific transaction types, e.g. where additional processing is needed before adding a state/command.
notary - Notary used for the transaction. If null, this indicates the transaction DOES NOT have a notary.When this is set to a non-null value, an output state can be added by just passing in a interface ContractState – aclass TransactionState with this notary specified will be generated automatically.public TransactionBuilder()
A TransactionBuilder is a transaction class that's mutable (unlike the others which are all immutable). It is intended to be passed around contracts that may edit it by adding new states/commands. Then once the states and commands are right, this class can be used as a holding bucket to gather signatures from multiple parties.
The builder can be customised for specific transaction types, e.g. where additional processing is needed before adding a state/command.
public TransactionBuilder(@Nullable
Party notary,
@NotNull
java.util.UUID lockId,
@NotNull
java.util.List<net.corda.core.contracts.StateRef> inputs,
@NotNull
java.util.List<net.corda.core.crypto.SecureHash> attachments,
@NotNull
java.util.List<net.corda.core.contracts.TransactionState> outputs,
@NotNull
java.util.List<net.corda.core.contracts.Command> commands,
@Nullable
TimeWindow window,
@NotNull
PrivacySalt privacySalt)
public TransactionBuilder(@NotNull
Party notary)
@NotNull public TransactionBuilder copy()
Creates a copy of the builder.
@NotNull public TransactionBuilder withItems(@NotNull java.lang.Object... items)
A more convenient way to add items to this transaction that calls the add* methods for you based on type
@NotNull public WireTransaction toWireTransaction(@NotNull ServicesForResolution services)
Generates a class WireTransaction from this builder, resolves any class AutomaticPlaceholderConstraint, and selects the attachments to use for this transaction.
ZoneVersionTooLowException - if there are reference states and the zone minimum platform version is less than 4.class WireTransaction,
class AutomaticPlaceholderConstraint@NotNull public WireTransaction toWireTransaction(@NotNull ServicesForResolution services, int schemeId)
Generates a class WireTransaction from this builder, resolves any class AutomaticPlaceholderConstraint, and selects the attachments to use for this transaction.
schemeId - is used to specify the interface CustomSerializationScheme used to serialize each component of the componentGroups of the class WireTransaction.This is an experimental feature.ZoneVersionTooLowException - if there are reference states and the zone minimum platform version is less than 4.class WireTransaction,
class AutomaticPlaceholderConstraint@NotNull public WireTransaction toWireTransaction(@NotNull ServicesForResolution services, int schemeId, @NotNull java.util.Map<java.lang.Object,? extends java.lang.Object> properties)
Generates a class WireTransaction from this builder, resolves any class AutomaticPlaceholderConstraint, and selects the attachments to use for this transaction.
schemeId - is used to specify the interface CustomSerializationScheme used to serialize each component of the componentGroups of the class WireTransaction.This is an experimental feature.properties - a list of properties to add to the interface SerializationSchemeContext these properties can be accessed in CustomSerializationScheme.serializewhen serializing the componentGroups of the wire transaction but might not be available when deserializing.ZoneVersionTooLowException - if there are reference states and the zone minimum platform version is less than 4.class WireTransaction,
class AutomaticPlaceholderConstraint@NotNull public LedgerTransaction toLedgerTransaction(@NotNull ServiceHub services)
public void verify(@NotNull
ServiceHub services)
@NotNull public TransactionBuilder addReferenceState(@NotNull ReferencedStateAndRef<?> referencedStateAndRef)
Adds a reference input class StateRef to the transaction.
Note: Reference states are only supported on Corda networks running a minimum platform version of 4.
toWireTransaction will throw an IllegalStateException if called in such an environment.
class StateRef,
toWireTransaction,
IllegalStateException@NotNull public TransactionBuilder addInputState(@NotNull StateAndRef<?> stateAndRef)
Adds an input class StateRef to the transaction.
class StateRef@NotNull public TransactionBuilder addAttachment(@NotNull SecureHash attachmentId)
Adds an attachment with the specified hash to the TransactionBuilder.
@NotNull public TransactionBuilder addOutputState(@NotNull TransactionState<?> state)
Adds an output state to the transaction.
@JvmOverloads @NotNull public TransactionBuilder addOutputState(@NotNull ContractState state, @NotNull java.lang.String contract, @NotNull Party notary, @Nullable java.lang.Integer encumbrance, @NotNull AttachmentConstraint constraint)
Adds an output state, with associated contract code (and constraints), and notary, to the transaction.
@JvmOverloads @NotNull public TransactionBuilder addOutputState(@NotNull ContractState state, @NotNull java.lang.String contract, @NotNull Party notary, @Nullable java.lang.Integer encumbrance)
Adds an output state, with associated contract code (and constraints), and notary, to the transaction.
@JvmOverloads @NotNull public TransactionBuilder addOutputState(@NotNull ContractState state, @NotNull java.lang.String contract, @NotNull Party notary)
Adds an output state, with associated contract code (and constraints), and notary, to the transaction.
@JvmOverloads @NotNull public TransactionBuilder addOutputState(@NotNull ContractState state, @NotNull Party notary)
Adds an output state, with associated contract code (and constraints), and notary, to the transaction.
@JvmOverloads @NotNull public TransactionBuilder addOutputState(@NotNull ContractState state, @NotNull java.lang.String contract, @NotNull AttachmentConstraint constraint)
Adds an output state. A default notary must be specified during builder construction to use this method
@JvmOverloads @NotNull public TransactionBuilder addOutputState(@NotNull ContractState state, @NotNull java.lang.String contract)
Adds an output state. A default notary must be specified during builder construction to use this method
@JvmOverloads @NotNull public TransactionBuilder addOutputState(@NotNull ContractState state)
Adds an output state. A default notary must be specified during builder construction to use this method
@NotNull public TransactionBuilder addOutputState(@NotNull ContractState state, @NotNull AttachmentConstraint constraint)
Adds an output state with the specified constraint.
@NotNull public TransactionBuilder addCommand(@NotNull Command<?> arg)
Adds a class Command to the transaction.
class Command@NotNull public TransactionBuilder addCommand(@NotNull CommandData data, @NotNull java.security.PublicKey... keys)
Adds a class Command to the transaction, specified by the encapsulated interface CommandData object and required list of
signing PublicKeys.
class Command,
interface CommandData,
PublicKey@NotNull public TransactionBuilder addCommand(@NotNull CommandData data, @NotNull java.util.List<? extends java.security.PublicKey> keys)
@NotNull public TransactionBuilder setTimeWindow(@NotNull TimeWindow timeWindow)
Sets the class TimeWindow for this transaction, replacing the existing class TimeWindow if there is one. To be valid, the
transaction must then be signed by the notary service within this window of time. In this way, the notary acts as
the Timestamp Authority.
class TimeWindow,
class TimeWindow@NotNull public TransactionBuilder setTimeWindow(@NotNull java.time.Instant time, @NotNull java.time.Duration timeTolerance)
The class TimeWindow for the transaction can also be defined as time +/- timeTolerance. The tolerance should be
chosen such that your code can finish building the transaction and sending it to the Timestamp Authority within
that window of time, taking into account factors such as network latency. Transactions being built by a group of
collaborating parties may therefore require a higher time tolerance than a transaction being built by a single
node.
class TimeWindow,
time,
timeTolerance@NotNull public TransactionBuilder setPrivacySalt(@NotNull PrivacySalt privacySalt)
@NotNull public java.util.List<net.corda.core.contracts.StateRef> inputStates()
Returns an immutable list of input class StateRefs.
class StateRef@NotNull public java.util.List<net.corda.core.contracts.StateRef> referenceStates()
Returns an immutable list of reference input class StateRefs.
class StateRef@NotNull public java.util.List<net.corda.core.crypto.SecureHash> attachments()
Returns an immutable list of attachment hashes.
@NotNull public java.util.List<net.corda.core.contracts.TransactionState> outputStates()
Returns an immutable list of output class TransactionStates.
class TransactionState@NotNull public java.util.List<net.corda.core.contracts.Command> commands()
Returns an immutable list of class Commands.
class Command@NotNull public SignedTransaction toSignedTransaction(@NotNull KeyManagementService keyManagementService, @NotNull java.security.PublicKey publicKey, @NotNull SignatureMetadata signatureMetadata, @NotNull ServicesForResolution services)
Sign the built transaction and return it. This is an internal function for use by the service hub, please use ServiceHub.signInitialTransaction instead.
@Nullable public Party getNotary()
Notary used for the transaction.
If null, this indicates the transaction DOES NOT have a notary.When this is set to a non-null value, an output state can be added by just passing in a interface ContractState – aclass TransactionState with this notary specified will be generated automatically.
interface ContractState,
class TransactionStatepublic void setNotary(@Nullable
Party p)
Notary used for the transaction.
If null, this indicates the transaction DOES NOT have a notary.When this is set to a non-null value, an output state can be added by just passing in a interface ContractState – aclass TransactionState with this notary specified will be generated automatically.
p - Notary used for the transaction. If null, this indicates the transaction DOES NOT have a notary.When this is set to a non-null value, an output state can be added by just passing in a interface ContractState – aclass TransactionState with this notary specified will be generated automatically.interface ContractState,
class TransactionState@NotNull public java.util.UUID getLockId()
public void setLockId(@NotNull
java.util.UUID p)
@NotNull protected java.util.List<net.corda.core.contracts.StateRef> getInputs()
@NotNull protected java.util.List<net.corda.core.crypto.SecureHash> getAttachments()
@NotNull protected java.util.List<net.corda.core.contracts.TransactionState> getOutputs()
@NotNull protected java.util.List<net.corda.core.contracts.Command> getCommands()
@Nullable protected TimeWindow getWindow()
protected void setWindow(@Nullable
TimeWindow p)
@NotNull protected PrivacySalt getPrivacySalt()
protected void setPrivacySalt(@NotNull
PrivacySalt p)
@NotNull protected java.util.List<net.corda.core.contracts.StateRef> getReferences()
@Nullable protected ServiceHub getServiceHub()