| title | M10 - A Vesting Contract I |
|---|---|
| author | Walker Leite |
In this module we'll see how to handle time in the blockchain and build a Vesting Contract.
To run this presentation type (you will need nix):
../../slide README.md- LovelaceAcademy Discord
- StackExchange (:bulb: use the tag lovelace-academy)
- Plutonomicon Discord
- Bulding smart contracts (module 6);
- Cardano-Transaction-Lib (module 8);
data ScriptContext = ScriptContext
{ scriptContextTxInfo :: TxInfo
scriptContextPurpose :: ScriptPurpose
}
data ScriptPurpose =
Minting CurrencySymbol
| Spending TxOutRef
| Rewarding StakingCredential
| Certifying DCert
data TxOutRef = TxOutRef
{ txOutRefId :: TxId
, txOutRefIdx :: Integer
}
data TxId = TxId { getTxId :: BuiltinByteString }data TxInfo = TxInfo
{ txInfoInputs :: [TxInInfo]
, txInfoReferenceInputs :: [TxInInfo]
, txInfoOutputs :: [TxOut]
, txInfoFee :: Value
, txInfoMint :: Value
, txInfoDCert :: [DCert]
, txInfoWdrl :: Map StakingCredential Integer
, txInfoValidRange :: POSIXTimeRange
, txInfoSignatories :: [PubKeyHash]
, txInfoRedeemers :: Map ScriptPurpose Redeemer
, txInfoData :: Map DatumHash Datum
, txInfoId :: TxId
}1 slot = 1 second up to 36 hours(by protocol design)- Allowed time range can be provided on transaction creation in POSIX format
type POSIXTimeRange = Interval POSIXTime
newtype POSIXTime = POSIXTime { getPOSIXTime :: Integer }
data Interval a = Interval
{ ivFrom :: LowerBound a
, ivTo :: UpperBound a
}
data LowerBound a = LowerBound (Extended a) Closure
data UpperBound a = UpperBound (Extended a) Closure
type Closure = Bool
data Extended a = NegInf | Finite a | PosInfAs a donator I want to lock an ADA value in a contract, to be rewarded to a given beneficiary according a given deadline
As the beneficiary I want to reclaim the locked ADA value only after the deadline
mkdir modules/M10-a-vesting-contract-i/{contract,dapp}
(
cd modules/M10-a-vesting-contract-i/contract
nix flake init -t github:LovelaceAcademy/nix-templates#hor-plutus
)
(
cd modules/M10-a-vesting-contract-i/dapp
nix flake init -t github:LovelaceAcademy/nix-templates#pix-ctl-full
)

