Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
01.* | ||
02.* | ||
node.socket | ||
protocol.json | ||
tx.* | ||
vesting.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"constructor":0,"fields":[]} |