Class TransactionBuilder
-
- All Implemented Interfaces:
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.
-
-
Constructor Summary
Constructors Constructor Description TransactionBuilder(Party notary, UUID lockId, List<StateRef> inputs, List<SecureHash> attachments, List<TransactionState<ContractState>> outputs, List<Command<?>> commands, TimeWindow window, PrivacySalt privacySalt)
TransactionBuilder(Party notary)
TransactionBuilder(Party notary, UUID lockId, List<StateRef> inputs, List<SecureHash> attachments, List<TransactionState<ContractState>> outputs, List<Command<?>> commands, TimeWindow window, PrivacySalt privacySalt, List<StateRef> references, ServiceHub serviceHub)
-
Method Summary
Modifier and Type Method Description final Party
getNotary()
final Unit
setNotary(Party notary)
final UUID
getLockId()
final Unit
setLockId(UUID lockId)
final TransactionBuilder
copy()
Creates a copy of the builder. final <Error class: unknown class>
withItems(Object items)
A more convenient way to add items to this transaction that calls the add* methods for you based on type final WireTransaction
toWireTransaction(ServicesForResolution services)
Generates a WireTransaction from this builder, resolves any AutomaticPlaceholderConstraint, and selects the attachments to use for this transaction. final WireTransaction
toWireTransaction(ServicesForResolution services, Integer schemeId)
Generates a WireTransaction from this builder, resolves any AutomaticPlaceholderConstraint, and selects the attachments to use for this transaction. final WireTransaction
toWireTransaction(ServicesForResolution services, Integer schemeId, Map<Object, Object> properties)
Generates a WireTransaction from this builder, resolves any AutomaticPlaceholderConstraint, and selects the attachments to use for this transaction. final LedgerTransaction
toLedgerTransaction(ServiceHub services)
final Unit
verify(ServiceHub services)
<Error class: unknown class>
addReferenceState(ReferencedStateAndRef<?> referencedStateAndRef)
Adds a reference input StateRef to the transaction. <Error class: unknown class>
addInputState(StateAndRef<?> stateAndRef)
Adds an input StateRef to the transaction. final <Error class: unknown class>
addAttachment(SecureHash attachmentId)
Adds an attachment with the specified hash to the TransactionBuilder. final <Error class: unknown class>
addOutputState(TransactionState<?> state)
Adds an output state to the transaction. final TransactionBuilder
addOutputState(ContractState state, String contract, Party notary, Integer encumbrance, AttachmentConstraint constraint)
Adds an output state, with associated contract code (and constraints), and notary, to the transaction. final TransactionBuilder
addOutputState(ContractState state, String contract, AttachmentConstraint constraint)
Adds an output state. final TransactionBuilder
addOutputState(ContractState state, AttachmentConstraint constraint)
Adds an output state with the specified constraint. final <Error class: unknown class>
addCommand(Command<?> arg)
Adds a Command to the transaction. final <Error class: unknown class>
addCommand(CommandData data, PublicKey keys)
Adds a Command to the transaction, specified by the encapsulated CommandData object and required list of signing PublicKeys. final <Error class: unknown class>
addCommand(CommandData data, List<PublicKey> keys)
final <Error class: unknown class>
setTimeWindow(TimeWindow timeWindow)
Sets the TimeWindow for this transaction, replacing the existing TimeWindow if there is one. final <Error class: unknown class>
setTimeWindow(Instant time, Duration timeTolerance)
The TimeWindow for the transaction can also be defined as time +/- timeTolerance. final <Error class: unknown class>
setPrivacySalt(PrivacySalt privacySalt)
final List<StateRef>
inputStates()
Returns an immutable list of input StateRefs. final List<StateRef>
referenceStates()
Returns an immutable list of reference input StateRefs. final List<SecureHash>
attachments()
Returns an immutable list of attachment hashes. final List<TransactionState<?>>
outputStates()
Returns an immutable list of output TransactionStates. final List<Command<?>>
commands()
Returns an immutable list of Commands. final SignedTransaction
toSignedTransaction(KeyManagementService keyManagementService, PublicKey publicKey, SignatureMetadata signatureMetadata, ServicesForResolution services)
Sign the built transaction and return it. -
-
Constructor Detail
-
TransactionBuilder
TransactionBuilder(Party notary, UUID lockId, List<StateRef> inputs, List<SecureHash> attachments, List<TransactionState<ContractState>> outputs, List<Command<?>> commands, TimeWindow window, PrivacySalt privacySalt)
-
TransactionBuilder
TransactionBuilder(Party notary)
-
TransactionBuilder
TransactionBuilder(Party notary, UUID lockId, List<StateRef> inputs, List<SecureHash> attachments, List<TransactionState<ContractState>> outputs, List<Command<?>> commands, TimeWindow window, PrivacySalt privacySalt, List<StateRef> references, ServiceHub serviceHub)
- Parameters:
notary
- Notary used for the transaction.
-
-
Method Detail
-
copy
final TransactionBuilder copy()
Creates a copy of the builder.
-
withItems
final <Error class: unknown class> withItems(Object items)
A more convenient way to add items to this transaction that calls the add* methods for you based on type
-
toWireTransaction
final WireTransaction toWireTransaction(ServicesForResolution services)
Generates a WireTransaction from this builder, resolves any AutomaticPlaceholderConstraint, and selects the attachments to use for this transaction.
-
toWireTransaction
final WireTransaction toWireTransaction(ServicesForResolution services, Integer schemeId)
Generates a WireTransaction from this builder, resolves any AutomaticPlaceholderConstraint, and selects the attachments to use for this transaction.
- Parameters:
schemeId
- is used to specify the CustomSerializationScheme used to serialize each component of the componentGroups of the WireTransaction.
-
toWireTransaction
final WireTransaction toWireTransaction(ServicesForResolution services, Integer schemeId, Map<Object, Object> properties)
Generates a WireTransaction from this builder, resolves any AutomaticPlaceholderConstraint, and selects the attachments to use for this transaction.
- Parameters:
schemeId
- is used to specify the CustomSerializationScheme used to serialize each component of the componentGroups of the WireTransaction.properties
- a list of properties to add to the SerializationSchemeContext these properties can be accessed in CustomSerializationScheme.serialize when serializing the componentGroups of the wire transaction but might not be available when deserializing.
-
toLedgerTransaction
final LedgerTransaction toLedgerTransaction(ServiceHub services)
-
verify
final Unit verify(ServiceHub services)
-
addReferenceState
<Error class: unknown class> addReferenceState(ReferencedStateAndRef<?> referencedStateAndRef)
Adds a reference input 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.
-
addInputState
<Error class: unknown class> addInputState(StateAndRef<?> stateAndRef)
Adds an input StateRef to the transaction.
-
addAttachment
final <Error class: unknown class> addAttachment(SecureHash attachmentId)
Adds an attachment with the specified hash to the TransactionBuilder.
-
addOutputState
final <Error class: unknown class> addOutputState(TransactionState<?> state)
Adds an output state to the transaction.
-
addOutputState
final TransactionBuilder addOutputState(ContractState state, String contract, Party notary, Integer encumbrance, AttachmentConstraint constraint)
Adds an output state, with associated contract code (and constraints), and notary, to the transaction.
-
addOutputState
final TransactionBuilder addOutputState(ContractState state, String contract, AttachmentConstraint constraint)
Adds an output state. A default notary must be specified during builder construction to use this method
-
addOutputState
final TransactionBuilder addOutputState(ContractState state, AttachmentConstraint constraint)
Adds an output state with the specified constraint.
-
addCommand
final <Error class: unknown class> addCommand(Command<?> arg)
Adds a Command to the transaction.
-
addCommand
final <Error class: unknown class> addCommand(CommandData data, PublicKey keys)
Adds a Command to the transaction, specified by the encapsulated CommandData object and required list of signing PublicKeys.
-
addCommand
final <Error class: unknown class> addCommand(CommandData data, List<PublicKey> keys)
-
setTimeWindow
final <Error class: unknown class> setTimeWindow(TimeWindow timeWindow)
Sets the TimeWindow for this transaction, replacing the existing 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.
-
setTimeWindow
final <Error class: unknown class> setTimeWindow(Instant time, Duration timeTolerance)
The 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.
-
setPrivacySalt
final <Error class: unknown class> setPrivacySalt(PrivacySalt privacySalt)
-
inputStates
final List<StateRef> inputStates()
Returns an immutable list of input StateRefs.
-
referenceStates
final List<StateRef> referenceStates()
Returns an immutable list of reference input StateRefs.
-
attachments
final List<SecureHash> attachments()
Returns an immutable list of attachment hashes.
-
outputStates
final List<TransactionState<?>> outputStates()
Returns an immutable list of output TransactionStates.
-
toSignedTransaction
final SignedTransaction toSignedTransaction(KeyManagementService keyManagementService, PublicKey publicKey, SignatureMetadata signatureMetadata, 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.
-
-
-
-