corda / net.corda.finance.contracts.asset / Cash

Cash

class Cash : OnLedgerAsset<Currency, Commands, State>

A cash transaction may split and merge money represented by a set of (issuer, depositRef) pairs, across multiple input and output states. Imagine a Bitcoin transaction but in which all UTXOs had a colour (a blend of issuer+depositRef) and you couldn't merge outputs of two colours together, but you COULD put them in the same transaction.

The goal of this design is to ensure that money can be withdrawn from the ledger easily: if you receive some money via this contract, you always know where to go in order to extract it from the R3 ledger, no matter how many hands it has passed through in the intervening time.

At the same time, other contracts that just want money and don't care much who is currently holding it in their vaults can ignore the issuer/depositRefs and just examine the amount fields.

Types

Commands

interface Commands : CommandData

State

data class State : FungibleAsset<Currency>, QueryableState

A state representing a cash claim against some party.

Constructors

<init>

Cash()

A cash transaction may split and merge money represented by a set of (issuer, depositRef) pairs, across multiple input and output states. Imagine a Bitcoin transaction but in which all UTXOs had a colour (a blend of issuer+depositRef) and you couldn't merge outputs of two colours together, but you COULD put them in the same transaction.

Functions

deriveState

fun deriveState(txState: TransactionState<State>, amount: Amount<Issued<Currency>>, owner: AbstractParty): TransactionState<State>

Derive a new transaction state based on the given example, with amount and owner modified. This allows concrete implementations to have fields in their state which we don't know about here, and we simply leave them untouched when sending out "change" from spending/exiting.

extractCommands

fun extractCommands(commands: Collection<CommandWithParties<CommandData>>): List<CommandWithParties<Commands>>

generateExitCommand

fun generateExitCommand(amount: Amount<Issued<Currency>>): Exit

generateIssue

fun generateIssue(tx: TransactionBuilder, tokenDef: Issued<Currency>, pennies: Long, owner: AbstractParty, notary: Party): Set<PublicKey>

Puts together an issuance transaction from the given template, that starts out being owned by the given pubkey.

fun generateIssue(tx: TransactionBuilder, amount: Amount<Issued<Currency>>, owner: AbstractParty, notary: Party): Set<PublicKey>

Puts together an issuance transaction for the specified amount that starts out being owned by the given pubkey.

generateMoveCommand

fun generateMoveCommand(): Move

verify

fun verify(tx: LedgerTransaction): Unit

Takes an object that represents a state transition, and ensures the inputs/outputs/commands make sense. Must throw an exception if there's a problem that should prevent state transition. Takes a single object rather than an argument so that additional data can be added without breaking binary compatibility with existing contract code.

Inherited Functions

generateExit

fun generateExit(tx: TransactionBuilder, amountIssued: Amount<Issued<T>>, assetStates: List<StateAndRef<S>>): Set<PublicKey>
fun generateExit(tx: TransactionBuilder, amountIssued: Amount<Issued<T>>, assetStates: List<StateAndRef<S>>, payChangeTo: AbstractParty): Set<PublicKey>

Generate an transaction exiting assets from the ledger.

Companion Object Properties

PROGRAM_ID

const val PROGRAM_ID: ContractClassName

Companion Object Functions

generateSpend

fun generateSpend(services: ServiceHub, tx: TransactionBuilder, amount: Amount<Currency>, to: AbstractParty, onlyFromParties: Set<AbstractParty> = emptySet()): Pair<TransactionBuilder, List<PublicKey>>

Generate a transaction that moves an amount of currency to the given party, and sends any change back to sole identity of the calling node. Fails for nodes with multiple identities.

fun generateSpend(services: ServiceHub, tx: TransactionBuilder, amount: Amount<Currency>, ourIdentity: PartyAndCertificate, to: AbstractParty, onlyFromParties: Set<AbstractParty> = emptySet()): Pair<TransactionBuilder, List<PublicKey>>

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

fun generateSpend(services: ServiceHub, tx: TransactionBuilder, payments: List<PartyAndAmount<Currency>>, onlyFromParties: Set<AbstractParty> = emptySet()): Pair<TransactionBuilder, List<PublicKey>>

Generate a transaction that moves money of the given amounts to the recipients specified, and sends any change back to sole identity of the calling node. Fails for nodes with multiple identities.

fun generateSpend(services: ServiceHub, tx: TransactionBuilder, payments: List<PartyAndAmount<Currency>>, ourIdentity: PartyAndCertificate, onlyFromParties: Set<AbstractParty> = emptySet()): Pair<TransactionBuilder, List<PublicKey>>

Generate a transaction that moves money of the given amounts to the recipients specified.

Extension Functions

contextLogger

fun Any.contextLogger(): Logger

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