com.r3corda.contracts.asset / CommodityContract

# CommodityContract

`class CommodityContract : OnLedgerAsset<Commodity, Commands, State>`

A commodity contract represents an amount of some commodity, tracked on a distributed ledger. The design of this contract is intentionally similar to the Cash contract, and the same commands (issue, move, exit) apply, the differences are in representation of the underlying commodity. Issuer in this context means the party who has the commodity, or is otherwise responsible for delivering the commodity on demand, and the deposit reference is use for internal accounting by the issuer (it might be, for example, a warehouse and/or location within a warehouse).

This is an early stage example contract used to illustrate non-cash fungible assets, and is likely to change significantly in future.

### Types

Clauses | `interface Clauses` The clauses for this contract are essentially:
Commands | `interface Commands : Commands`
State | `data class State : FungibleAsset<Commodity>` A state representing a commodity claim against some party

### Constructors

<init> | `CommodityContract()` A commodity contract represents an amount of some commodity, tracked on a distributed ledger. The design of this contract is intentionally similar to the Cash contract, and the same commands (issue, move, exit) apply, the differences are in representation of the underlying commodity. Issuer in this context means the party who has the commodity, or is otherwise responsible for delivering the commodity on demand, and the deposit reference is use for internal accounting by the issuer (it might be, for example, a warehouse and/or location within a warehouse).

### Properties

conserveClause | `val conserveClause: AbstractConserveAmount<State, Commands, Commodity>`
legalContractReference | `val legalContractReference: SecureHash` TODO:

### Functions

deriveState | `fun deriveState(txState: TransactionState<State>, amount: Amount<Issued<Commodity>>, owner: PublicKey): 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 dont know about here, and we simply leave them untouched when sending out "change" from spending/exiting.
extractCommands | `fun extractCommands(commands: Collection<AuthenticatedObject<CommandData>>): List<AuthenticatedObject<Commands>>`
generateExitCommand | `fun generateExitCommand(amount: Amount<Issued<Commodity>>): Exit`
generateIssue | `fun generateIssue(tx: TransactionBuilder, tokenDef: Issued<Commodity>, pennies: Long, owner: PublicKey, notary: Party): Unit` 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<Commodity>>, owner: PublicKey, notary: Party): Unit` Puts together an issuance transaction for the specified amount that starts out being owned by the given pubkey.
generateIssueCommand | `fun generateIssueCommand(): Issue`
generateMoveCommand | `fun generateMoveCommand(): Move`
verify | `fun verify(tx: TransactionForContract): Unit` Takes an object that represents a state transition, and ensures the inputs/outputs/commands make sense. Must throw an exception if theres 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.