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

Remove unused functions #1762

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
225c038
Remove unused Test.Plutus.Validator
locallycompact Dec 8, 2024
73b1dd1
Remove unused lookupScriptData
locallycompact Dec 8, 2024
798216f
Remove unused defaultProtocolParameters
locallycompact Dec 8, 2024
cf7893f
Remove unused Hydra.Cardano.Api.KeyWitness
locallycompact Dec 8, 2024
caa8ccf
deriving stock Eq QueryException
locallycompact Dec 8, 2024
aa8fd6c
Remove unused partial function min
locallycompact Dec 8, 2024
b3ed52d
Remove unused functions anyPayToPubKeyTxOut and headTxIn
locallycompact Dec 8, 2024
ae566fc
Remove unused function queryProtocolParameters'
locallycompact Dec 8, 2024
250ac50
Remove unused function genBytes
locallycompact Dec 8, 2024
9b8c189
Remove unused helper functions in EndToEnd benchmark
locallycompact Dec 8, 2024
d871761
Remove unused function forAll2
locallycompact Dec 8, 2024
77b0e2f
Remove unused functions guardEra, waitUntilEpoch, someTxId, outputRef
locallycompact Dec 8, 2024
38c804c
Remove unused function canApply
locallycompact Dec 8, 2024
708f682
Remove unused functions generateCardanoKey, withObject
locallycompact Dec 8, 2024
1fc4d84
Remove unused function fromLedgerScript
locallycompact Dec 8, 2024
8c3b112
Remove unused function isInitialSnapshot
locallycompact Dec 8, 2024
554fd27
Remove unused function txFee'
locallycompact Dec 8, 2024
1e6a3ac
Remove unused function recomputeIntegrityHash
locallycompact Dec 8, 2024
69bcb0c
Remove unused functions genPointInTime, genPointInTimeAfter
locallycompact Dec 8, 2024
3401fca
Remove unused function prepareTxScripts
locallycompact Dec 8, 2024
9b208fd
Remove unused function getHydraHeadV1TxName
locallycompact Dec 8, 2024
a32e06e
Remove unused function isPendingCommitFrom
locallycompact Dec 8, 2024
3e2db61
Remove unused function withCounterExample
locallycompact Dec 8, 2024
664c0ae
Remove unused function isReqSn
locallycompact Dec 8, 2024
540191e
Remove unused function watchUTxOUntil
locallycompact Dec 8, 2024
7a0f8be
Remove unused function matchFanout
locallycompact Dec 8, 2024
ae661c0
Remove unused function readVerificationKey
locallycompact Dec 8, 2024
d21401a
Remove unused function retry
locallycompact Dec 8, 2024
2ce92ec
Remove unused function orSometimes
locallycompact Dec 8, 2024
33bc2ae
Remove unused function recoverDeadline
locallycompact Dec 8, 2024
b642ce0
Remove unused function healthyCloseSnapshotNumber
locallycompact Dec 8, 2024
c7435ed
Remove unused functions shouldReturn, shouldSatisfy, shouldContain, i…
locallycompact Dec 8, 2024
76fbe82
Add github action for weeder
locallycompact Dec 8, 2024
0e4db0a
Remove unused function (\)
locallycompact Dec 8, 2024
06b71d0
Remove unused function getPaymentScriptHash
locallycompact Dec 9, 2024
ce9eabe
Remove unused function healthySignature
locallycompact Dec 9, 2024
1d1113d
Remove unused function renderEvaluationReportFailures
locallycompact Dec 9, 2024
37de2da
Remove unused function defaultNetworkId
locallycompact Dec 9, 2024
6dada1c
Remove unused functions prop_checkModel, assertBalancesInOpenHeadAreC…
locallycompact Dec 9, 2024
e17b9b7
Remove unused function showRollbackInfo
locallycompact Dec 9, 2024
a0ccd3f
Remove unused functions aliceVk, bobVk, carolVk
locallycompact Dec 9, 2024
d9e116d
Remove unused function unsafeScriptHashFromBytes
locallycompact Dec 9, 2024
9ee5c69
Remove unused function identifyNode
locallycompact Dec 9, 2024
8906a11
Remove unused function listOfCommittedUTxOs
locallycompact Dec 9, 2024
55f309d
Remove unused function mkTxOutDatum
locallycompact Dec 9, 2024
12993e1
Remove unused function fromLedgerTxId
locallycompact Dec 9, 2024
93db3dc
Remove unused function fromLedgerExUnits
locallycompact Dec 9, 2024
79df381
Remove unused function toLedgerScriptHash
locallycompact Dec 9, 2024
6a83ea5
Remove unused function renderTxs
locallycompact Dec 9, 2024
bc4b625
Remove unused function toPlutusValue
locallycompact Dec 9, 2024
aba73bd
Add weeder roots
locallycompact Dec 9, 2024
8edaea1
Remove unused function depositTxOut
locallycompact Dec 9, 2024
631370d
Remove unused function padLeft
locallycompact Dec 9, 2024
d18e001
Rename dummyValidatorHash to validatorHash
locallycompact Dec 9, 2024
a9b4b63
Rename HydraTestUtilsSpec to Spec
locallycompact Dec 9, 2024
31392bd
Use .#ci shell
locallycompact Dec 10, 2024
9ee86e6
ADd cabal update
locallycompact Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/weeder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Check code weeds

