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)TransactionBuilder(notary: Party? = null, lockId: UUID = (Strand.currentStrand() as? FlowStateMachine<*>)?.id?.uuid ?: UUID.randomUUID(), inputs: MutableList<StateRef> = arrayListOf(), attachments: MutableList<SecureHash> = arrayListOf(), outputs: MutableList<TransactionState<ContractState>> = arrayListOf(), commands: MutableList<Command<*>> = arrayListOf(), window: TimeWindow? = null, privacySalt: PrivacySalt = PrivacySalt())

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<SecureHash>

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

window

var window: TimeWindow?

Functions

addAttachment

fun addAttachment(attachmentId: SecureHash): TransactionBuilder

addCommand

fun addCommand(arg: Command<*>): TransactionBuilder
fun addCommand(data: CommandData, vararg keys: PublicKey): TransactionBuilder
fun addCommand(data: CommandData, keys: List<PublicKey>): TransactionBuilder

addInputState

open fun addInputState(stateAndRef: StateAndRef<*>): TransactionBuilder

addOutputState

fun addOutputState(state: TransactionState<*>): TransactionBuilder
fun addOutputState(state: ContractState, contract: ContractClassName, notary: Party, encumbrance: Int? = null, constraint: AttachmentConstraint = AutomaticHashConstraint): TransactionBuilderfun addOutputState(state: ContractState, contract: ContractClassName, constraint: AttachmentConstraint = AutomaticHashConstraint): TransactionBuilder

A default notary must be specified during builder construction to use this method

attachments

fun attachments(): List<SecureHash>

commands

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

copy

fun copy(): TransactionBuilder

Creates a copy of the builder.

inputStates

fun inputStates(): List<StateRef>

outputStates

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

setPrivacySalt

fun setPrivacySalt(privacySalt: PrivacySalt): TransactionBuilder

setTimeWindow

fun setTimeWindow(timeWindow: TimeWindow): TransactionBuilder

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): TransactionBuilder

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

Generates a WireTransaction from this builder and resolves any AutomaticHashConstraint on contracts to HashAttachmentConstraint.

verify

fun verify(services: ServiceHub): Unit

withItems

fun withItems(vararg items: Any): TransactionBuilder

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(): Logger

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