Created
August 11, 2021 02:35
-
-
Save davidawad/05143aa022c362c0da388e0fcec1eac8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
progressTracker.setCurrentStep(TX_BUILDING); | |
// If our transaction has input states or a time-window, we must instantiate it with a | |
// notary. | |
TransactionBuilder txBuilder = new TransactionBuilder(specificNotary); | |
// Otherwise, we can choose to instantiate it without one: | |
TransactionBuilder txBuilderNoNotary = new TransactionBuilder(); | |
// We add items to the transaction builder using ``TransactionBuilder.withItems``: | |
txBuilder.withItems( | |
// Inputs, as ``StateAndRef``s that reference to the outputs of previous transactions | |
ourStateAndRef, | |
// Outputs, as ``StateAndContract``s | |
ourOutput, | |
// Commands, as ``Command``s | |
ourCommand, | |
// Attachments, as ``SecureHash``es | |
ourAttachment, | |
// A time-window, as ``TimeWindow`` | |
ourTimeWindow | |
); | |
// We can also add items using methods for the individual components. | |
// The individual methods for adding input states and attachments: | |
txBuilder.addInputState(ourStateAndRef); | |
txBuilder.addAttachment(ourAttachment); | |
// An output state can be added as a ``ContractState``, contract class name and notary. | |
txBuilder.addOutputState(ourOutputState, DummyContract.PROGRAM_ID, specificNotary); | |
// We can also leave the notary field blank, in which case the transaction's default | |
// notary is used. | |
txBuilder.addOutputState(ourOutputState, DummyContract.PROGRAM_ID); | |
// Or we can add the output state as a ``TransactionState``, which already specifies | |
// the output's contract and notary. | |
TransactionState txState = new TransactionState<>(ourOutputState, DummyContract.PROGRAM_ID, specificNotary); | |
// Commands can be added as ``Command``s. | |
txBuilder.addCommand(ourCommand); | |
// Or as ``CommandData`` and a ``vararg PublicKey``. | |
txBuilder.addCommand(commandData, ourPubKey, counterpartyPubKey); | |
// We can set a time-window directly. | |
txBuilder.setTimeWindow(ourTimeWindow); | |
// Or as a start time plus a duration (e.g. 45 seconds). | |
txBuilder.setTimeWindow(getServiceHub().getClock().instant(), Duration.ofSeconds(45)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment