corda / net.corda.finance.contracts.asset / OnLedgerAsset / generateSpend

generateSpend

@JvmStatic fun <S : FungibleAsset<T>, T : Any> generateSpend(tx: TransactionBuilder, amount: Amount<T>, to: AbstractParty, acceptableStates: List<StateAndRef<S>>, payChangeTo: AbstractParty, deriveState: (TransactionState<S>, Amount<Issued<T>>, AbstractParty) -> TransactionState<S>, generateMoveCommand: () -> CommandData): Pair<TransactionBuilder, List<PublicKey>>

Generate a transaction that moves an amount of currency to the given pubkey.

Note: an Amount of Currency is only fungible for a given Issuer Party within a FungibleAsset

Parameters

tx - A builder, which may contain inputs, outputs and commands already. The relevant components needed to move the cash will be added on top.

amount - How much currency to send.

to - a key of the recipient.

acceptableStates - a list of acceptable input states to use.

payChangeTo - party to pay any change to; this is normally a confidential identity of the calling party.

deriveState - a function to derive an output state based on an input state, amount for the output and public key to pay to.

Exceptions

InsufficientBalanceException - when a cash spending transaction fails because there is insufficient quantity for a given currency (and optionally set of Issuer Parties).

Return
A Pair of the same transaction builder passed in as tx, and the list of keys that need to sign the resulting transaction for it to be valid.

@JvmStatic fun <S : FungibleAsset<T>, T : Any> generateSpend(tx: TransactionBuilder, payments: List<PartyAndAmount<T>>, acceptableStates: List<StateAndRef<S>>, payChangeTo: AbstractParty, deriveState: (TransactionState<S>, Amount<Issued<T>>, AbstractParty) -> TransactionState<S>, generateMoveCommand: () -> CommandData): Pair<TransactionBuilder, List<PublicKey>>

Adds to the given transaction states that move amounts of a fungible asset to the given parties, using only the provided acceptable input states to find a solution (not all of them may be used in the end). A change output will be generated if the state amounts don't exactly fit.

The fungible assets must all be of the same type and the amounts must be summable i.e. amounts of the same token.

Parameters

tx - A builder, which may contain inputs, outputs and commands already. The relevant components needed to move the cash will be added on top.

acceptableStates - a list of acceptable input states to use.

payChangeTo - party to pay any change to; this is normally a confidential identity of the calling party. We use a new confidential identity here so that the recipient is not identifiable.

deriveState - a function to derive an output state based on an input state, amount for the output and public key to pay to.

T - A type representing a token

S - A fungible asset state type

Exceptions

InsufficientBalanceException - when a cash spending transaction fails because there is insufficient quantity for a given currency (and optionally set of Issuer Parties).

Return
A Pair of the same transaction builder passed in as tx, and the list of keys that need to sign the resulting transaction for it to be valid.