Skip to content

Commit f25405b

Browse files
author
euonymos
committed
feat: build/parse Oura txs
1 parent 3d7e90a commit f25405b

File tree

10 files changed

+174
-85
lines changed

10 files changed

+174
-85
lines changed

src/Cardano/CEM/Examples/Auction.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE NoPolyKinds #-}
2-
{-# OPTIONS_GHC -Wno-unrecognised-pragmas -ddump-splices #-}
2+
3+
-- {-# OPTIONS_GHC -Wno-unrecognised-pragmas -ddump-splices #-}
34

45
module Cardano.CEM.Examples.Auction where
56

src/Cardano/CEM/Examples/Voting.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# OPTIONS_GHC -Wno-unrecognised-pragmas -ddump-splices #-}
1+
-- {-# OPTIONS_GHC -Wno-unrecognised-pragmas -ddump-splices #-}
22

33
{-# HLINT ignore "Use when" #-}
44

src/Cardano/CEM/Monads.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ data TxResolutionError
140140
-- | Ability to send transaction to chain
141141
class (MonadQueryUtxo m) => MonadSubmitTx m where
142142
submitResolvedTx :: ResolvedTx -> m (Either TxSubmittingError TxId)
143-
submitResolvedTxRet :: ResolvedTx -> m (Either TxSubmittingError (TxBody Era, TxInMode, UTxO Era))
143+
submitResolvedTxRet ::
144+
ResolvedTx ->
145+
m (Either TxSubmittingError (TxBodyContent BuildTx Era, TxBody Era, TxInMode, UTxO Era))
144146

145147
-- | Stuff needed to use monad for local testing
146148
class (MonadSubmitTx m) => MonadTest m where

src/Cardano/CEM/Monads/CLB.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,22 @@ instance (Monad m, MonadBlockchainParams (ClbT m)) => MonadQueryUtxo (ClbT m) wh
9191
ByTxIns txIns -> return $ \txIn _ -> txIn `elem` txIns
9292

9393
instance (Monad m, MonadBlockchainParams (ClbT m)) => MonadSubmitTx (ClbT m) where
94-
submitResolvedTxRet :: ResolvedTx -> ClbT m (Either TxSubmittingError (TxBody Era, TxInMode, UTxO Era))
94+
submitResolvedTxRet ::
95+
ResolvedTx ->
96+
ClbT m (Either TxSubmittingError (TxBodyContent BuildTx Era, TxBody Era, TxInMode, UTxO Era))
9597
submitResolvedTxRet tx = do
9698
cardanoTxBodyFromResolvedTx tx >>= \case
97-
Right (body, txInMode@(TxInMode ShelleyBasedEraBabbage tx'), utxo) -> do
99+
Right (preBody, body, txInMode@(TxInMode ShelleyBasedEraBabbage tx'), utxo) -> do
98100
result <- sendTx tx'
99101
case result of
100-
Success _ _ -> return $ Right (body, txInMode, utxo)
102+
Success _ _ -> return $ Right (preBody, body, txInMode, utxo)
101103
Fail _ validationError ->
102104
return $ Left $ UnhandledNodeSubmissionError validationError
103-
Right (_, _, _) -> fail "Unsupported tx format"
105+
Right _ -> fail "Unsupported tx format"
104106
Left e -> return $ Left $ UnhandledAutobalanceError e
105107

106108
submitResolvedTx :: ResolvedTx -> ClbT m (Either TxSubmittingError TxId)
107-
submitResolvedTx tx = mapRight (getTxId . (\(a, _, _) -> a)) <$> submitResolvedTxRet tx
109+
submitResolvedTx tx = mapRight (getTxId . (\(_, a, _, _) -> a)) <$> submitResolvedTxRet tx
108110

109111
instance (Monad m, MonadBlockchainParams (ClbT m)) => MonadTest (ClbT m) where
110112
getTestWalletSks = return $ map intToCardanoSk [1 .. 10]

src/Cardano/CEM/Monads/L1.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ instance MonadSubmitTx L1Runner where
103103
submitResolvedTx tx = do
104104
ci <- localNode <$> ask
105105
cardanoTxBodyFromResolvedTx tx >>= \case
106-
Right (body, txInMode, _) ->
106+
Right (_, body, txInMode, _) ->
107107
liftIO $
108108
submitTxToNodeLocal ci txInMode >>= \case
109109
SubmitSuccess ->

src/Cardano/CEM/Monads/L1Commons.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Data.Maybe (mapMaybe)
2323
cardanoTxBodyFromResolvedTx ::
2424
(MonadQueryUtxo m, MonadBlockchainParams m) =>
2525
ResolvedTx ->
26-
m (Either (TxBodyErrorAutoBalance Era) (TxBody Era, TxInMode, UTxO Era))
26+
m (Either (TxBodyErrorAutoBalance Era) (TxBodyContent BuildTx Era, TxBody Era, TxInMode, UTxO Era))
2727
cardanoTxBodyFromResolvedTx (MkResolvedTx {..}) = do
2828
-- (lowerBound, upperBound) <- convertValidityBound validityBound
2929

@@ -93,7 +93,7 @@ cardanoTxBodyFromResolvedTx (MkResolvedTx {..}) = do
9393

9494
lift $ recordFee txInsUtxo body
9595

96-
return (body, txInMode, utxo)
96+
return (preBody, body, txInMode, txInsUtxo)
9797
where
9898
recordFee txInsUtxo body@(TxBody content) = do
9999
case txFee content of

src/Cardano/CEM/OffChain.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ resolveTxAndSubmit spec = do
237237
resolveTxAndSubmitRet ::
238238
(MonadQueryUtxo m, MonadSubmitTx m, MonadIO m) =>
239239
TxSpec ->
240-
m (Either TxResolutionError (TxBody Era, TxInMode, UTxO Era))
240+
m (Either TxResolutionError (TxBodyContent BuildTx Era, TxBody Era, TxInMode, UTxO Era))
241241
resolveTxAndSubmitRet spec = do
242242
result <- runExceptT $ do
243243
resolved <- ExceptT $ resolveTx spec
244244
let result = submitResolvedTxRet resolved
245245
ExceptT $ first UnhandledSubmittingError <$> result
246-
logEvent $ SubmittedTxSpec spec (mapRight (getTxId . (\(a, _, _) -> a)) result)
246+
logEvent $ SubmittedTxSpec spec (mapRight (getTxId . (\(_, a, _, _) -> a)) result)
247247
return result

test/Auction.hs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import Prelude
55
import Control.Monad.Trans (MonadIO (..))
66
import PlutusLedgerApi.V1.Value (assetClassValue)
77

8+
import Cardano.Api.NetworkId (toShelleyNetwork)
9+
810
import Cardano.CEM
911
import Cardano.CEM.Examples.Auction
1012
import Cardano.CEM.Examples.Compilation ()
@@ -17,6 +19,9 @@ import Test.Hspec (describe, it, shouldBe)
1719
import TestNFT (testNftAssetClass)
1820
import Utils (execClb, mintTestTokens, submitAndCheck, submitCheckReturn)
1921

22+
import Data.Aeson (encode)
23+
import OuraFilters.Mock (extractEvent, resolvedTxToOura)
24+
2025
auctionSpec = describe "Auction" $ do
2126
it "Wrong transition resolution error" $ execClb $ do
2227
seller <- (!! 0) <$> getTestWalletSks
@@ -202,7 +207,7 @@ auctionSpec = describe "Auction" $ do
202207
Just (CurrentBid currentBid) <- queryScriptState auctionParams
203208
liftIO $ currentBid `shouldBe` bid1
204209

205-
(tx, txInMode, utxo) <-
210+
(preBody, tx, txInMode, utxo) <-
206211
submitCheckReturn $
207212
MkTxSpec
208213
{ actions =
@@ -215,9 +220,20 @@ auctionSpec = describe "Auction" $ do
215220
, specSigner = bidder1
216221
}
217222

218-
-- liftIO $ print tx
223+
liftIO $ print tx
224+
liftIO $ putStrLn "---"
225+
219226
-- liftIO $ print txInMode
220227
liftIO $ print utxo
228+
liftIO $ putStrLn "---"
229+
230+
let otx = resolvedTxToOura preBody utxo
231+
liftIO $ print $ encode otx
232+
liftIO $ putStrLn "---"
233+
234+
network <- toShelleyNetwork <$> askNetworkId
235+
mEvent <- liftIO $ extractEvent @SimpleAuction otx network
236+
liftIO $ print mEvent
221237

222238
submitAndCheck $
223239
MkTxSpec

0 commit comments

Comments
 (0)