Plutonomicon / cardano-transaction-lib

A Purescript library for building smart contract transactions on Cardano
https://plutonomicon.github.io/cardano-transaction-lib/
MIT License
93 stars 50 forks source link

Make `Contract` query backend configurable #1119

Closed klntsky closed 1 year ago

klntsky commented 2 years ago

Make Contract runtime and ConfigParams parametrize-able with a backend. Move every query layer function to a handle (as in handle pattern):

type QueryHandle = 
  { getChainTip :: Aff ChainTip
  , getDatumByHash :: DatumHash -> Aff Datum
  ...
  }

Particular handle contents are TBD. Please pay close attention to this description: https://github.com/Plutonomicon/cardano-transaction-lib/issues/524 - it should highlight what is required to be in the handle. In particular, note that we use EraSummaries ogmios endpoint in QueryM for time conversions (slotToPosixTime, posixTimeToSlot), so we should expose only these functions in the handle, and not the whole eraSummaries.


QueryM monad should be either removed or used only for Ogmios/ODC/ctl-server backends, and Contract should contain a reference to a handle instead. ConfigParams should be changed: we should include a type BackendSpec { ctlServer :: Maybe _, queryBackend:: QueryBackend } where data QueryBackend = CtlRuntime { ... } | BlockfrostRuntime {..}

We want a function of type QueryBackend -> Aff QueryHandle (attempt to use it with BlockfrostRuntime should throw an error until Blockfrost backend is implemented).

Luis-omega commented 1 year ago

Is there something more that I must know about it? I would like to take it.