on:
# We're using merge-chains; so this needs to run then.
merge_group:
pull_request:

jobs:
weeder:
name: Check code weeds
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4

- name: ❄ Prepare nix
uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
accept-flake-config = true
log-lines = 1000

- name: ❄ Cachix cache of nix derivations
uses: cachix/cachix-action@v15
with:
name: cardano-scaling
authToken: '${{ secrets.CACHIX_CARDANO_SCALING_AUTH_TOKEN }}'

- name: 📐 Check weeder
run: |
nix develop .#ci --command -- bash -c "cabal update && cabal build all"
nix develop .#ci --command -- bash -c "weeder --require-hs-files"
1 change: 0 additions & 1 deletion hydra-cardano-api/hydra-cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ library
Hydra.Cardano.Api.CtxUTxO
Hydra.Cardano.Api.ExecutionUnits
Hydra.Cardano.Api.Hash
Hydra.Cardano.Api.KeyWitness
Hydra.Cardano.Api.Network
Hydra.Cardano.Api.NetworkId
Hydra.Cardano.Api.PlutusScript
Expand Down
10 changes: 0 additions & 10 deletions hydra-cardano-api/src/Cardano/Api/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,10 @@ render :: (TxIn, TxOut ctx era) -> Text
render (k, TxOut _ (txOutValueToValue -> v) _ _) =
T.drop 54 (renderTxIn k) <> " ↦ " <> renderValue v

-- | Select the minimum (by TxIn) utxo entry from the UTxO map.
--
-- This function is partial.
min :: UTxO -> UTxO
min = UTxO . uncurry Map.singleton . Map.findMin . toMap

-- | Remove the right hand side from the left hand side.
difference :: UTxO' out -> UTxO' out -> UTxO' out
difference a b = UTxO $ Map.difference (toMap a) (toMap b)

-- | Infix version of 'difference'.
(\\) :: UTxO' out -> UTxO' out -> UTxO' out
a \\ b = difference a b

-- * Type Conversions

