-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
BalanceChanges (Map.singleton addr value) | ||
txOutChange _ = mempty | ||
|
||
data BalanceTxError era = | ||
ACoinSelectionError CoinSelectionError | ||
| ABalancingError (BalancingError era) | ||
deriving stock (Show, Generic) | ||
deriving anyclass (ToJSON, FromJSON) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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
.
src/base/lib/Convex/BuildTx.hs
Outdated
=> 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 -} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
?
src/base/lib/Convex/BuildTx.hs
Outdated
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 -} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update comment.
src/base/lib/Convex/PlutusLedger.hs
Outdated
@@ -3,6 +3,7 @@ | |||
{-# LANGUAGE NamedFieldPuns #-} | |||
{-# LANGUAGE TupleSections #-} | |||
{-# LANGUAGE TypeApplications #-} | |||
{-# OPTIONS_GHC -Wno-deprecations #-} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We lost MonadTrans?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 show
ing the BalanceAndSubmitError
, but now we can get some more information from matching on the constructor of ValidationError
src/base/lib/Convex/Utxos.hs
Outdated
@@ -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) } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
I added two tickets to address some work that needs to be done separately: |
28a2caa
to
344a8f6
Compare
ConwayEra
in most places, use constraints fromcardano-api
Scripts.MatchingIndex
example to use plutus v3Thanks to @Swordlash for contributing a large part of the code