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

Plutus.Contracts.Escrow

Description

A general-purpose escrow contract in Plutus

Synopsis

Documentation

The escrow contract implements the exchange of value between multiple parties. It is defined by a list of targets (public keys and script addresses, each associated with a value). It works similar to the crowdfunding contract in that the contributions can be made independently, and the funds can be unlocked only by a transaction that pays the correct amount to each target. A refund is possible if the outputs locked by the contract have not been spent by the deadline. (Compared to the crowdfunding contract, the refund policy is simpler because here because there is no "collection period" during which the outputs may be spent after the deadline has passed. This is because we're assuming that the participants in the escrow contract will make their deposits as quickly as possible after agreeing on a deal)

The contract supports two modes of operation, manual and automatic. In manual mode, all actions are driven by endpoints that exposed via payEp redeemEp and refundEp. In automatic mode, the pay, redeem and refundactions start immediately. This mode is useful when the escrow is called from within another contract, for example during setup (collection of the initial deposits).

data Escrow Source #

Instances

Instances details
ValidatorTypes Escrow Source # 
Instance details

Defined in Plutus.Contracts.Escrow

Associated Types

type RedeemerType Escrow Source #

type DatumType Escrow Source #

type DatumType Escrow Source # 
Instance details

Defined in Plutus.Contracts.Escrow

type RedeemerType Escrow Source # 
Instance details

Defined in Plutus.Contracts.Escrow

data EscrowError Source #

Instances

Instances details
Show EscrowError Source # 
Instance details

Defined in Plutus.Contracts.Escrow

Generic EscrowError Source # 
Instance details

Defined in Plutus.Contracts.Escrow

Associated Types

type Rep EscrowError :: Type -> Type Source #

ToJSON EscrowError Source # 
Instance details

Defined in Plutus.Contracts.Escrow

FromJSON EscrowError Source # 
Instance details

Defined in Plutus.Contracts.Escrow

AsContractError EscrowError Source # 
Instance details

Defined in Plutus.Contracts.Escrow

AsEscrowError EscrowError Source # 
Instance details

Defined in Plutus.Contracts.Escrow

type Rep EscrowError Source # 
Instance details

Defined in Plutus.Contracts.Escrow

type Rep EscrowError = D1 ('MetaData "EscrowError" "Plutus.Contracts.Escrow" "plutus-use-cases-0.1.0.0-sCb7ThsvWbFT6VPXrOzPF" 'False) (C1 ('MetaCons "RedeemFailed" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 RedeemFailReason)) :+: (C1 ('MetaCons "RefundFailed" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "EContractError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ContractError))))

data EscrowParams d Source #

Definition of an escrow contract, consisting of a deadline and a list of targets

Constructors

EscrowParams 

Fields

  • escrowDeadline :: POSIXTime

    Latest point at which the outputs may be spent.

  • escrowTargets :: [EscrowTarget d]

    Where the money should go. For each target, the contract checks that the output mkTxOutput of the target is present in the spending transaction.

data EscrowTarget d Source #

Defines where the money should go. Usually we have `d = Datum` (when defining EscrowTarget values in off-chain code). Sometimes we have `d = DatumHash` (when checking the hashes in on-chain code)

payToScriptTarget :: ValidatorHash -> Datum -> Value -> EscrowTarget Datum Source #

An EscrowTarget that pays the value to a script address, with the given data script.

payToPaymentPubKeyTarget :: PaymentPubKeyHash -> Value -> EscrowTarget d Source #

An EscrowTarget that pays the value to a public key address.

targetTotal :: EscrowParams d -> Value Source #

The total Value that must be paid into the escrow contract before it can be unlocked

payRedeemRefund :: forall w s. EscrowParams Datum -> Value -> Contract w s EscrowError (Either RefundSuccess RedeemSuccess) Source #

Pay some money into the escrow contract. Then release all funds to their specified targets if enough funds were deposited before the deadline, or reclaim the contribution if the goal has not been met.

Actions

pay Source #

Arguments

:: forall w s e. AsContractError e 
=> TypedValidator Escrow

The instance

-> EscrowParams Datum

The escrow contract

-> Value

How much money to pay in

-> Contract w s e TxId 

Pay some money into the escrow contract.

payEp :: forall w s e. (HasEndpoint "pay-escrow" Value s, AsEscrowError e) => EscrowParams Datum -> Promise w s e TxId Source #

pay with an endpoint that gets the owner's public key and the contribution.

redeem :: forall w s e. AsEscrowError e => TypedValidator Escrow -> EscrowParams Datum -> Contract w s e RedeemSuccess Source #

Redeem all outputs at the contract address using a transaction that has all the outputs defined in the contract's list of targets.

redeemEp :: forall w s e. (HasEndpoint "redeem-escrow" () s, AsEscrowError e) => EscrowParams Datum -> Promise w s e RedeemSuccess Source #

redeem with an endpoint.

refund :: forall w s. TypedValidator Escrow -> EscrowParams Datum -> Contract w s EscrowError RefundSuccess Source #

Claim a refund of the contribution.

refundEp :: forall w s. HasEndpoint "refund-escrow" () s => EscrowParams Datum -> Promise w s EscrowError RefundSuccess Source #

refund with an endpoint.

data RedeemFailReason Source #

Instances

Instances details
Eq RedeemFailReason Source # 
Instance details

Defined in Plutus.Contracts.Escrow

Show RedeemFailReason Source # 
Instance details

Defined in Plutus.Contracts.Escrow

Generic RedeemFailReason Source # 
Instance details

Defined in Plutus.Contracts.Escrow

Associated Types

type Rep RedeemFailReason :: Type -> Type Source #

ToJSON RedeemFailReason Source # 
Instance details

Defined in Plutus.Contracts.Escrow

FromJSON RedeemFailReason Source # 
Instance details

Defined in Plutus.Contracts.Escrow

type Rep RedeemFailReason Source # 
Instance details

Defined in Plutus.Contracts.Escrow

type Rep RedeemFailReason = D1 ('MetaData "RedeemFailReason" "Plutus.Contracts.Escrow" "plutus-use-cases-0.1.0.0-sCb7ThsvWbFT6VPXrOzPF" 'False) (C1 ('MetaCons "DeadlinePassed" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "NotEnoughFundsAtAddress" 'PrefixI 'False) (U1 :: Type -> Type))

type EscrowSchema = (Endpoint "pay-escrow" Value .\/ Endpoint "redeem-escrow" ()) .\/ Endpoint "refund-escrow" () Source #

Exposed for test endpoints