Skip to content

Commit

Permalink
feat(#348): update formatter config
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabhxyz committed Sep 5, 2024
1 parent 965a151 commit e52a873
Show file tree
Hide file tree
Showing 82 changed files with 2,433 additions and 2,431 deletions.
4 changes: 3 additions & 1 deletion fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
indentation: 2
comma-style: leading
record-brace-space: true
indent-wheres: true
indent-wheres: false
respectful: true
haddock-style: multi-line
newlines-between-decls: 1
single-constraint-parens: never
single-deriving-parens: never
14 changes: 7 additions & 7 deletions src-plutustx/GeniusYield/OnChain/AStakeValidator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ mkAStakeValidator addr _ ctx' = case scriptContextPurpose ctx of
Certifying _ -> ()
Rewarding _ -> if paidToAddress then () else error ()
_ -> error ()
where
ctx :: ScriptContext
ctx = unsafeFromBuiltinData ctx'
where
ctx :: ScriptContext
ctx = unsafeFromBuiltinData ctx'

info :: TxInfo
info = scriptContextTxInfo ctx
info :: TxInfo
info = scriptContextTxInfo ctx

paidToAddress :: Bool
paidToAddress = any (\o -> txOutAddress o == addr) $ txInfoOutputs info
paidToAddress :: Bool
paidToAddress = any (\o -> txOutAddress o == addr) $ txInfoOutputs info
20 changes: 10 additions & 10 deletions src-plutustx/GeniusYield/OnChain/Examples/ReadOracle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ mkReadOracleValidator :: BuiltinData -> BuiltinData -> BuiltinData -> ()
mkReadOracleValidator _ _ ctx'
| any (hasOutputDatum . txOutDatum) refins = ()
| otherwise = error ()
where
ctx :: ScriptContext
ctx = unsafeFromBuiltinData ctx'
where
ctx :: ScriptContext
ctx = unsafeFromBuiltinData ctx'

info :: TxInfo
info = scriptContextTxInfo ctx
info :: TxInfo
info = scriptContextTxInfo ctx

refins :: [TxOut]
refins = map txInInfoResolved (txInfoReferenceInputs info)
refins :: [TxOut]
refins = map txInInfoResolved (txInfoReferenceInputs info)

hasOutputDatum :: OutputDatum -> Bool
hasOutputDatum (OutputDatum _) = True
hasOutputDatum _ = False
hasOutputDatum :: OutputDatum -> Bool
hasOutputDatum (OutputDatum _) = True
hasOutputDatum _ = False
16 changes: 8 additions & 8 deletions src-plutustx/GeniusYield/OnChain/TestToken.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ mkTestTokenPolicy amt tn utxo _ ctx'
| tn /= tn' = traceError "wrong token"
| amt /= amt' = traceError "wrong amount"
| otherwise = ()
where
ctx :: ScriptContext
ctx = unsafeFromBuiltinData ctx'
where
ctx :: ScriptContext
ctx = unsafeFromBuiltinData ctx'

info :: TxInfo
info = scriptContextTxInfo ctx
info :: TxInfo
info = scriptContextTxInfo ctx

[(_, tn', amt')] = flattenValue $ txInfoMint info
[(_, tn', amt')] = flattenValue $ txInfoMint info

hasn'tUTxO :: Bool
hasn'tUTxO = all (\i -> txInInfoOutRef i /= utxo) $ txInfoInputs info
hasn'tUTxO :: Bool
hasn'tUTxO = all (\i -> txInInfoOutRef i /= utxo) $ txInfoInputs info
2 changes: 1 addition & 1 deletion src/GeniusYield/Api/TestTokens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import GeniusYield.TxBuilder
import GeniusYield.Types

mintTestTokens ::
(GYTxUserQueryMonad m) =>
GYTxUserQueryMonad m =>
GYTokenName ->
Natural ->
m (GYAssetClass, GYTxSkeleton 'PlutusV2)
Expand Down
4 changes: 2 additions & 2 deletions src/GeniusYield/CardanoApi/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import GeniusYield.Types
-------------------------------------------------------------------------------

newtype CardanoQueryException = CardanoQueryException String
deriving stock (Show)
deriving anyclass (Exception)
deriving stock Show
deriving anyclass Exception

-------------------------------------------------------------------------------
-- Low-level query runners
Expand Down
10 changes: 5 additions & 5 deletions src/GeniusYield/Examples/Gift.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ giftScript =
UPLC.LamAbs ann redeemerName $
UPLC.LamAbs ann scName $
UPLC.Var ann scName
where
ann = ()
where
ann = ()

datumName = UPLC.Name "datum" (UPLC.Unique 0)
redeemerName = UPLC.Name "redeemer" (UPLC.Unique 1)
scName = UPLC.Name "sc" (UPLC.Unique 2)
datumName = UPLC.Name "datum" (UPLC.Unique 0)
redeemerName = UPLC.Name "redeemer" (UPLC.Unique 1)
scName = UPLC.Name "sc" (UPLC.Unique 2)

giftScript' :: UPLC.Term UPLC.DeBruijn UPLC.DefaultUni UPLC.DefaultFun ()
giftScript' = toDeBruijn giftScript
Expand Down
10 changes: 5 additions & 5 deletions src/GeniusYield/Examples/Limbo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ limboScript =
UPLC.LamAbs ann redeemerName $
UPLC.LamAbs ann scName $
UPLC.Error ann
where
ann = ()
where
ann = ()

datumName = UPLC.Name "datum" (UPLC.Unique 0)
redeemerName = UPLC.Name "redeemer" (UPLC.Unique 1)
scName = UPLC.Name "sc" (UPLC.Unique 2)
datumName = UPLC.Name "datum" (UPLC.Unique 0)
redeemerName = UPLC.Name "redeemer" (UPLC.Unique 1)
scName = UPLC.Name "sc" (UPLC.Unique 2)

limboScript' :: UPLC.Term UPLC.DeBruijn UPLC.DefaultUni UPLC.DefaultFun ()
limboScript' = toDeBruijn limboScript
Expand Down
10 changes: 5 additions & 5 deletions src/GeniusYield/Examples/Treat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ treatScript =
ann
(UPLC.Builtin ann PLC.SerialiseData)
(UPLC.Var ann scName)
where
ann = ()
where
ann = ()

datumName = UPLC.Name "datum" (UPLC.Unique 0)
redeemerName = UPLC.Name "redeemer" (UPLC.Unique 1)
scName = UPLC.Name "sc" (UPLC.Unique 2)
datumName = UPLC.Name "datum" (UPLC.Unique 0)
redeemerName = UPLC.Name "redeemer" (UPLC.Unique 1)
scName = UPLC.Name "sc" (UPLC.Unique 2)

treatScript' :: UPLC.Term UPLC.DeBruijn UPLC.DefaultUni UPLC.DefaultFun ()
treatScript' = toDeBruijn treatScript
Expand Down
130 changes: 65 additions & 65 deletions src/GeniusYield/GYConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ data GYCoreProviderInfo
= GYNodeKupo {cpiSocketPath :: !FilePath, cpiKupoUrl :: !Text}
| GYMaestro {cpiMaestroToken :: !(Confidential Text), cpiTurboSubmit :: !(Maybe Bool)}
| GYBlockfrost {cpiBlockfrostKey :: !(Confidential Text)}
deriving stock (Show)
deriving stock Show

$( deriveFromJSON
defaultOptions
Expand Down Expand Up @@ -130,7 +130,7 @@ data GYCoreConfig = GYCoreConfig
}
-- , cfgUtxoCacheEnable :: !Bool

deriving stock (Show)
deriving stock Show

$( deriveFromJSON
defaultOptions
Expand Down Expand Up @@ -254,69 +254,69 @@ logTiming providers@GYProviders {..} =
, gyGetStakeAddressInfo = gyGetStakeAddressInfo'
, gyLog' = gyLog'
}
where
wrap :: String -> IO a -> IO a
wrap msg m = do
(!a, !t) <- duration m
gyLog providers "" GYDebug $ msg <> " took " <> show t
pure a

gyLookupDatum' :: GYLookupDatum
gyLookupDatum' = wrap "gyLookupDatum" . gyLookupDatum

gySubmitTx' :: GYSubmitTx
gySubmitTx' = wrap "gySubmitTx" . gySubmitTx

gyAwaitTxConfirmed' :: GYAwaitTx
gyAwaitTxConfirmed' p = wrap "gyAwaitTxConfirmed" . gyAwaitTxConfirmed p

gySlotActions' :: GYSlotActions
gySlotActions' =
GYSlotActions
{ gyGetSlotOfCurrentBlock' = wrap "gyGetSlotOfCurrentBlock" $ gyGetSlotOfCurrentBlock providers
, gyWaitForNextBlock' = wrap "gyWaitForNextBlock" $ gyWaitForNextBlock providers
, gyWaitUntilSlot' = wrap "gyWaitUntilSlot" . gyWaitUntilSlot providers
}

gyGetParameters' :: GYGetParameters
gyGetParameters' =
GYGetParameters
{ gyGetProtocolParameters' = wrap "gyGetProtocolParameters" $ gyGetProtocolParameters providers
, gyGetSystemStart' = wrap "gyGetSystemStart" $ gyGetSystemStart providers
, gyGetEraHistory' = wrap "gyGetEraHistory" $ gyGetEraHistory providers
, gyGetStakePools' = wrap "gyGetStakePools" $ gyGetStakePools providers
, gyGetSlotConfig' = wrap "gyGetSlotConfig" $ gyGetSlotConfig providers
}

gyQueryUTxO' :: GYQueryUTxO
gyQueryUTxO' =
GYQueryUTxO
{ gyQueryUtxosAtTxOutRefs' = wrap "gyQueryUtxosAtTxOutRefs" . gyQueryUtxosAtTxOutRefs providers
, gyQueryUtxosAtTxOutRefsWithDatums' = case gyQueryUtxosAtTxOutRefsWithDatums' gyQueryUTxO of
Nothing -> Nothing
Just q -> Just $ wrap "gyQueryUtxosAtTxOutRefsWithDatums" . q
, gyQueryUtxoAtTxOutRef' = wrap "gyQueryUtxoAtTxOutRef" . gyQueryUtxoAtTxOutRef providers
, gyQueryUtxoRefsAtAddress' = wrap "gyQueryUtxoRefsAtAddress" . gyQueryUtxoRefsAtAddress providers
, gyQueryUtxosAtAddress' = \addr mac -> wrap "gyQueryUtxosAtAddress'" $ gyQueryUtxosAtAddress providers addr mac
, gyQueryUtxosAtAddressWithDatums' = case gyQueryUtxosAtAddressWithDatums' gyQueryUTxO of
Nothing -> Nothing
Just q -> Just $ \addr mac -> wrap "gyQueryUtxosAtAddressWithDatums'" $ q addr mac
, gyQueryUtxosAtAddresses' = wrap "gyQueryUtxosAtAddresses" . gyQueryUtxosAtAddresses providers
, gyQueryUtxosAtAddressesWithDatums' = case gyQueryUtxosAtAddressesWithDatums' gyQueryUTxO of
Nothing -> Nothing
Just q -> Just $ wrap "gyQueryUtxosAtAddressesWithDatums" . q
, gyQueryUtxosAtPaymentCredential' = \cred -> wrap "gyQueryUtxosAtPaymentCredential" . gyQueryUtxosAtPaymentCredential providers cred
, gyQueryUtxosAtPaymentCredWithDatums' = case gyQueryUtxosAtPaymentCredWithDatums' gyQueryUTxO of
Nothing -> Nothing
Just q -> Just $ \cred mac -> wrap "gyQueryUtxosAtPaymentCredWithDatums" $ q cred mac
, gyQueryUtxosAtPaymentCredentials' = wrap "gyQueryUtxosAtPaymentCredentials" . gyQueryUtxosAtPaymentCredentials providers
, gyQueryUtxosAtPaymentCredsWithDatums' = case gyQueryUtxosAtPaymentCredsWithDatums' gyQueryUTxO of
Nothing -> Nothing
Just q -> Just $ wrap "gyQueryUtxosAtPaymentCredsWithDatums" . q
}

gyGetStakeAddressInfo' :: GYStakeAddress -> IO (Maybe GYStakeAddressInfo)
gyGetStakeAddressInfo' = wrap "gyGetStakeAddressInfo" . gyGetStakeAddressInfo
where
wrap :: String -> IO a -> IO a
wrap msg m = do
(!a, !t) <- duration m
gyLog providers "" GYDebug $ msg <> " took " <> show t
pure a

gyLookupDatum' :: GYLookupDatum
gyLookupDatum' = wrap "gyLookupDatum" . gyLookupDatum

gySubmitTx' :: GYSubmitTx
gySubmitTx' = wrap "gySubmitTx" . gySubmitTx

gyAwaitTxConfirmed' :: GYAwaitTx
gyAwaitTxConfirmed' p = wrap "gyAwaitTxConfirmed" . gyAwaitTxConfirmed p

gySlotActions' :: GYSlotActions
gySlotActions' =
GYSlotActions
{ gyGetSlotOfCurrentBlock' = wrap "gyGetSlotOfCurrentBlock" $ gyGetSlotOfCurrentBlock providers
, gyWaitForNextBlock' = wrap "gyWaitForNextBlock" $ gyWaitForNextBlock providers
, gyWaitUntilSlot' = wrap "gyWaitUntilSlot" . gyWaitUntilSlot providers
}

gyGetParameters' :: GYGetParameters
gyGetParameters' =
GYGetParameters
{ gyGetProtocolParameters' = wrap "gyGetProtocolParameters" $ gyGetProtocolParameters providers
, gyGetSystemStart' = wrap "gyGetSystemStart" $ gyGetSystemStart providers
, gyGetEraHistory' = wrap "gyGetEraHistory" $ gyGetEraHistory providers
, gyGetStakePools' = wrap "gyGetStakePools" $ gyGetStakePools providers
, gyGetSlotConfig' = wrap "gyGetSlotConfig" $ gyGetSlotConfig providers
}

gyQueryUTxO' :: GYQueryUTxO
gyQueryUTxO' =
GYQueryUTxO
{ gyQueryUtxosAtTxOutRefs' = wrap "gyQueryUtxosAtTxOutRefs" . gyQueryUtxosAtTxOutRefs providers
, gyQueryUtxosAtTxOutRefsWithDatums' = case gyQueryUtxosAtTxOutRefsWithDatums' gyQueryUTxO of
Nothing -> Nothing
Just q -> Just $ wrap "gyQueryUtxosAtTxOutRefsWithDatums" . q
, gyQueryUtxoAtTxOutRef' = wrap "gyQueryUtxoAtTxOutRef" . gyQueryUtxoAtTxOutRef providers
, gyQueryUtxoRefsAtAddress' = wrap "gyQueryUtxoRefsAtAddress" . gyQueryUtxoRefsAtAddress providers
, gyQueryUtxosAtAddress' = \addr mac -> wrap "gyQueryUtxosAtAddress'" $ gyQueryUtxosAtAddress providers addr mac
, gyQueryUtxosAtAddressWithDatums' = case gyQueryUtxosAtAddressWithDatums' gyQueryUTxO of
Nothing -> Nothing
Just q -> Just $ \addr mac -> wrap "gyQueryUtxosAtAddressWithDatums'" $ q addr mac
, gyQueryUtxosAtAddresses' = wrap "gyQueryUtxosAtAddresses" . gyQueryUtxosAtAddresses providers
, gyQueryUtxosAtAddressesWithDatums' = case gyQueryUtxosAtAddressesWithDatums' gyQueryUTxO of
Nothing -> Nothing
Just q -> Just $ wrap "gyQueryUtxosAtAddressesWithDatums" . q
, gyQueryUtxosAtPaymentCredential' = \cred -> wrap "gyQueryUtxosAtPaymentCredential" . gyQueryUtxosAtPaymentCredential providers cred
, gyQueryUtxosAtPaymentCredWithDatums' = case gyQueryUtxosAtPaymentCredWithDatums' gyQueryUTxO of
Nothing -> Nothing
Just q -> Just $ \cred mac -> wrap "gyQueryUtxosAtPaymentCredWithDatums" $ q cred mac
, gyQueryUtxosAtPaymentCredentials' = wrap "gyQueryUtxosAtPaymentCredentials" . gyQueryUtxosAtPaymentCredentials providers
, gyQueryUtxosAtPaymentCredsWithDatums' = case gyQueryUtxosAtPaymentCredsWithDatums' gyQueryUTxO of
Nothing -> Nothing
Just q -> Just $ wrap "gyQueryUtxosAtPaymentCredsWithDatums" . q
}

gyGetStakeAddressInfo' :: GYStakeAddress -> IO (Maybe GYStakeAddressInfo)
gyGetStakeAddressInfo' = wrap "gyGetStakeAddressInfo" . gyGetStakeAddressInfo

duration :: IO a -> IO (a, NominalDiffTime)
duration m = do
Expand Down
2 changes: 1 addition & 1 deletion src/GeniusYield/HTTP/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import GeniusYield.Imports
type IsGYApiError :: Type -> Constraint
class IsGYApiError e where
toApiError :: e -> GYApiError
default toApiError :: (Exception e) => e -> GYApiError
default toApiError :: Exception e => e -> GYApiError
toApiError e = someBackendError . Txt.pack $ displayException e

{- | An example error code can be: "INSUFFICIENT_BALANCE" (i.e.
Expand Down
10 changes: 5 additions & 5 deletions src/GeniusYield/Imports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import Data.Text.Lazy.Encoding qualified as LTE
import GHC.TypeLits (ErrorMessage (..), TypeError)

-- | Use 'TODO' instead of 'undefined's
pattern TODO :: () => (HasCallStack) => a
pattern TODO :: () => HasCallStack => a
pattern TODO <- (todoMatch -> ())
where
TODO = error "TODO"
Expand All @@ -88,15 +88,15 @@ pattern TODO <- (todoMatch -> ())
todoMatch :: a -> ()
todoMatch _ = ()

findFirst :: (Foldable f) => (a -> Maybe b) -> f a -> Maybe b
findFirst :: Foldable f => (a -> Maybe b) -> f a -> Maybe b
findFirst f xs = getFirst (foldMap (coerce f) xs)

-- poisonous instances
-- (the orphan in plutus-ledger-api was removed in Feb 2022)
instance (TypeError ('Text "Forbidden FromJSON ByteString instance")) => FromJSON ByteString where
instance TypeError ('Text "Forbidden FromJSON ByteString instance") => FromJSON ByteString where
parseJSON = error "FromJSON @ByteString"

instance (TypeError ('Text "Forbidden ToJSON ByteString instance")) => ToJSON ByteString where
instance TypeError ('Text "Forbidden ToJSON ByteString instance") => ToJSON ByteString where
toJSON = error "ToJSON @ByteString"

{- | Decode a lazy 'ByteString' containing UTF-8 encoded text.
Expand All @@ -119,5 +119,5 @@ hush = either (const Nothing) Just
__NOTE:__ This is also defined (& exported) in @transformers-0.6.0.0@, so should be removed once we upgrade to it.
-}
hoistMaybe :: (Applicative m) => Maybe b -> MaybeT m b
hoistMaybe :: Applicative m => Maybe b -> MaybeT m b
hoistMaybe = MaybeT . pure
Loading

0 comments on commit e52a873

Please sign in to comment.