Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Era constraints, cardano-api-9.3.0.0 #211

Merged
merged 12 commits into from
Oct 14, 2024
Merged

Era constraints, cardano-api-9.3.0.0 #211

merged 12 commits into from
Oct 14, 2024

Conversation

j-mueller
Copy link
Owner

@j-mueller j-mueller commented Oct 6, 2024

  • Bump cardano-api to 9.3.0.0
  • Remove hard-coded ConwayEra in most places, use constraints from cardano-api
  • Update the Scripts.MatchingIndex example to use plutus v3

Thanks to @Swordlash for contributing a large part of the code

@j-mueller j-mueller changed the title Era constraints Era constraints, cardano-api-9.3.0.0 Oct 7, 2024
@j-mueller j-mueller requested a review from koslambrou October 7, 2024 12:37
BalanceChanges (Map.singleton addr value)
txOutChange _ = mempty

data BalanceTxError era =
ACoinSelectionError CoinSelectionError
| ABalancingError (BalancingError era)
deriving stock (Show, Generic)
deriving anyclass (ToJSON, FromJSON)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to keep the JSON instances

@@ -432,35 +432,36 @@ instance Monad m => MonadBlockchain (MockchainT m) where
st <- get
NodeParams{npSystemStart, npEraHistory, npSlotLength} <- ask
let slotNo = st ^. env . L.slot
utime <- either (throwError . FailWith) pure (slotToUtcTime npEraHistory npSystemStart slotNo)
-- FIXME: Propagate this to user?
let utime = either (error . (<>) "MockchainT: slotToUtcTime failed ") id (slotToUtcTime npEraHistory npSystemStart slotNo)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return Either as the third item

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this some more. The utime :: UTCTime is the time of the current slot. So it's definitely less than the current wall clock time and it should always be possible to compute it. Returning the error (Either String UTCTime) would only make sense if the query was for some time in the future, for which we could get a PastHorizon error.

Copy link
Collaborator

@koslambrou koslambrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The only thing is that we are going back from InAnyCardanoEra TxOut to TxOut era. IIRC, I did this so that we can use this with the chain-indexer which returns UTXOs from multiple eras.

Need to think about this. Maybe the solution would be to modify the chain-indexer so that it always converts UTXOs to the latest era, then we would not need InAnyCardanoEra.

=> C.AddressInEra era -> C.Script lang -> a -> C.Value -> m ()
createRefScriptInlineDatum addr script datum vl =
let dat = C.TxOutDatumInline C.babbageBasedEra (toHashableScriptData datum)
in createRefScriptBase addr script dat vl

{-| same as payToPlutusV2Inline but also specify a datum -}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update comment.

payToPlutusV2InlineWithInlineDatum addr script datum vl =
let dat = C.TxOutDatumInline C.BabbageEraOnwardsConway (toHashableScriptData datum)
in payToPlutusV2InlineBase addr script dat vl
createRefScriptInlineDatum :: forall a lang era m. (MonadBuildTx era m, Plutus.ToData a, C.IsBabbageBasedEra era, C.IsScriptLanguage lang)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep this consistent with the other names, maybe payToScriptWithRefScriptBase?

payToPlutusV2Inline :: MonadBuildTx m => C.AddressInEra C.ConwayEra -> PlutusScript PlutusScriptV2 -> C.Value -> m ()
payToPlutusV2Inline addr script = payToPlutusV2InlineBase addr script C.TxOutDatumNone
createRefScriptNoDatum :: (MonadBuildTx era m, C.IsBabbageBasedEra era, C.IsScriptLanguage lang) => C.AddressInEra era -> C.Script lang -> C.Value -> m ()
createRefScriptNoDatum addr script = createRefScriptBase addr script C.TxOutDatumNone

{-| same as payToPlutusV2Inline but also specify an inline datum -}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update comment.

@@ -3,6 +3,7 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-deprecations #-}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on when this can be removed?

newtype WalletAPIQueryT m a = WalletAPIQueryT{ runWalletAPIQueryT_ :: ReaderT ClientEnv m a }
deriving newtype (Functor, Applicative, Monad, MonadIO, MonadBlockchain, MonadLog, MonadTrans)
newtype WalletAPIQueryT era m a = WalletAPIQueryT{ runWalletAPIQueryT_ :: ReaderT ClientEnv m a }
deriving newtype (Functor, Applicative, Monad, MonadIO, MonadBlockchain era, MonadLog)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lost MonadTrans?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, brought it back in

deriving anyclass (ToJSON, FromJSON)
| SubmitError (ValidationError era)
deriving stock Show
deriving anyclass Exception
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lost JSON instances here.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We keep the original ValidationError era instead of the string. We could still convert to JSON after showing the BalanceAndSubmitError, but now we can get some more information from matching on the constructor of ValidationError

@@ -115,244 +111,97 @@ type AddressCredential = Shelley.PaymentCredential StandardCrypto

{-| A set of unspent transaction outputs
-}
newtype UtxoSet ctx a = UtxoSet{ _utxos :: Map C.TxIn (C.InAnyCardanoEra (C.TxOut ctx), a) }
newtype UtxoSet ctx era a = UtxoSet{ _utxos :: Map C.TxIn (C.TxOut ctx era, a) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the impact of this change in our other repo, but the advantage of using InAnyCardanoEra is that we can have utxos from multiple eras inside that type. Right now, you are restricted to a single era.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I brought back the InAnyCardanoEra type for UTxOs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this ever used / needed?

@j-mueller
Copy link
Owner Author

I added two tickets to address some work that needs to be done separately:

@j-mueller j-mueller merged commit 1141f7f into main Oct 14, 2024
5 checks passed
@j-mueller j-mueller deleted the era-constraints branch October 14, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants