corda / net.corda.core.transactions / TransactionBuilder

TransactionBuilder

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

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

<init>

TransactionBuilder(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())
TransactionBuilder(notary: Party)TransactionBuilder(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)

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.

Properties

attachments

val attachments: MutableList<AttachmentId>

commands

val commands: MutableList<Command<*>>

inputs

val inputs: MutableList<StateRef>

lockId

var lockId: UUID

notary

var notary: Party?

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.

outputs

val outputs: MutableList<TransactionState<ContractState>>

privacySalt

var privacySalt: PrivacySalt

references

val references: MutableList<StateRef>

serviceHub

val serviceHub: ServiceHub?

window

var window: TimeWindow?

Functions

addAttachment

fun addAttachment(attachmentId: AttachmentId): <ERROR CLASS>

Adds an attachment with the specified hash to the TransactionBuilder.

addCommand

fun addCommand(arg: Command<*>): <ERROR CLASS>

Adds a Command to the transaction.

fun addCommand(data: CommandData, vararg keys: PublicKey): <ERROR 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>

addInputState

open fun addInputState(stateAndRef: StateAndRef<*>): <ERROR CLASS>

Adds an input StateRef to the transaction.

addOutputState

fun addOutputState(state: TransactionState<*>): <ERROR CLASS>

Adds an output state to the transaction.

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.

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, constraint: AttachmentConstraint): TransactionBuilder

Adds an output state with the specified constraint.

addReferenceState

open fun addReferenceState(referencedStateAndRef: ReferencedStateAndRef<*>): <ERROR CLASS>

Adds a reference input StateRef to the transaction.

attachments

fun attachments(): List<AttachmentId>

Returns an immutable list of attachment hashes.

commands

fun commands(): List<Command<*>>

Returns an immutable list of Commands.

copy

fun copy(): TransactionBuilder

Creates a copy of the builder.

inputStates

fun inputStates(): List<StateRef>

Returns an immutable list of input StateRefs.

outputStates

fun outputStates(): List<TransactionState<*>>

Returns an immutable list of output TransactionStates.

referenceStates

fun referenceStates(): List<StateRef>

Returns an immutable list of reference input StateRefs.

setPrivacySalt

fun setPrivacySalt(privacySalt: PrivacySalt): <ERROR CLASS>

setTimeWindow

fun setTimeWindow(timeWindow: TimeWindow): <ERROR 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>

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.

toLedgerTransaction

fun toLedgerTransaction(services: ServiceHub): LedgerTransaction

toSignedTransaction

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.

toWireTransaction

fun toWireTransaction(services: ServicesForResolution): WireTransaction
fun toWireTransaction(services: ServicesForResolution, schemeId: Int): WireTransaction
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.

verify

fun verify(services: ServiceHub): Unit

withItems

fun withItems(vararg items: Any): <ERROR CLASS>

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

Extension Functions

contextLogger

fun Any.contextLogger(): <ERROR CLASS>

When called from a companion object, returns the logger for the enclosing class.