Safe Haskell | None |
---|---|
Language | Haskell2010 |
A general-purpose escrow contract in Plutus
Synopsis
- data Escrow
- data EscrowError
- = RedeemFailed RedeemFailReason
- | RefundFailed
- | EContractError ContractError
- class AsEscrowError r where
- _EscrowError :: Prism' r EscrowError
- _RedeemFailed :: Prism' r RedeemFailReason
- _RefundFailed :: Prism' r ()
- _EContractError :: Prism' r ContractError
- data EscrowParams d = EscrowParams {
- escrowTargets :: [EscrowTarget d]
- data EscrowTarget d
- = PaymentPubKeyTarget PaymentPubKeyHash Value
- | ScriptTarget ValidatorHash d Value
- payToScriptTarget :: ValidatorHash -> Datum -> Value -> EscrowTarget Datum
- payToPaymentPubKeyTarget :: PaymentPubKeyHash -> Value -> EscrowTarget d
- targetTotal :: EscrowParams d -> Value
- escrowContract :: EscrowParams Datum -> Contract () EscrowSchema EscrowError ()
- typedValidator :: EscrowParams Datum -> TypedValidator Escrow
- pay :: forall w s e. AsContractError e => TypedValidator Escrow -> EscrowParams Datum -> Value -> Contract w s e TxId
- payEp :: forall w s e. (HasEndpoint "pay-escrow" Value s, AsEscrowError e) => EscrowParams Datum -> Promise w s e TxId
- redeem :: forall w s e. AsEscrowError e => TypedValidator Escrow -> EscrowParams Datum -> Contract w s e RedeemSuccess
- redeemEp :: forall w s e. (HasEndpoint "redeem-escrow" () s, AsEscrowError e) => EscrowParams Datum -> Promise w s e RedeemSuccess
- refund :: forall w s. TypedValidator Escrow -> EscrowParams Datum -> Contract w s EscrowError RefundSuccess
- refundEp :: forall w s. HasEndpoint "refund-escrow" () s => EscrowParams Datum -> Promise w s EscrowError RefundSuccess
- data RedeemFailReason
- newtype RedeemSuccess = RedeemSuccess TxId
- newtype RefundSuccess = RefundSuccess TxId
- type EscrowSchema = (Endpoint "pay-escrow" Value .\/ Endpoint "redeem-escrow" ()) .\/ Endpoint "refund-escrow" ()
- data Action
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
refund
actions start immediately. This mode is useful when the escrow is
called from within another contract, for example during setup (collection of
the initial deposits).
Instances
ValidatorTypes Escrow Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict | |
type DatumType Escrow Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict type DatumType Escrow = PaymentPubKeyHash | |
type RedeemerType Escrow Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict |
data EscrowError Source #
RedeemFailed RedeemFailReason | |
RefundFailed | |
EContractError ContractError |
Instances
class AsEscrowError r where Source #
_EscrowError :: Prism' r EscrowError Source #
_RedeemFailed :: Prism' r RedeemFailReason Source #
_RefundFailed :: Prism' r () Source #
_EContractError :: Prism' r ContractError Source #
Instances
AsEscrowError EscrowError Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict _EscrowError :: Prism' EscrowError EscrowError Source # _RedeemFailed :: Prism' EscrowError RedeemFailReason Source # _RefundFailed :: Prism' EscrowError () Source # _EContractError :: Prism' EscrowError ContractError Source # |
data EscrowParams d Source #
Definition of an escrow contract, consisting of a deadline and a list of targets
EscrowParams | |
|
Instances
Functor EscrowParams Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict fmap :: (a -> b) -> EscrowParams a -> EscrowParams b Source # (<$) :: a -> EscrowParams b -> EscrowParams a Source # | |
(Typeable DefaultUni d, Lift DefaultUni [EscrowTarget d]) => Lift DefaultUni (EscrowParams d) Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict lift :: EscrowParams d -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ()) | |
Typeable DefaultUni EscrowParams Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict typeRep :: Proxy EscrowParams -> RTCompile DefaultUni fun (Type TyName DefaultUni ()) |
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)
PaymentPubKeyTarget PaymentPubKeyHash Value | |
ScriptTarget ValidatorHash d Value |
Instances
Functor EscrowTarget Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict fmap :: (a -> b) -> EscrowTarget a -> EscrowTarget b Source # (<$) :: a -> EscrowTarget b -> EscrowTarget a Source # | |
(Typeable DefaultUni d, Lift DefaultUni d) => Lift DefaultUni (EscrowTarget d) Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict lift :: EscrowTarget d -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ()) | |
Typeable DefaultUni EscrowTarget Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict typeRep :: Proxy EscrowTarget -> RTCompile DefaultUni fun (Type TyName DefaultUni ()) |
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
escrowContract :: EscrowParams Datum -> Contract () EscrowSchema EscrowError () Source #
typedValidator :: EscrowParams Datum -> TypedValidator Escrow Source #
Actions
:: 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
newtype RedeemSuccess Source #
RedeemSuccess TxId |
Instances
Eq RedeemSuccess Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict (==) :: RedeemSuccess -> RedeemSuccess -> Bool Source # (/=) :: RedeemSuccess -> RedeemSuccess -> Bool Source # | |
Show RedeemSuccess Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict |
newtype RefundSuccess Source #
RefundSuccess TxId |
Instances
Eq RefundSuccess Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict (==) :: RefundSuccess -> RefundSuccess -> Bool Source # (/=) :: RefundSuccess -> RefundSuccess -> Bool Source # | |
Show RefundSuccess Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict | |
Generic RefundSuccess Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict from :: RefundSuccess -> Rep RefundSuccess x Source # to :: Rep RefundSuccess x -> RefundSuccess Source # | |
FromJSON RefundSuccess Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict parseJSON :: Value -> Parser RefundSuccess parseJSONList :: Value -> Parser [RefundSuccess] | |
ToJSON RefundSuccess Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict toJSON :: RefundSuccess -> Value toEncoding :: RefundSuccess -> Encoding toJSONList :: [RefundSuccess] -> Value toEncodingList :: [RefundSuccess] -> Encoding | |
type Rep RefundSuccess Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict |
type EscrowSchema = (Endpoint "pay-escrow" Value .\/ Endpoint "redeem-escrow" ()) .\/ Endpoint "refund-escrow" () Source #
Exposed for test endpoints
Instances
ToData Action Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict toBuiltinData :: Action -> BuiltinData | |
FromData Action Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict fromBuiltinData :: BuiltinData -> Maybe Action | |
UnsafeFromData Action Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict unsafeFromBuiltinData :: BuiltinData -> Action | |
Lift DefaultUni Action Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict | |
Typeable DefaultUni Action Source # | |
Defined in Plutus.Contracts.Tutorial.EscrowStrict |