Skip to content

Instantly share code, notes, and snippets.

@davidawad
Created August 11, 2021 02:23
Show Gist options
  • Save davidawad/6369d16f41e63daa2c0009d99f728acb to your computer and use it in GitHub Desktop.
Save davidawad/6369d16f41e63daa2c0009d99f728acb to your computer and use it in GitHub Desktop.
progressTracker.setCurrentStep(EXTRACTING_VAULT_STATES);
// Let's assume there are already some DummyState in our
// node's vault, stored there as a result of running past flows,
// and we want to consume them in a transaction. There are many
// ways to extract these states from our vault.
// For example, we would extract any unconsumed DummyState
// from our vault as follows:
VaultQueryCriteria criteria = new VaultQueryCriteria(Vault.StateStatus.UNCONSUMED);
Page<DummyState> results = getServiceHub().getVaultService().queryBy(DummyState.class, criteria);
List<StateAndRef<DummyState>> dummyStates = results.getStates();
// When building a transaction, input states are passed in as
// ``StateRef`` instances, which pair the hash of the transaction
// that generated the state with the state's index in the outputs
// of that transaction. In practice, we'd pass the transaction hash
// or the ``StateRef`` as a parameter to the flow, or extract the
// ``StateRef`` from our vault.
StateRef ourStateRef = new StateRef(SecureHash.sha256("DummyTransactionHash"), 0);
// A ``StateAndRef`` pairs a ``StateRef`` with the state it points to.
StateAndRef ourStateAndRef = getServiceHub().toStateAndRef(ourStateRef);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment