Safe Haskell | None |
---|---|
Language | Haskell2010 |
Plutus implementation of an account that can be unlocked with a token.
Whoever owns the token can spend the outputs locked by the contract.
(A suitable token can be created with the Currency
contract, or with newAccount
in this module)
Synopsis
- newtype Account = Account {
- accountOwner :: AssetClass
- pay :: AsTokenAccountError e => Account -> Value -> Contract w s e CardanoTx
- redeem :: AsTokenAccountError e => CardanoAddress -> Account -> Contract w s e CardanoTx
- newAccount :: forall w s e. AsTokenAccountError e => TokenName -> CardanoAddress -> Contract w s e Account
- balance :: AsTokenAccountError e => Account -> Contract w s e Value
- address :: Account -> CardanoAddress
- accountToken :: Account -> Value
- payTx :: Value -> TxConstraints (RedeemerType TokenAccount) (DatumType TokenAccount)
- redeemTx :: forall w s e. AsTokenAccountError e => Account -> CardanoAddress -> Contract w s e (TxConstraints () (), ScriptLookups TokenAccount)
- type TokenAccountSchema = (Endpoint "redeem" (Account, CardanoAddress) .\/ Endpoint "pay" (Account, Value)) .\/ Endpoint "new-account" (TokenName, CardanoAddress)
- type HasTokenAccountSchema s = (HasEndpoint "redeem" (Account, CardanoAddress) s, HasEndpoint "pay" (Account, Value) s, HasEndpoint "new-account" (TokenName, CardanoAddress) s)
- tokenAccountContract :: forall w s e. (HasTokenAccountSchema s, AsTokenAccountError e) => Contract w s e ()
- data TokenAccount
- data TokenAccountError
- = TAContractError ContractError
- | TACurrencyError CurrencyError
- class AsTokenAccountError r where
- _TokenAccountError :: Prism' r TokenAccountError
- _TAContractError :: Prism' r ContractError
- _TACurrencyError :: Prism' r CurrencyError
- validatorHash :: Account -> ValidatorHash
- typedValidator :: Account -> TypedValidator TokenAccount
Documentation
Account | |
|
Instances
Contract functionality
pay :: AsTokenAccountError e => Account -> Value -> Contract w s e CardanoTx Source #
Pay some money to the given token account
:: AsTokenAccountError e | |
=> CardanoAddress | Where the token should go after the transaction |
-> Account | The token account |
-> Contract w s e CardanoTx |
Empty the account by spending all outputs belonging to the Account
.
:: forall w s e. AsTokenAccountError e | |
=> TokenName | Name of the token |
-> CardanoAddress | Address of the token's initial owner |
-> Contract w s e Account |
Create a new token and return its Account
information.
balance :: AsTokenAccountError e => Account -> Contract w s e Value Source #
balance account
returns the value of all unspent outputs that can be
unlocked with accountToken account
accountToken :: Account -> Value Source #
payTx :: Value -> TxConstraints (RedeemerType TokenAccount) (DatumType TokenAccount) Source #
A transaction that pays the given value to the account
redeemTx :: forall w s e. AsTokenAccountError e => Account -> CardanoAddress -> Contract w s e (TxConstraints () (), ScriptLookups TokenAccount) Source #
Create a transaction that spends all outputs belonging to the Account
.
Endpoints
type TokenAccountSchema = (Endpoint "redeem" (Account, CardanoAddress) .\/ Endpoint "pay" (Account, Value)) .\/ Endpoint "new-account" (TokenName, CardanoAddress) Source #
type HasTokenAccountSchema s = (HasEndpoint "redeem" (Account, CardanoAddress) s, HasEndpoint "pay" (Account, Value) s, HasEndpoint "new-account" (TokenName, CardanoAddress) s) Source #
tokenAccountContract :: forall w s e. (HasTokenAccountSchema s, AsTokenAccountError e) => Contract w s e () Source #
redeem
, pay
and newAccount
with endpoints.
Etc.
data TokenAccount Source #
Instances
ValidatorTypes TokenAccount Source # | |
Defined in Plutus.Contracts.TokenAccount type RedeemerType TokenAccount type DatumType TokenAccount | |
type DatumType TokenAccount Source # | |
Defined in Plutus.Contracts.TokenAccount type DatumType TokenAccount = () | |
type RedeemerType TokenAccount Source # | |
Defined in Plutus.Contracts.TokenAccount type RedeemerType TokenAccount = () |
data TokenAccountError Source #
TAContractError ContractError | |
TACurrencyError CurrencyError |
Instances
class AsTokenAccountError r where Source #
_TokenAccountError :: Prism' r TokenAccountError Source #
_TAContractError :: Prism' r ContractError Source #
_TACurrencyError :: Prism' r CurrencyError Source #
Instances
AsTokenAccountError TokenAccountError Source # | |
Defined in Plutus.Contracts.TokenAccount _TokenAccountError :: Prism' TokenAccountError TokenAccountError Source # _TAContractError :: Prism' TokenAccountError ContractError Source # _TACurrencyError :: Prism' TokenAccountError CurrencyError Source # |
validatorHash :: Account -> ValidatorHash Source #
typedValidator :: Account -> TypedValidator TokenAccount Source #