Skip to content

Commit fb06ec3

Browse files
committed
Add Flat instance for CompiledCodeIn
1 parent 681b986 commit fb06ec3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

plutus-tx/src/PlutusTx/Code.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import qualified PlutusCore.Pretty as PLC
1919
import qualified UntypedPlutusCore as UPLC
2020

2121
import Control.Exception
22-
import Flat (Flat, unflat)
22+
import Flat (Flat (..), unflat)
2323
import Flat.Decoder (DecodeException)
2424

2525
import qualified Data.ByteString as BS
@@ -56,6 +56,16 @@ applyCode fun arg = DeserializedCode (UPLC.applyProgram (getPlc fun) (getPlc arg
5656
sizePlc :: (PLC.Closed uni, uni `PLC.Everywhere` Flat, Flat fun, uni `PLC.Everywhere` PLC.PrettyConst, PLC.GShow uni, PLC.Pretty fun) => CompiledCodeIn uni fun a -> Integer
5757
sizePlc = UPLC.programSize . getPlc
5858

59+
instance (PLC.Closed uni, uni `PLC.Everywhere` Flat, Flat fun, uni `PLC.Everywhere` PLC.PrettyConst, PLC.GShow uni, PLC.Pretty fun)
60+
=> Flat (CompiledCodeIn uni fun a) where
61+
encode c = encode (getPlc c)
62+
63+
decode = do
64+
p <- decode
65+
pure $ DeserializedCode p Nothing
66+
67+
size c = size (getPlc c)
68+
5969
{- Note [Deserializing the AST]
6070
The types suggest that we can fail to deserialize the AST that we embedded in the program.
6171
However, we just did it ourselves, so this should be impossible, and we signal this with an

0 commit comments

Comments
 (0)