Skip to content

Commit

Permalink
Merge pull request #1671 from Plutonomicon/provider-extraction-2
Browse files Browse the repository at this point in the history
Move provider and other types to separate packages
  • Loading branch information
errfrom authored Feb 4, 2025
2 parents 5b0a18b + 668422c commit 2586ef6
Show file tree
Hide file tree
Showing 44 changed files with 497 additions and 872 deletions.
154 changes: 77 additions & 77 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,83 +7,82 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Changelog](#changelog)
- [\[Unreleased\]](#unreleased)
- [Changed](#changed)
- [Fixed](#fixed)
- [\[v9.3.1\]](#v931)
- [Fixed](#fixed-1)
- [\[v9.3.0\]](#v930)
- [Fixed](#fixed-2)
- [Changed](#changed-1)
- [\[v9.2.0\]](#v920)
- [Added](#added)
- [Changed](#changed-2)
- [Removed](#removed)
- [Fixed](#fixed-3)
- [\[v9.1.0\]](#v910)
- [Added](#added-1)
- [Changed](#changed-3)
- [Removed](#removed-1)
- [Fixed](#fixed-4)
- [\[v9.0.0\]](#v900)
- [Deprecated](#deprecated)
- [Added](#added-2)
- [Removed](#removed-2)
- [Changed](#changed-4)
- [Fixed](#fixed-5)
- [\[v8.0.0\]](#v800)
- [Added](#added-3)
- [Changed](#changed-5)
- [Fixed](#fixed-6)
- [Removed](#removed-3)
- [\[v7.0.0\]](#v700)
- [Added](#added-4)
- [Changed](#changed-6)
- [Fixed](#fixed-7)
- [Removed](#removed-4)
- [\[v6.0.0\]](#v600)
- [Added](#added-5)
- [Changed](#changed-7)
- [Fixed](#fixed-8)
- [Removed](#removed-5)
- [\[v5.0.0\]](#v500)
- [Added](#added-6)
- [Changed](#changed-8)
- [Removed](#removed-6)
- [Fixed](#fixed-9)
- [Runtime Dependencies](#runtime-dependencies)
- [\[v4.0.2\] - 2023-01-17](#v402---2023-01-17)
- [Fixed](#fixed-10)
- [\[v4.0.1\] - 2022-12-20](#v401---2022-12-20)
- [Added](#added-7)
- [\[v4.0.0\] - 2022-12-15](#v400---2022-12-15)
- [Added](#added-8)
- [Changed](#changed-9)
- [Removed](#removed-7)
- [Fixed](#fixed-11)
- [Runtime Dependencies](#runtime-dependencies-1)
- [\[3.0.0\] - 2022-11-21](#300---2022-11-21)
- [Added](#added-9)
- [Changed](#changed-10)
- [Removed](#removed-8)
- [Fixed](#fixed-12)
- [Runtime Dependencies](#runtime-dependencies-2)
- [\[2.0.0\] - 2022-09-12](#200---2022-09-12)
- [Added](#added-10)
- [Changed](#changed-11)
- [Removed](#removed-9)
- [Fixed](#fixed-13)
- [\[2.0.0-alpha\] - 2022-07-05](#200-alpha---2022-07-05)
- [Added](#added-11)
- [Removed](#removed-10)
- [Changed](#changed-12)
- [Fixed](#fixed-14)
- [\[1.1.0\] - 2022-06-30](#110---2022-06-30)
- [Fixed](#fixed-15)
- [\[1.0.1\] - 2022-06-17](#101---2022-06-17)
- [Fixed](#fixed-16)
- [\[1.0.0\] - 2022-06-10](#100---2022-06-10)
- [[Unreleased]](#unreleased)
- [Changed](#changed)
- [Fixed](#fixed)
- [[v9.3.1]](#v931)
- [Fixed](#fixed-1)
- [[v9.3.0]](#v930)
- [Fixed](#fixed-2)
- [Changed](#changed-1)
- [[v9.2.0]](#v920)
- [Added](#added)
- [Changed](#changed-2)
- [Removed](#removed)
- [Fixed](#fixed-3)
- [[v9.1.0]](#v910)
- [Added](#added-1)
- [Changed](#changed-3)
- [Removed](#removed-1)
- [Fixed](#fixed-4)
- [[v9.0.0]](#v900)
- [Deprecated](#deprecated)
- [Added](#added-2)
- [Removed](#removed-2)
- [Changed](#changed-4)
- [Fixed](#fixed-5)
- [[v8.0.0]](#v800)
- [Added](#added-3)
- [Changed](#changed-5)
- [Fixed](#fixed-6)
- [Removed](#removed-3)
- [[v7.0.0]](#v700)
- [Added](#added-4)
- [Changed](#changed-6)
- [Fixed](#fixed-7)
- [Removed](#removed-4)
- [[v6.0.0]](#v600)
- [Added](#added-5)
- [Changed](#changed-7)
- [Fixed](#fixed-8)
- [Removed](#removed-5)
- [[v5.0.0]](#v500)
- [Added](#added-6)
- [Changed](#changed-8)
- [Removed](#removed-6)
- [Fixed](#fixed-9)
- [Runtime Dependencies](#runtime-dependencies)
- [[v4.0.2] - 2023-01-17](#v402---2023-01-17)
- [Fixed](#fixed-10)
- [[v4.0.1] - 2022-12-20](#v401---2022-12-20)
- [Added](#added-7)
- [[v4.0.0] - 2022-12-15](#v400---2022-12-15)
- [Added](#added-8)
- [Changed](#changed-9)
- [Removed](#removed-7)
- [Fixed](#fixed-11)
- [Runtime Dependencies](#runtime-dependencies-1)
- [[3.0.0] - 2022-11-21](#300---2022-11-21)
- [Added](#added-9)
- [Changed](#changed-10)
- [Removed](#removed-8)
- [Fixed](#fixed-12)
- [Runtime Dependencies](#runtime-dependencies-2)
- [[2.0.0] - 2022-09-12](#200---2022-09-12)
- [Added](#added-10)
- [Changed](#changed-11)
- [Removed](#removed-9)
- [Fixed](#fixed-13)
- [[2.0.0-alpha] - 2022-07-05](#200-alpha---2022-07-05)
- [Added](#added-11)
- [Removed](#removed-10)
- [Changed](#changed-12)
- [Fixed](#fixed-14)
- [[1.1.0] - 2022-06-30](#110---2022-06-30)
- [Fixed](#fixed-15)
- [[1.0.1] - 2022-06-17](#101---2022-06-17)
- [Fixed](#fixed-16)
- [[1.0.0] - 2022-06-10](#100---2022-06-10)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand All @@ -102,6 +101,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Switched to the [purescript-cardano-package-set](https://github.com/mlabs-haskell/purescript-cardano-package-set) in `packages.dhall` (see the [section on updating PureScript dependencies in the docs](./doc/ctl-as-dependency.md)) ([#1667](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1667))
- Switched to the aggregate `@mlabs-haskell/ctl-npm-meta` package for NPM dependencies (see the [section on updating JS dependencies in the docs](./doc/ctl-as-dependency.md)) ([#1666](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1666))
- Ignore **any** tx evaluation errors if tx marked invalid. Previously, certain internal evaluation errors were not properly handled, leading to unexpected behavior for a subset of explicitly marked "invalid" transactions. ([#1668](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1668))
- `Provider` (previously called `QueryHandle`) is extracted to its own package [purescript-cardano-provider](https://github.com/mlabs-haskell/purescript-cardano-provider) using module names in the format `Cardano.Provider.*` ([#1671](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1671))

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions doc/comparisons.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ Additionally, CTL supports [testing with real wallets](./e2e-testing.md) via hea

Lucid aims for simplicity, while CTL allows more fine-grained control over transaction building process without losing the benefits of declarativeness.

- CTL uses [`cardano-serialization-lib`](https://github.com/Emurgo/cardano-serialization-lib/), while Lucid uses a fork of [`cardano-multiplatform-lib`](https://github.com/berry-pool/cardano-multiplatform-lib). Lucid allows to use CML's `TxBuilder` or [call CML directly](https://lucid.spacebudz.io/docs/advanced/cml/), while CTL allows to alter the transaction arbitrarily as PureScript data type either before or after balancing.
- CTL uses [`cardano-serialization-lib`](https://github.com/Emurgo/cardano-serialization-lib/), while Lucid uses [`Pallas`](https://github.com/txpipe/pallas).
- In CTL, CSL types and method wrappers are used via [`purescript-cardano-serialization-lib`](https://github.com/mlabs-haskell/purescript-cardano-serialization-lib) and [`purescript-cardano-types`](https://github.com/mlabs-haskell/purescript-cardano-types). However, `TxBuilder` APIs from CSL are not provided by these packages.
- Plutus Data conversion is handled via a [schema-enabled API](https://lucid.spacebudz.io/docs/advanced/type-casting/) in Lucid. CTL allows for automatic `ToData` / `FromData` deriving for some types, via `HasPlutusSchema`.
- Plutus Data conversion is handled via a [schema-enabled API](https://github.com/spacebudz/lucid/blob/e13206b225edb0e55a7eeb98b1200223e201fbfe/examples/typed_data.ts#L15) in Lucid. CTL allows for automatic `ToData` / `FromData` deriving for some types, via `HasPlutusSchema`.
4 changes: 2 additions & 2 deletions doc/custom-query-layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

CTL can be extended with custom (user) query layers if needed. At this moment it can be done by forking.

Every query CTL uses, except of backend-specific ones, goes through a [provider](https://github.com/Plutonomicon/cardano-transaction-lib/blob/10a88faa2e6237aafc90568e3488f3421517af63/src/Internal/Contract/Provider/Type.purs#L36).
Every query CTL uses, except of backend-specific ones, goes through a [provider](https://github.com/mlabs-haskell/purescript-cardano-provider/blob/e789464eac6dc18708b25f7a9008a7e6633b3f9a/src/Provider/Type.purs#L20).

A new [backend option](https://github.com/Plutonomicon/cardano-transaction-lib/blob/10a88faa2e6237aafc90568e3488f3421517af63/src/Internal/Contract/ProviderBackend.purs#L57) should be added, with corresponding [initialization code](https://github.com/Plutonomicon/cardano-transaction-lib/blob/develop/src/Internal/Contract/Provider.purs)
A new [backend option](https://github.com/Plutonomicon/cardano-transaction-lib/blob/20207fcda113cdafc80ef136d4c59e1ca3fe698e/src/Internal/Contract/ProviderBackend.purs#L57) should be added, with corresponding [initialization code](https://github.com/Plutonomicon/cardano-transaction-lib/blob/develop/src/Internal/Contract/Provider.purs)

## Replacing some queries in existing backend

Expand Down
7 changes: 3 additions & 4 deletions packages.dhall
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
let upstream =
-- https://github.com/mlabs-haskell/purescript-cardano-package-set
https://raw.githubusercontent.com/mlabs-haskell/purescript-cardano-package-set/v1.0.0/packages.dhall
sha256:ba13784e7036a201398c64032426db3b22379a1d5a81e1304a4b427c0581bc53
-- https://github.com/mlabs-haskell/purescript-cardano-package-set
https://raw.githubusercontent.com/mlabs-haskell/purescript-cardano-package-set/v1.1.0/packages.dhall sha256:6197d808325030415858c597b61c83320344bf899107b83f7dfe366de4650aa6

in upstream
in upstream
24 changes: 18 additions & 6 deletions spago-packages.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
, "cardano-serialization-lib"
, "cardano-transaction-builder"
, "cardano-types"
, "cardano-provider"
, "checked-exceptions"
, "cip30"
, "cip30-mock"
Expand Down
10 changes: 5 additions & 5 deletions src/Contract/Chain.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ module Contract.Chain
, module Contract.WaitUntilSlot
) where

import Cardano.Types.Chain
( BlockHeaderHash(BlockHeaderHash)
, ChainTip(ChainTip)
, Tip(Tip, TipAtGenesis)
) as Chain
import Contract.Monad (Contract)
import Ctl.Internal.Contract (getChainTip) as Contract
import Ctl.Internal.Contract.WaitUntilSlot
Expand All @@ -13,11 +18,6 @@ import Ctl.Internal.Contract.WaitUntilSlot
, waitNSlots
, waitUntilSlot
) as Contract.WaitUntilSlot
import Ctl.Internal.Types.Chain
( BlockHeaderHash(BlockHeaderHash)
, ChainTip(ChainTip)
, Tip(Tip, TipAtGenesis)
) as Chain

getTip :: Contract Chain.Tip
getTip = Contract.getChainTip
2 changes: 1 addition & 1 deletion src/Contract/ClientError.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Contract.ClientError (module X) where

import Ctl.Internal.Service.Error
import Cardano.Provider.Error
( BlockfrostError(BlockfrostError)
, ClientError
( ClientHttpError
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/Scripts.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Contract.Scripts

import Prelude

import Cardano.Provider.Error (ClientError)
import Cardano.Types
( PlutusScript(PlutusScript)
, ScriptHash
Expand All @@ -33,7 +34,6 @@ import Cardano.Types.ScriptRef (ScriptRef)
import Contract.Monad (Contract)
import Control.Parallel (parTraverse)
import Ctl.Internal.Contract.Monad (getProvider)
import Ctl.Internal.Service.Error (ClientError)
import Data.Either (Either)
import Data.Map (Map)
import Data.Map as Map
Expand Down
4 changes: 2 additions & 2 deletions src/Contract/Staking.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import Cardano.Types
, ScriptHash
, StakeCredential(StakeCredential)
)
import Cardano.Types.DelegationsAndRewards (DelegationsAndRewards)
import Cardano.Types.DelegationsAndRewards (DelegationsAndRewards) as X
import Contract.Monad (Contract)
import Control.Monad.Reader (asks)
import Ctl.Internal.Contract.Monad (getProvider)
import Ctl.Internal.Types.DelegationsAndRewards (DelegationsAndRewards)
import Ctl.Internal.Types.DelegationsAndRewards (DelegationsAndRewards) as X
import Data.Either (either)
import Data.Maybe (Maybe)
import Data.Newtype (wrap)
Expand Down
33 changes: 16 additions & 17 deletions src/Contract/Time.purs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,12 @@ import Prelude
import Cardano.Types (BigNum, Epoch(Epoch), Slot)
import Cardano.Types (Slot(Slot)) as X
import Cardano.Types.BigNum as BigNum
import Contract.Chain (getTip) as Chain
import Contract.Log (logInfo')
import Contract.Monad (Contract, liftContractM, liftedE)
import Control.Monad.Reader.Class (asks)
import Ctl.Internal.Contract (getChainTip)
import Ctl.Internal.Contract.Monad (getProvider)
import Ctl.Internal.Helpers (liftM)
import Ctl.Internal.QueryM.Ogmios (CurrentEpoch(CurrentEpoch))
import Ctl.Internal.QueryM.Ogmios
( CurrentEpoch(CurrentEpoch)
, OgmiosEraSummaries(OgmiosEraSummaries)
) as ExportOgmios
import Ctl.Internal.Types.Chain
import Cardano.Types.Chain
( BlockHeaderHash(BlockHeaderHash)
, ChainTip(ChainTip)
, Tip(TipAtGenesis, Tip)
) as Chain
import Ctl.Internal.Types.EraSummaries
import Cardano.Types.EraSummaries
( EpochLength(EpochLength)
, EraSummaries(EraSummaries)
, EraSummary(EraSummary)
Expand All @@ -44,7 +32,18 @@ import Ctl.Internal.Types.EraSummaries
, SafeZone(SafeZone)
, SlotLength(SlotLength)
) as ExportEraSummaries
import Ctl.Internal.Types.EraSummaries (EraSummaries, EraSummary)
import Cardano.Types.EraSummaries (EraSummaries, EraSummary)
import Contract.Chain (getTip) as Chain
import Contract.Log (logInfo')
import Contract.Monad (Contract, liftContractM, liftedE)
import Control.Monad.Reader.Class (asks)
import Ctl.Internal.Contract (getChainTip)
import Ctl.Internal.Contract.Monad (getProvider)
import Ctl.Internal.Helpers (liftM)
import Ctl.Internal.QueryM.Ogmios
( CurrentEpoch(CurrentEpoch)
, OgmiosEraSummaries(OgmiosEraSummaries)
) as ExportOgmios
import Ctl.Internal.Types.Interval
( AbsTime(AbsTime)
, Closure
Expand Down Expand Up @@ -174,10 +173,10 @@ normalizeTimeInterval = case _ of
getCurrentEpoch :: Contract Epoch
getCurrentEpoch = do
provider <- getProvider
CurrentEpoch bigNum <- liftAff $ provider.getCurrentEpoch
epoch <- liftAff provider.getCurrentEpoch
map Epoch $ liftM (error "Unable to convert CurrentEpoch")
$ UInt.fromString
$ BigNum.toString (bigNum :: BigNum)
$ BigNum.toString (epoch :: BigNum)

-- | Get `EraSummaries` as used for Slot arithemetic.
-- |
Expand Down
Loading

0 comments on commit 2586ef6

Please sign in to comment.