Skip to content

Commit

Permalink
Alonzo UTXOW examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Corduan committed Apr 2, 2021
1 parent 0785f35 commit 42a4fcc
Show file tree
Hide file tree
Showing 7 changed files with 794 additions and 7 deletions.
12 changes: 12 additions & 0 deletions alonzo/impl/cardano-ledger-alonzo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,27 @@ test-suite tests
test/test
other-modules:
Test.Cardano.Ledger.Alonzo.Serialisation.Tripping
Test.Cardano.Ledger.Alonzo.Examples.Utxow
build-depends:
base16-bytestring,
bytestring,
cardano-binary,
cardano-ledger-alonzo,
cardano-ledger-core,
cardano-ledger-shelley-ma,
cardano-ledger-shelley-ma-test,
containers,
data-default-class,
plutus-core,
plutus-tx,
plutus-ledger-api,
QuickCheck,
small-steps,
small-steps-test,
shelley-spec-ledger,
shelley-spec-ledger-test,
strict-containers,
tasty-hunit,
tasty-quickcheck,
tasty,
test
4 changes: 3 additions & 1 deletion alonzo/impl/src/Cardano/Ledger/Alonzo/FakePlutus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,7 @@ data ScriptPurpose
data Context = Context TxInfo ScriptPurpose

instance IsData Context where
toData (Context _ _) = undefined
-- toData will be implemented in the Plutus library,
-- this is just a FakePlutus hack.
toData (Context _ _) = I 0
fromData _ctxdata = Nothing
11 changes: 9 additions & 2 deletions alonzo/impl/src/Cardano/Ledger/Alonzo/PlutusScriptApi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Cardano.Ledger.Alonzo.Tx
wits',
)
import qualified Cardano.Ledger.Alonzo.TxBody as Alonzo (TxBody (..), TxOut (..), vldt')
import Cardano.Ledger.Alonzo.TxInfo (runPLCScript, transTx, valContext)
import Cardano.Ledger.Alonzo.TxInfo (transTx, valContext)
import Cardano.Ledger.Alonzo.TxWitness (TxWitness (txwitsVKey'), txscripts')
import qualified Cardano.Ledger.Core as Core
import Cardano.Ledger.Era (Crypto, Era, ValidateScript (..))
Expand All @@ -48,6 +48,7 @@ import Data.Sequence.Strict (StrictSeq)
import Data.Set (Set)
import qualified Data.Set as Set
import GHC.Records (HasField (..))
import qualified Language.PlutusTx as P (Data (..))
import Shelley.Spec.Ledger.Address (Addr)
import Shelley.Spec.Ledger.BaseTypes (StrictMaybe (..))
import Shelley.Spec.Ledger.Credential (Credential (ScriptHashObj))
Expand Down Expand Up @@ -140,7 +141,13 @@ evalScripts tx ((AlonzoScript.TimelockScript timelock, _, _, _) : rest) =
where
vhks = Set.map witKeyHash (txwitsVKey' (wits' tx))
evalScripts tx ((AlonzoScript.PlutusScript pscript, ds, units, cost) : rest) =
runPLCScript cost pscript units (map getPlutusData ds) && evalScripts tx rest
runPLCScript_TESTING_ONLY_WARNING cost pscript units (map getPlutusData ds) && evalScripts tx rest
where
-- TEMPORARY replacement for runPLCScript in order to write tests.
-- TODO WARNING replace this function with runPLCScript AS SOON AS
-- we can supply a proper cost model to plutus
runPLCScript_TESTING_ONLY_WARNING _ _ _ ((P.I x) : _) = x == 42
runPLCScript_TESTING_ONLY_WARNING _ _ _ _ = False

-- ===================================================================
-- From Specification, Figure 12 "UTXOW helper functions"
Expand Down
2 changes: 1 addition & 1 deletion alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import Shelley.Spec.Ledger.UTxO

-- Size of the datum hash attached to the output (could be Nothing)
datHashSize :: TxOut era -> Integer
datHashSize out = error "need heapwords instance"
datHashSize out = 0 --TODO "need heapwords instance"
where
_ = getField @"datahash" out

Expand Down
6 changes: 4 additions & 2 deletions alonzo/impl/src/Cardano/Ledger/Alonzo/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ deriving stock instance
Eq (TxOut era)

instance
( Show (Core.Value era)
( Era era,
Show (Core.Value era)
) =>
Show (TxOut era)
where
show = error "Not yet implemented"
show (TxOut addr vl dh) =
"TxOut (" <> show addr <> " " <> show vl <> " " <> show dh <> ")"

deriving via InspectHeapNamed "TxOut" (TxOut era) instance NoThunks (TxOut era)

Expand Down
Loading

0 comments on commit 42a4fcc

Please sign in to comment.