Safe Haskell | None |
---|---|
Language | Haskell2010 |
Crowdfunding contract implemented using the [[Plutus]] interface. This is the fully parallel version that collects all contributions in a single transaction. This is, of course, limited by the maximum number of inputs a transaction can have.
Synopsis
- data Campaign = Campaign {
- campaignDeadline :: POSIXTime
- campaignCollectionDeadline :: POSIXTime
- campaignOwner :: PaymentPubKeyHash
- type CrowdfundingSchema = Endpoint "schedule collection" () .\/ Endpoint "contribute" Contribution
- crowdfunding :: Campaign -> Contract () CrowdfundingSchema ContractError ()
- theCampaign :: POSIXTime -> Campaign
- contribute :: Campaign -> Promise () CrowdfundingSchema ContractError ()
- newtype Contribution = Contribution {
- contribValue :: Value
- scheduleCollection :: Campaign -> Promise () CrowdfundingSchema ContractError ()
- campaignAddress :: Campaign -> ValidatorHash
- contributionScript :: Campaign -> Validator
- mkValidator :: Campaign -> PaymentPubKeyHash -> CampaignAction -> ScriptContext -> Bool
- mkCampaign :: POSIXTime -> POSIXTime -> Wallet -> Campaign
- data CampaignAction
- collectionRange :: Campaign -> ValidityInterval POSIXTime
- refundRange :: Campaign -> ValidityInterval POSIXTime
- startCampaign :: EmulatorTrace (ContractHandle () CrowdfundingSchema ContractError)
- makeContribution :: Wallet -> Value -> EmulatorTrace ()
- successfulCampaign :: EmulatorTrace ()
Campaign parameters
A crowdfunding campaign.
Campaign | |
|
Instances
type CrowdfundingSchema = Endpoint "schedule collection" () .\/ Endpoint "contribute" Contribution Source #
crowdfunding :: Campaign -> Contract () CrowdfundingSchema ContractError () Source #
The crowdfunding contract for the Campaign
.
theCampaign :: POSIXTime -> Campaign Source #
A sample campaign
Functionality for campaign contributors
contribute :: Campaign -> Promise () CrowdfundingSchema ContractError () Source #
The "contribute" branch of the contract for a specific Campaign
. Exposes
an endpoint that allows the user to enter their public key and the
contribution. Then waits until the campaign is over, and collects the
refund if the funding was not collected.
newtype Contribution Source #
Contribution | |
|
Instances
Functionality for campaign owners
scheduleCollection :: Campaign -> Promise () CrowdfundingSchema ContractError () Source #
The campaign owner's branch of the contract for a given Campaign
. It
watches the campaign address for contributions and collects them if
the funding goal was reached in time.
campaignAddress :: Campaign -> ValidatorHash Source #
The address of a [[Campaign]]
Validator script
contributionScript :: Campaign -> Validator Source #
The validator script that determines whether the campaign owner can retrieve the funds or the contributors can claim a refund.
mkValidator :: Campaign -> PaymentPubKeyHash -> CampaignAction -> ScriptContext -> Bool Source #
The validator script is of type CrowdfundingValidator
, and is
additionally parameterized by a Campaign
definition. This argument is
provided by the Plutus client, using applyCode
.
As a result, the Campaign
definition is part of the script address,
and different campaigns have different addresses. The Campaign{..} syntax
means that all fields of the Campaign
value are in scope
(for example campaignDeadline
in l. 70).
mkCampaign :: POSIXTime -> POSIXTime -> Wallet -> Campaign Source #
Construct a Campaign
value from the campaign parameters,
using the wallet's public key.
data CampaignAction Source #
Action that can be taken by the participants in this contract. A value of
CampaignAction
is provided as the redeemer. The validator script then
checks if the conditions for performing this action are met.
Instances
ToData CampaignAction Source # | |
Defined in Plutus.Contracts.Crowdfunding toBuiltinData :: CampaignAction -> BuiltinData | |
FromData CampaignAction Source # | |
Defined in Plutus.Contracts.Crowdfunding fromBuiltinData :: BuiltinData -> Maybe CampaignAction | |
UnsafeFromData CampaignAction Source # | |
Defined in Plutus.Contracts.Crowdfunding unsafeFromBuiltinData :: BuiltinData -> CampaignAction | |
Lift DefaultUni CampaignAction Source # | |
Defined in Plutus.Contracts.Crowdfunding lift :: CampaignAction -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ()) | |
Typeable DefaultUni CampaignAction Source # | |
Defined in Plutus.Contracts.Crowdfunding typeRep :: Proxy CampaignAction -> RTCompile DefaultUni fun (Type TyName DefaultUni ()) |
collectionRange :: Campaign -> ValidityInterval POSIXTime Source #
The 'ValidityInterval POSIXTime' during which the funds can be collected
refundRange :: Campaign -> ValidityInterval POSIXTime Source #
The 'ValidityInterval POSIXTime' during which a refund may be claimed
Traces
startCampaign :: EmulatorTrace (ContractHandle () CrowdfundingSchema ContractError) Source #
Call the "schedule collection" endpoint and instruct the campaign owner's wallet (wallet 1) to start watching the campaign address.
makeContribution :: Wallet -> Value -> EmulatorTrace () Source #
Call the "contribute" endpoint, contributing the amount from the wallet
successfulCampaign :: EmulatorTrace () Source #
Run a successful campaign with contributions from wallets 2, 3 and 4.