-- | Transforms a UTxO containing tx outs from any era into Babbage era.
Expand Down
1 change: 0 additions & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ import Hydra.Cardano.Api.CtxTx as Extras
import Hydra.Cardano.Api.CtxUTxO as Extras
import Hydra.Cardano.Api.ExecutionUnits as Extras
import Hydra.Cardano.Api.Hash as Extras
import Hydra.Cardano.Api.KeyWitness as Extras
import Hydra.Cardano.Api.NetworkId ()
import Hydra.Cardano.Api.PlutusScript as Extras
import Hydra.Cardano.Api.PolicyId as Extras
Expand Down
4 changes: 0 additions & 4 deletions hydra-cardano-api/src/Hydra/Cardano/Api/ExecutionUnits.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ import Cardano.Ledger.Alonzo.Scripts qualified as Ledger
-- | Convert a cardano-api 'ExecutionUnits' into a cardano-ledger 'ExUnits'
toLedgerExUnits :: ExecutionUnits -> Ledger.ExUnits
toLedgerExUnits = toAlonzoExUnits

-- | Convert a cardano-ledger 'ExUnits' into a cardano-api 'ExecutionUnits'
fromLedgerExUnits :: Ledger.ExUnits -> ExecutionUnits
fromLedgerExUnits = fromAlonzoExUnits
17 changes: 0 additions & 17 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Hydra.Cardano.Api.Prelude
import Cardano.Ledger.Keys qualified as Ledger
import Cardano.Ledger.Plutus.TxInfo (transKeyHash)
import Cardano.Ledger.SafeHash (unsafeMakeSafeHash)
import Cardano.Ledger.Shelley.Scripts qualified as Ledger
import Data.ByteString qualified as BS
import PlutusLedgerApi.V3 qualified as Plutus

Expand Down Expand Up @@ -33,22 +32,6 @@ unsafePaymentKeyHashFromBytes bytes
| otherwise =
PaymentKeyHash $ Ledger.KeyHash $ unsafeHashFromBytes bytes

-- | Unsafe wrap some bytes as a 'ScriptHash', relying on the fact that Plutus
-- is using Blake2b_224 for hashing data (according to 'cardano-ledger').
--
-- Pre-condition: the input bytestring MUST be of length 28.
unsafeScriptHashFromBytes ::
HasCallStack =>
ByteString ->
ScriptHash
unsafeScriptHashFromBytes bytes
| BS.length bytes /= 28 =
error $ "unsafeScriptHashFromBytes: pre-condition failed: " <> show (BS.length bytes) <> " bytes."
| otherwise =
fromShelleyScriptHash
. Ledger.ScriptHash
$ unsafeHashFromBytes bytes

-- | Unsafe wrap some bytes as a 'Hash ScriptData', relying on the fact that
-- Plutus is using Blake2b_256 for hashing data (according to 'cardano-ledger').
--
Expand Down
74 changes: 0 additions & 74 deletions hydra-cardano-api/src/Hydra/Cardano/Api/KeyWitness.hs

This file was deleted.

18 changes: 0 additions & 18 deletions hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,12 @@ module Hydra.Cardano.Api.PlutusScript where

import Hydra.Cardano.Api.Prelude

import Cardano.Ledger.Alonzo.Scripts qualified as Ledger
import Cardano.Ledger.Plutus.Language qualified as Ledger
import Data.ByteString.Short qualified as SBS
import PlutusLedgerApi.Common qualified as Plutus
import Test.QuickCheck (listOf)

-- * Type Conversions

-- | Convert a cardano-ledger 'Script' into a cardano-api 'PlutusScript'
--
-- NOTE: This function is unsafe in two manners:
--
-- (a) If the given script is a timelock script, it throws an impure exception;
-- (b) If the given script is in a wrong language, it silently coerces it.
fromLedgerScript ::
( HasCallStack
, Ledger.AlonzoEraScript era
) =>
Ledger.AlonzoScript era ->
PlutusScript lang
fromLedgerScript = \case
Ledger.TimelockScript{} -> error "fromLedgerScript: TimelockScript"
Ledger.PlutusScript x -> Ledger.withPlutusScript x (\(Ledger.Plutus (Ledger.PlutusBinary bytes)) -> PlutusScriptSerialised bytes)

