contracts / CrowdFund

# CrowdFund

`class CrowdFund : Contract`

This is a basic crowd funding contract. It allows a party to create a funding opportunity, then for others to pledge during the funding period , and then for the party to either accept the funding (if the target has been reached) return the funds to the pledge-makers (if the target has not been reached).

Discussion

This method of modelling a crowdfund is similar to how itd be done in Ethereum. The state is essentially a database in which transactions evolve it over time. The state transition model we are using here though means its possible to do it in a different approach, with some additional (not yet implemented) extensions to the model. In the UTXO model you can do something more like the Lighthouse application (https://www.vinumeris.com/lighthouse) in which the campaign data and peoples pledges are transmitted out of band, with a pledge being a partially signed transaction which is valid only when merged with other transactions. The pledges can then be combined by the project owner at the point at which sufficient amounts of money have been gathered, and this creates a valid transaction that claims the money.

TODO: Prototype this second variant of crowdfunding once the core model has been sufficiently extended. TODO: Experiment with the use of the javax.validation API to simplify the validation logic by annotating state members.

See JIRA bug PD-21 for further discussion and followup.

Author
James Carlyle

### Types

Campaign | `data class Campaign`
Commands | `interface Commands : CommandData`
Pledge | `data class Pledge`
State | `data class State : ContractState`

### Constructors

<init> | `CrowdFund()` This is a basic crowd funding contract. It allows a party to create a funding opportunity, then for others to pledge during the funding period , and then for the party to either accept the funding (if the target has been reached) return the funds to the pledge-makers (if the target has not been reached).

### Properties

legalContractReference | `val legalContractReference: SecureHash` Unparsed reference to the natural language contract that this code is supposed to express (usually a hash of the contracts contents).

### Functions

generateClose | `fun generateClose(tx: TransactionBuilder, campaign: StateAndRef<State>, wallet: List<StateAndRef<State>>): Unit`
generatePledge | `fun generatePledge(tx: TransactionBuilder, campaign: StateAndRef<State>, subscriber: PublicKey): Unit` Updates the given partial transaction with an input/output/command to fund the opportunity.
generateRegister | `fun generateRegister(owner: PartyAndReference, fundingTarget: Amount, fundingName: String, closingTime: Instant): TransactionBuilder` Returns a transaction that registers a crowd-funding campaing, owned by the issuing institutions key. Does not update an existing transaction because its not possible to register multiple campaigns in a single transaction
verify | `fun verify(tx: TransactionForVerification): 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.