Skip to content

Instantly share code, notes, and snippets.

@davidawad
Created August 11, 2021 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidawad/05143aa022c362c0da388e0fcec1eac8 to your computer and use it in GitHub Desktop.
Save davidawad/05143aa022c362c0da388e0fcec1eac8 to your computer and use it in GitHub Desktop.
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