plutus-use-cases-1.2.0.0: Collection of smart contracts to develop the plutus/wallet interface
Safe HaskellNone
LanguageHaskell2010

Plutus.Contracts.Crowdfunding

Description

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

Campaign parameters

data Campaign Source #

A crowdfunding campaign.

Constructors

Campaign 

Fields

  • campaignDeadline :: POSIXTime

    The date by which the campaign funds can be contributed.

  • campaignCollectionDeadline :: POSIXTime

    The date by which the campaign owner has to collect the funds

  • campaignOwner :: PaymentPubKeyHash

    Public key of the campaign owner. This key is entitled to retrieve the funds if the campaign is successful.

Instances

Instances details
Show Campaign Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Generic Campaign Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Associated Types

type Rep Campaign :: Type -> Type Source #

FromJSON Campaign Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Methods

parseJSON :: Value -> Parser Campaign

parseJSONList :: Value -> Parser [Campaign]

ToJSON Campaign Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Methods

toJSON :: Campaign -> Value

toEncoding :: Campaign -> Encoding

toJSONList :: [Campaign] -> Value

toEncodingList :: [Campaign] -> Encoding

Lift DefaultUni Campaign Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Methods

lift :: Campaign -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni Campaign Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Methods

typeRep :: Proxy Campaign -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

type Rep Campaign Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

type Rep Campaign = D1 ('MetaData "Campaign" "Plutus.Contracts.Crowdfunding" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" 'False) (C1 ('MetaCons "Campaign" 'PrefixI 'True) (S1 ('MetaSel ('Just "campaignDeadline") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 POSIXTime) :*: (S1 ('MetaSel ('Just "campaignCollectionDeadline") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 POSIXTime) :*: S1 ('MetaSel ('Just "campaignOwner") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PaymentPubKeyHash))))

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 #

Constructors

Contribution 

Fields

Instances

Instances details
Eq Contribution Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Show Contribution Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Generic Contribution Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Associated Types

type Rep Contribution :: Type -> Type Source #

FromJSON Contribution Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Methods

parseJSON :: Value -> Parser Contribution

parseJSONList :: Value -> Parser [Contribution]

ToJSON Contribution Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Methods

toJSON :: Contribution -> Value

toEncoding :: Contribution -> Encoding

toJSONList :: [Contribution] -> Value

toEncodingList :: [Contribution] -> Encoding

type Rep Contribution Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

type Rep Contribution = D1 ('MetaData "Contribution" "Plutus.Contracts.Crowdfunding" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" 'True) (C1 ('MetaCons "Contribution" 'PrefixI 'True) (S1 ('MetaSel ('Just "contribValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value)))

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.

Constructors

Collect 
Refund 

Instances

Instances details
ToData CampaignAction Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Methods

toBuiltinData :: CampaignAction -> BuiltinData

FromData CampaignAction Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Methods

fromBuiltinData :: BuiltinData -> Maybe CampaignAction

UnsafeFromData CampaignAction Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Methods

unsafeFromBuiltinData :: BuiltinData -> CampaignAction

Lift DefaultUni CampaignAction Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Methods

lift :: CampaignAction -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni CampaignAction Source # 
Instance details

Defined in Plutus.Contracts.Crowdfunding

Methods

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.