Skip to content

Commit

Permalink
deploying to testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
brunjlar committed Jan 26, 2022
1 parent af511ff commit e17d071
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -26,11 +26,15 @@
- [Part 3 - Handling Time](https://youtu.be/mf06ll-4j2w)
- [Part 4 - A Vesting Example](https://youtu.be/ae7U_yKIQ0Y)
- [Part 5 - Parameterized Contracts](https://youtu.be/XqFILXV_ACM)
- [Part 6 - Deploying to the Testnet](https://youtu.be/ABtffZPoUqU)
- [Part 7 - Homework](https://youtu.be/GGUT2O_0urQ)
- [Part 8 - Summary](https://youtu.be/uyaPtayBRb8)

## Code Examples

- Lecture #1: [English Auction](code/week01)
- Lecture #2: [Simple Validation](code/week02)
- Lecture #3: [Script Contexts & Parameterized Contracts](code/week03)

## Exercises

Expand Down Expand Up @@ -59,6 +63,11 @@
- Fix and complete the code in the [Homework1](code/week02/src/Week02/Homework1.hs) module.
- Fix and complete the code in the [Homework2](code/week02/src/Week02/Homework2.hs) module.

- Week #3

- Fix and complete the code in the [Homework1](code/week03/src/Week03/Homework1.hs) module.
- Fix and complete the code in the [Homework2](code/week03/src/Week03/Homework2.hs) module.

## Some Plutus Modules

- `Ledger.Scripts`, contains functions related to untyped Plutus scripts.
Expand Down
3 changes: 3 additions & 0 deletions code/week03/plutus-pioneer-program-week03.cabal
Expand Up @@ -17,6 +17,8 @@ library
, Week03.Vesting
build-depends: aeson
, base ^>=4.14.1.0
, bytestring
, cardano-api
, containers
, data-default
, playground-common
Expand All @@ -26,6 +28,7 @@ library
, plutus-ledger-constraints
, plutus-tx-plugin
, plutus-tx
, serialise
, text
default-language: Haskell2010
ghc-options: -Wall -fobject-code -fno-ignore-interface-pragmas -fno-omit-interface-pragmas -fno-strictness -fno-spec-constr -fno-specialise
42 changes: 41 additions & 1 deletion code/week03/src/Week03/Deploy.hs
@@ -1,3 +1,43 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}

module Week03.Deploy
(
( writeJSON
, writeValidator
, writeUnit
, writeVestingValidator
) where

import Cardano.Api
import Cardano.Api.Shelley (PlutusScript (..))
import Codec.Serialise (serialise)
import Data.Aeson (encode)
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Short as SBS
import PlutusTx (Data (..))
import qualified PlutusTx
import qualified Ledger

import Week03.Parameterized

dataToScriptData :: Data -> ScriptData
dataToScriptData (Constr n xs) = ScriptDataConstructor n $ dataToScriptData <$> xs
dataToScriptData (Map xs) = ScriptDataMap [(dataToScriptData x, dataToScriptData y) | (x, y) <- xs]
dataToScriptData (List xs) = ScriptDataList $ dataToScriptData <$> xs
dataToScriptData (I n) = ScriptDataNumber n
dataToScriptData (B bs) = ScriptDataBytes bs

writeJSON :: PlutusTx.ToData a => FilePath -> a -> IO ()
writeJSON file = LBS.writeFile file . encode . scriptDataToJson ScriptDataJsonDetailedSchema . dataToScriptData . PlutusTx.toData

writeValidator :: FilePath -> Ledger.Validator -> IO (Either (FileError ()) ())
writeValidator file = writeFileTextEnvelope @(PlutusScript PlutusScriptV1) file Nothing . PlutusScriptSerialised . SBS.toShort . LBS.toStrict . serialise . Ledger.unValidatorScript

writeUnit :: IO ()
writeUnit = writeJSON "testnet/unit.json" ()

writeVestingValidator :: IO (Either (FileError ()) ())
writeVestingValidator = writeValidator "testnet/vesting.plutus" $ validator $ VestingParam
{ beneficiary = Ledger.PaymentPubKeyHash "c2ff616e11299d9094ce0a7eb5b7284b705147a822f4ffbd471f971a"
, deadline = 1643235300000
}
6 changes: 6 additions & 0 deletions code/week03/testnet/.gitignore
@@ -0,0 +1,6 @@
01.*
02.*
node.socket
protocol.json
tx.*
vesting.*
18 changes: 18 additions & 0 deletions code/week03/testnet/give.sh
@@ -0,0 +1,18 @@
cardano-cli transaction build \
--alonzo-era \
--testnet-magic 1097911063 \
--change-address $(cat 01.addr) \
--tx-in abae0d0e19f75938537dc5e33252567ae3b1df1f35aafedd1402b6b9ccb7685a#0 \
--tx-out "$(cat vesting.addr) 200000000 lovelace" \
--tx-out-datum-hash-file unit.json \
--out-file tx.body

cardano-cli transaction sign \
--tx-body-file tx.body \
--signing-key-file 01.skey \
--testnet-magic 1097911063 \
--out-file tx.signed

cardano-cli transaction submit \
--testnet-magic 1097911063 \
--tx-file tx.signed
23 changes: 23 additions & 0 deletions code/week03/testnet/grab.sh
@@ -0,0 +1,23 @@
cardano-cli transaction build \
--alonzo-era \
--testnet-magic 1097911063 \
--change-address $(cat 02.addr) \
--tx-in 18cbe6cadecd3f89b60e08e68e5e6c7d72d730aaa1ad21431590f7e6643438ef#1 \
--tx-in-script-file vesting.plutus \
--tx-in-datum-file unit.json \
--tx-in-redeemer-file unit.json \
--tx-in-collateral 18e93407ea137b6be63039fd3c564d4c5233e7eb7ce4ee845bc7df12c80e4df7#1 \
--required-signer-hash c2ff616e11299d9094ce0a7eb5b7284b705147a822f4ffbd471f971a \
--invalid-before 48866954 \
--protocol-params-file protocol.json \
--out-file tx.body

cardano-cli transaction sign \
--tx-body-file tx.body \
--signing-key-file 02.skey \
--testnet-magic 1097911063 \
--out-file tx.signed

cardano-cli transaction submit \
--testnet-magic 1097911063 \
--tx-file tx.signed
17 changes: 17 additions & 0 deletions code/week03/testnet/send.sh
@@ -0,0 +1,17 @@
cardano-cli transaction build \
--alonzo-era \
--testnet-magic 1097911063 \
--change-address $(cat 01.addr) \
--tx-in dfc1a522cd34fe723a0e89f68ed43a520fd218e20d8e5705b120d2cedc7f45ad#0 \
--tx-out "$(cat 02.addr) 10000000 lovelace" \
--out-file tx.body

cardano-cli transaction sign \
--tx-body-file tx.body \
--signing-key-file 01.skey \
--testnet-magic 1097911063 \
--out-file tx.signed

cardano-cli transaction submit \
--testnet-magic 1097911063 \
--tx-file tx.signed
1 change: 1 addition & 0 deletions code/week03/testnet/unit.json
@@ -0,0 +1 @@
{"constructor":0,"fields":[]}

0 comments on commit e17d071

Please sign in to comment.