-- | Convert a serialized plutus script into a cardano-api 'PlutusScript'.
fromPlutusScript :: Plutus.SerialisedScript -> PlutusScript lang
fromPlutusScript =
Expand Down
4 changes: 0 additions & 4 deletions hydra-cardano-api/src/Hydra/Cardano/Api/PolicyId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Hydra.Cardano.Api.PolicyId where
import Hydra.Cardano.Api.Prelude

import Cardano.Ledger.Alonzo.Plutus.TxInfo qualified as Ledger
import Cardano.Ledger.Hashes qualified as Ledger
import Cardano.Ledger.Mary.Value qualified as Ledger
import Hydra.Cardano.Api.ScriptHash ()
import PlutusLedgerApi.V3 (CurrencySymbol, fromBuiltin, unCurrencySymbol)
Expand All @@ -17,9 +16,6 @@ instance Arbitrary PolicyId where

-- * Type conversions

toLedgerScriptHash :: PolicyId -> Ledger.ScriptHash StandardCrypto
toLedgerScriptHash (PolicyId scriptHash) = toShelleyScriptHash scriptHash

-- | Convert Cardano api 'PolicyId' to Cardano ledger `PolicyID`.
toLedgerPolicyID :: PolicyId -> Ledger.PolicyID StandardCrypto
toLedgerPolicyID (PolicyId sh) = Ledger.PolicyID (toShelleyScriptHash sh)
Expand Down
5 changes: 1 addition & 4 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Cardano.Ledger.SafeHash qualified as Ledger
import Data.Aeson qualified as Aeson
import Data.ByteString.Lazy qualified as BL
import Data.Function (on)
import Data.List (intercalate, sort, sortBy)
import Data.List (sort, sortBy)
import Data.Map.Strict qualified as Map
import Data.Text qualified as T
import GHC.IsList (IsList (..))
Expand All @@ -23,9 +23,6 @@ import Hydra.Cardano.Api.ScriptData (fromLedgerData)
renderTx :: Api.Tx -> String
renderTx = renderTxWithUTxO mempty

renderTxs :: [Api.Tx] -> String
renderTxs xs = intercalate "\n\n" (renderTx <$> xs)

-- | Like 'renderTx', but uses the given UTxO to resolve inputs.
renderTxWithUTxO :: UTxO -> Api.Tx -> String
renderTxWithUTxO utxo (Tx body _wits) =
Expand Down
29 changes: 1 addition & 28 deletions hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ module Hydra.Cardano.Api.ScriptData where

import Hydra.Cardano.Api.Prelude hiding (left)

import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Era qualified as Ledger
import Cardano.Ledger.Plutus.Data qualified as Ledger
import Codec.Serialise (deserialiseOrFail, serialise)
import Control.Arrow (left)
import Data.Aeson (Value (String), withText)
import Data.ByteString qualified as BS
import Data.ByteString.Base16 qualified as Base16
import Data.Map qualified as Map
import PlutusLedgerApi.V3 qualified as Plutus
import Test.QuickCheck (arbitrarySizedNatural, choose, oneof, scale, sized, vector)

Expand All @@ -36,39 +34,14 @@ fromScriptData =
Plutus.fromData . toPlutusData . getScriptData

-- | Get the 'HashableScriptData' associated to the a 'TxOut'. Note that this
-- requires the 'CtxTx' context. To get script data in a 'CtxUTxO' context, see
-- 'lookupScriptData'.
-- requires the 'CtxTx' context.
txOutScriptData :: TxOut CtxTx era -> Maybe HashableScriptData
txOutScriptData (TxOut _ _ d _) =
case d of
TxOutDatumInTx _ sd -> Just sd
TxOutDatumInline _ sd -> Just sd
_ -> Nothing

