TransactionBuilder

open class TransactionBuilder(var notary: Party? = null, var lockId: UUID = defaultLockId(), inputs: MutableList<StateRef> = arrayListOf(), attachments: MutableList<AttachmentId> = arrayListOf(), outputs: MutableList<TransactionState<ContractState>> = arrayListOf(), commands: MutableList<Command<*>> = arrayListOf(), window: TimeWindow? = null, privacySalt: PrivacySalt = PrivacySalt(), references: MutableList<StateRef> = arrayListOf(), serviceHub: ServiceHub? = (Strand.currentStrand() as? FlowStateMachine<*>)?.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.

Parameters

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 ContractState – a TransactionState with this notary specified will be generated automatically.

Constructors

Link copied to clipboard
constructor(notary: Party? = null, lockId: UUID = defaultLockId(), inputs: MutableList<StateRef> = arrayListOf(), attachments: MutableList<AttachmentId> = arrayListOf(), outputs: MutableList<TransactionState<ContractState>> = arrayListOf(), commands: MutableList<Command<*>> = arrayListOf(), window: TimeWindow? = null, privacySalt: PrivacySalt = PrivacySalt())
constructor(notary: Party)
constructor(notary: Party? = null, lockId: UUID = defaultLockId(), inputs: MutableList<StateRef> = arrayListOf(), attachments: MutableList<AttachmentId> = arrayListOf(), outputs: MutableList<TransactionState<ContractState>> = arrayListOf(), commands: MutableList<Command<*>> = arrayListOf(), window: TimeWindow? = null, privacySalt: PrivacySalt = PrivacySalt(), references: MutableList<StateRef> = arrayListOf(), serviceHub: ServiceHub? = (Strand.currentStrand() as? FlowStateMachine<*>)?.serviceHub)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun addAttachment(attachmentId: AttachmentId): <Error class: unknown class>

Adds an attachment with the specified hash to the TransactionBuilder.

Link copied to clipboard
fun addCommand(arg: Command<*>): <Error class: unknown class>

Adds a Command to the transaction.

fun addCommand(data: CommandData, vararg keys: PublicKey): <Error class: unknown class>

Adds a Command to the transaction, specified by the encapsulated CommandData object and required list of signing PublicKeys.

fun addCommand(data: CommandData, keys: List<PublicKey>): <Error class: unknown class>
Link copied to clipboard
open fun addInputState(stateAndRef: StateAndRef<*>): <Error class: unknown class>

Adds an input StateRef to the transaction.

Link copied to clipboard
fun addOutputState(state: TransactionState<*>): <Error class: unknown class>

Adds an output state to the transaction.

Adds an output state with the specified constraint.

fun addOutputState(state: ContractState, contract: ContractClassName = requireNotNullContractClassName(state), constraint: AttachmentConstraint = AutomaticPlaceholderConstraint): TransactionBuilder

Adds an output state. A default notary must be specified during builder construction to use this method

fun addOutputState(state: ContractState, contract: ContractClassName = requireNotNullContractClassName(state), notary: Party, encumbrance: Int? = null, constraint: AttachmentConstraint = AutomaticPlaceholderConstraint): TransactionBuilder

Adds an output state, with associated contract code (and constraints), and notary, to the transaction.

Link copied to clipboard
open fun addReferenceState(referencedStateAndRef: ReferencedStateAndRef<*>): <Error class: unknown class>

Adds a reference input StateRef to the transaction.

Link copied to clipboard

Returns an immutable list of attachment hashes.

Link copied to clipboard
fun commands(): List<Command<*>>

Returns an immutable list of Commands.

Link copied to clipboard

Creates a copy of the builder.

Link copied to clipboard

Returns an immutable list of input StateRefs.

Link copied to clipboard

Returns an immutable list of output TransactionStates.

Link copied to clipboard

Returns an immutable list of reference input StateRefs.

Link copied to clipboard
fun setPrivacySalt(privacySalt: PrivacySalt): <Error class: unknown class>
Link copied to clipboard
fun setTimeWindow(timeWindow: TimeWindow): <Error class: unknown class>

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.

fun setTimeWindow(time: Instant, timeTolerance: Duration): <Error class: unknown class>

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.

Link copied to clipboard
Link copied to clipboard
fun toSignedTransaction(keyManagementService: KeyManagementService, publicKey: PublicKey, signatureMetadata: SignatureMetadata, services: ServicesForResolution): SignedTransaction

Sign the built transaction and return it. This is an internal function for use by the service hub, please use ServiceHub.signInitialTransaction instead.

Link copied to clipboard
fun toWireTransaction(services: ServicesForResolution, schemeId: Int, properties: Map<Any, Any>): WireTransaction

Generates a WireTransaction from this builder, resolves any AutomaticPlaceholderConstraint, and selects the attachments to use for this transaction.

Link copied to clipboard
fun verify(services: ServiceHub)
Link copied to clipboard
fun withItems(vararg items: Any): <Error class: unknown class>

A more convenient way to add items to this transaction that calls the add* methods for you based on type