-- | Lookup included datum of given 'TxOut'.
lookupScriptData ::
forall era.
( UsesStandardCrypto era
, Ledger.Era (ShelleyLedgerEra era)
) =>
Tx era ->
TxOut CtxUTxO era ->
Maybe HashableScriptData
lookupScriptData (Tx (ShelleyTxBody _ _ _ scriptsData _ _) _) (TxOut _ _ datum _) =
case datum of
TxOutDatumNone ->
Nothing
(TxOutDatumHash _ (ScriptDataHash h)) ->
fromLedgerData <$> Map.lookup h datums
(TxOutDatumInline _ dat) ->
Just dat
where
datums :: Map (Ledger.DataHash StandardCrypto) (Ledger.Data (ShelleyLedgerEra era))
datums =
case (scriptsData :: TxBodyScriptData era) of
TxBodyNoScriptData -> mempty
TxBodyScriptData _ (Ledger.TxDats m) _ -> m

-- * Type Conversions

-- | Convert a cardano-ledger script 'Data' into a cardano-api 'ScriptDatum'.
Expand Down
9 changes: 0 additions & 9 deletions hydra-cardano-api/src/Hydra/Cardano/Api/ScriptHash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@ module Hydra.Cardano.Api.ScriptHash where

import Hydra.Cardano.Api.Prelude

import Cardano.Ledger.Credential qualified as Ledger
import Hydra.Cardano.Api.PlutusScript ()

-- * Extras

-- | Extract the payment part of an address, as a script hash.
getPaymentScriptHash :: AddressInEra era -> Maybe ScriptHash
getPaymentScriptHash = \case
AddressInEra _ (ShelleyAddress _ (Ledger.ScriptHashObj h) _) ->
Just (fromShelleyScriptHash h)
_ ->
Nothing

-- | Like 'hashScript', but for a 'ScriptInAnyLang'.
hashScriptInAnyLang :: ScriptInAnyLang -> ScriptHash
hashScriptInAnyLang (ScriptInAnyLang _ script) =
Expand Down
34 changes: 1 addition & 33 deletions hydra-cardano-api/src/Hydra/Cardano/Api/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,13 @@ where
import Hydra.Cardano.Api.Prelude

import Cardano.Api.UTxO qualified as UTxO
import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Api (
EraTx (mkBasicTx),
bodyTxL,
datsTxWitsL,
getLanguageView,
inputsTxBodyL,
mkBasicTxBody,
rdmrsTxWitsL,
scriptIntegrityHashTxBodyL,
witsTxL,
)
import Cardano.Ledger.Api qualified as Ledger
import Cardano.Ledger.Babbage.Tx (hashScriptIntegrity)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Plutus.Language qualified as Ledger
import Control.Lens ((&), (.~), (^.))
import Control.Lens ((&), (.~))
import Data.Bifunctor (bimap)
import Data.Functor ((<&>))
import Data.Set qualified as Set
Expand Down Expand Up @@ -68,12 +58,6 @@ utxoProducedByTx tx =
where
TxBody body = getTxBody tx

-- | Get explicit fees allocated to a transaction.
txFee' :: Tx era -> Coin
txFee' (getTxBody -> TxBody body) =
case txFee body of
TxFeeExplicit _ y -> y

-- * Type Conversions

-- | Convert a cardano-api 'Tx' into a matching cardano-ledger 'Tx'.
Expand All @@ -89,19 +73,3 @@ fromLedgerTx ::
Tx era
fromLedgerTx =
ShelleyTx shelleyBasedEra

-- | Compute the integrity hash of a transaction using a list of plutus languages.
recomputeIntegrityHash ::
(Ledger.AlonzoEraPParams ppera, Ledger.AlonzoEraTxWits txera, Ledger.AlonzoEraTxBody txera, EraTx txera) =>
Ledger.PParams ppera ->
[Ledger.Language] ->
Ledger.Tx txera ->
Ledger.Tx txera
recomputeIntegrityHash pp languages tx = do
tx & bodyTxL . scriptIntegrityHashTxBodyL .~ integrityHash
where
integrityHash =
hashScriptIntegrity
(Set.fromList $ getLanguageView pp <$> languages)
(tx ^. witsTxL . rdmrsTxWitsL)
(tx ^. witsTxL . datsTxWitsL)
Loading
Loading