-- SPDX-FileCopyrightText: 2021 Oxhead Alpha
-- SPDX-License-Identifier: LicenseRef-MIT-OA

{-# LANGUAGE InstanceSigs #-}

-- | Implementation of full-featured Morley client.

module Morley.Client.Full
  ( MorleyClientEnv
  , MorleyClientM
  , runMorleyClientM
  ) where

import Colog (HasLog(..), Message)
import Network.HTTP.Types (Status(..))
import Servant.Client.Core (Request, Response, RunClient(..))
import UnliftIO (MonadUnliftIO)

import Morley.Client.App
import Morley.Client.Env (MorleyClientEnv'(..))
import Morley.Client.RPC.Class
import Morley.Client.TezosClient.Class
import Morley.Client.TezosClient.Impl qualified as TezosClient
import Morley.Client.TezosClient.Types
import Morley.Tezos.Crypto (Signature(..))
import Morley.Tezos.Crypto.Ed25519 qualified as Ed25519

type MorleyClientEnv = MorleyClientEnv' MorleyClientM

newtype MorleyClientM a = MorleyClientM
  { MorleyClientM a -> ReaderT MorleyClientEnv IO a
unMorleyClientM :: ReaderT MorleyClientEnv IO a }
  deriving newtype
    ( a -> MorleyClientM b -> MorleyClientM a
(a -> b) -> MorleyClientM a -> MorleyClientM b
(forall a b. (a -> b) -> MorleyClientM a -> MorleyClientM b)
-> (forall a b. a -> MorleyClientM b -> MorleyClientM a)
-> Functor MorleyClientM
forall a b. a -> MorleyClientM b -> MorleyClientM a
forall a b. (a -> b) -> MorleyClientM a -> MorleyClientM b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> MorleyClientM b -> MorleyClientM a
$c<$ :: forall a b. a -> MorleyClientM b -> MorleyClientM a
fmap :: (a -> b) -> MorleyClientM a -> MorleyClientM b
$cfmap :: forall a b. (a -> b) -> MorleyClientM a -> MorleyClientM b
Functor, Functor MorleyClientM
a -> MorleyClientM a
Functor MorleyClientM
-> (forall a. a -> MorleyClientM a)
-> (forall a b.
    MorleyClientM (a -> b) -> MorleyClientM a -> MorleyClientM b)
-> (forall a b c.
    (a -> b -> c)
    -> MorleyClientM a -> MorleyClientM b -> MorleyClientM c)
-> (forall a b.
    MorleyClientM a -> MorleyClientM b -> MorleyClientM b)
-> (forall a b.
    MorleyClientM a -> MorleyClientM b -> MorleyClientM a)
-> Applicative MorleyClientM
MorleyClientM a -> MorleyClientM b -> MorleyClientM b
MorleyClientM a -> MorleyClientM b -> MorleyClientM a
MorleyClientM (a -> b) -> MorleyClientM a -> MorleyClientM b
(a -> b -> c)
-> MorleyClientM a -> MorleyClientM b -> MorleyClientM c
forall a. a -> MorleyClientM a
forall a b. MorleyClientM a -> MorleyClientM b -> MorleyClientM a
forall a b. MorleyClientM a -> MorleyClientM b -> MorleyClientM b
forall a b.
MorleyClientM (a -> b) -> MorleyClientM a -> MorleyClientM b
forall a b c.
(a -> b -> c)
-> MorleyClientM a -> MorleyClientM b -> MorleyClientM c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: MorleyClientM a -> MorleyClientM b -> MorleyClientM a
$c<* :: forall a b. MorleyClientM a -> MorleyClientM b -> MorleyClientM a
*> :: MorleyClientM a -> MorleyClientM b -> MorleyClientM b
$c*> :: forall a b. MorleyClientM a -> MorleyClientM b -> MorleyClientM b
liftA2 :: (a -> b -> c)
-> MorleyClientM a -> MorleyClientM b -> MorleyClientM c
$cliftA2 :: forall a b c.
(a -> b -> c)
-> MorleyClientM a -> MorleyClientM b -> MorleyClientM c
<*> :: MorleyClientM (a -> b) -> MorleyClientM a -> MorleyClientM b
$c<*> :: forall a b.
MorleyClientM (a -> b) -> MorleyClientM a -> MorleyClientM b
pure :: a -> MorleyClientM a
$cpure :: forall a. a -> MorleyClientM a
$cp1Applicative :: Functor MorleyClientM
Applicative, Applicative MorleyClientM
a -> MorleyClientM a
Applicative MorleyClientM
-> (forall a b.
    MorleyClientM a -> (a -> MorleyClientM b) -> MorleyClientM b)
-> (forall a b.
    MorleyClientM a -> MorleyClientM b -> MorleyClientM b)
-> (forall a. a -> MorleyClientM a)
-> Monad MorleyClientM
MorleyClientM a -> (a -> MorleyClientM b) -> MorleyClientM b
MorleyClientM a -> MorleyClientM b -> MorleyClientM b
forall a. a -> MorleyClientM a
forall a b. MorleyClientM a -> MorleyClientM b -> MorleyClientM b
forall a b.
MorleyClientM a -> (a -> MorleyClientM b) -> MorleyClientM b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> MorleyClientM a
$creturn :: forall a. a -> MorleyClientM a
>> :: MorleyClientM a -> MorleyClientM b -> MorleyClientM b
$c>> :: forall a b. MorleyClientM a -> MorleyClientM b -> MorleyClientM b
>>= :: MorleyClientM a -> (a -> MorleyClientM b) -> MorleyClientM b
$c>>= :: forall a b.
MorleyClientM a -> (a -> MorleyClientM b) -> MorleyClientM b
$cp1Monad :: Applicative MorleyClientM
Monad, MonadReader MorleyClientEnv
    , Monad MorleyClientM
Monad MorleyClientM
-> (forall a. IO a -> MorleyClientM a) -> MonadIO MorleyClientM
IO a -> MorleyClientM a
forall a. IO a -> MorleyClientM a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> MorleyClientM a
$cliftIO :: forall a. IO a -> MorleyClientM a
$cp1MonadIO :: Monad MorleyClientM
MonadIO, Monad MorleyClientM
e -> MorleyClientM a
Monad MorleyClientM
-> (forall e a. Exception e => e -> MorleyClientM a)
-> MonadThrow MorleyClientM
forall e a. Exception e => e -> MorleyClientM a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
throwM :: e -> MorleyClientM a
$cthrowM :: forall e a. Exception e => e -> MorleyClientM a
$cp1MonadThrow :: Monad MorleyClientM
MonadThrow, MonadThrow MorleyClientM
MonadThrow MorleyClientM
-> (forall e a.
    Exception e =>
    MorleyClientM a -> (e -> MorleyClientM a) -> MorleyClientM a)
-> MonadCatch MorleyClientM
MorleyClientM a -> (e -> MorleyClientM a) -> MorleyClientM a
forall e a.
Exception e =>
MorleyClientM a -> (e -> MorleyClientM a) -> MorleyClientM a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
catch :: MorleyClientM a -> (e -> MorleyClientM a) -> MorleyClientM a
$ccatch :: forall e a.
Exception e =>
MorleyClientM a -> (e -> MorleyClientM a) -> MorleyClientM a
$cp1MonadCatch :: MonadThrow MorleyClientM
MonadCatch, MonadCatch MorleyClientM
MonadCatch MorleyClientM
-> (forall b.
    ((forall a. MorleyClientM a -> MorleyClientM a) -> MorleyClientM b)
    -> MorleyClientM b)
-> (forall b.
    ((forall a. MorleyClientM a -> MorleyClientM a) -> MorleyClientM b)
    -> MorleyClientM b)
-> (forall a b c.
    MorleyClientM a
    -> (a -> ExitCase b -> MorleyClientM c)
    -> (a -> MorleyClientM b)
    -> MorleyClientM (b, c))
-> MonadMask MorleyClientM
MorleyClientM a
-> (a -> ExitCase b -> MorleyClientM c)
-> (a -> MorleyClientM b)
-> MorleyClientM (b, c)
((forall a. MorleyClientM a -> MorleyClientM a) -> MorleyClientM b)
-> MorleyClientM b
((forall a. MorleyClientM a -> MorleyClientM a) -> MorleyClientM b)
-> MorleyClientM b
forall b.
((forall a. MorleyClientM a -> MorleyClientM a) -> MorleyClientM b)
-> MorleyClientM b
forall a b c.
MorleyClientM a
-> (a -> ExitCase b -> MorleyClientM c)
-> (a -> MorleyClientM b)
-> MorleyClientM (b, c)
forall (m :: * -> *).
MonadCatch m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
    m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
generalBracket :: MorleyClientM a
-> (a -> ExitCase b -> MorleyClientM c)
-> (a -> MorleyClientM b)
-> MorleyClientM (b, c)
$cgeneralBracket :: forall a b c.
MorleyClientM a
-> (a -> ExitCase b -> MorleyClientM c)
-> (a -> MorleyClientM b)
-> MorleyClientM (b, c)
uninterruptibleMask :: ((forall a. MorleyClientM a -> MorleyClientM a) -> MorleyClientM b)
-> MorleyClientM b
$cuninterruptibleMask :: forall b.
((forall a. MorleyClientM a -> MorleyClientM a) -> MorleyClientM b)
-> MorleyClientM b
mask :: ((forall a. MorleyClientM a -> MorleyClientM a) -> MorleyClientM b)
-> MorleyClientM b
$cmask :: forall b.
((forall a. MorleyClientM a -> MorleyClientM a) -> MorleyClientM b)
-> MorleyClientM b
$cp1MonadMask :: MonadCatch MorleyClientM
MonadMask, MonadIO MorleyClientM
MonadIO MorleyClientM
-> (forall b.
    ((forall a. MorleyClientM a -> IO a) -> IO b) -> MorleyClientM b)
-> MonadUnliftIO MorleyClientM
((forall a. MorleyClientM a -> IO a) -> IO b) -> MorleyClientM b
forall b.
((forall a. MorleyClientM a -> IO a) -> IO b) -> MorleyClientM b
forall (m :: * -> *).
MonadIO m
-> (forall b. ((forall a. m a -> IO a) -> IO b) -> m b)
-> MonadUnliftIO m
withRunInIO :: ((forall a. MorleyClientM a -> IO a) -> IO b) -> MorleyClientM b
$cwithRunInIO :: forall b.
((forall a. MorleyClientM a -> IO a) -> IO b) -> MorleyClientM b
$cp1MonadUnliftIO :: MonadIO MorleyClientM
MonadUnliftIO
    )

-- | Run 'MorleyClientM' action within given t'MorleyClientEnv'. Retry action
-- in case of invalid counter error.
runMorleyClientM :: MorleyClientEnv -> MorleyClientM a -> IO a
runMorleyClientM :: MorleyClientEnv -> MorleyClientM a -> IO a
runMorleyClientM MorleyClientEnv
env MorleyClientM a
client =
  ReaderT MorleyClientEnv IO a -> MorleyClientEnv -> IO a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (MorleyClientM a -> ReaderT MorleyClientEnv IO a
forall a. MorleyClientM a -> ReaderT MorleyClientEnv IO a
unMorleyClientM MorleyClientM a
client) MorleyClientEnv
env

instance HasLog MorleyClientEnv Message MorleyClientM where
  getLogAction :: MorleyClientEnv -> LogAction MorleyClientM Message
getLogAction = MorleyClientEnv -> LogAction MorleyClientM Message
forall (m :: * -> *). MorleyClientEnv' m -> ClientLogAction m
mceLogAction
  setLogAction :: LogAction MorleyClientM Message
-> MorleyClientEnv -> MorleyClientEnv
setLogAction LogAction MorleyClientM Message
action MorleyClientEnv
mce = MorleyClientEnv
mce { mceLogAction :: LogAction MorleyClientM Message
mceLogAction = LogAction MorleyClientM Message
action }

instance HasTezosClient MorleyClientM where
  signBytes :: AddressOrAlias
-> Maybe ScrubbedBytes -> ByteString -> MorleyClientM Signature
signBytes AddressOrAlias
senderAlias Maybe ScrubbedBytes
mbPassword ByteString
opHash = MorleyClientM Signature -> MorleyClientM Signature
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
retryOnceOnTimeout (MorleyClientM Signature -> MorleyClientM Signature)
-> MorleyClientM Signature -> MorleyClientM Signature
forall a b. (a -> b) -> a -> b
$ do
    MorleyClientEnv
env <- MorleyClientM MorleyClientEnv
forall r (m :: * -> *). MonadReader r m => m r
ask
    case MorleyClientEnv -> Maybe SecretKey
forall (m :: * -> *). MorleyClientEnv' m -> Maybe SecretKey
mceSecretKey MorleyClientEnv
env of
      Just SecretKey
sk -> Signature -> MorleyClientM Signature
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Signature -> MorleyClientM Signature)
-> (Signature -> Signature) -> Signature -> MorleyClientM Signature
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Signature -> Signature
SignatureEd25519 (Signature -> MorleyClientM Signature)
-> Signature -> MorleyClientM Signature
forall a b. (a -> b) -> a -> b
$ SecretKey -> ByteString -> Signature
Ed25519.sign SecretKey
sk ByteString
opHash
      Maybe SecretKey
Nothing -> AddressOrAlias
-> Maybe ScrubbedBytes -> ByteString -> MorleyClientM Signature
forall env (m :: * -> *).
(WithClientLog env m, HasTezosClientEnv env, MonadIO m,
 MonadCatch m) =>
AddressOrAlias -> Maybe ScrubbedBytes -> ByteString -> m Signature
TezosClient.signBytes AddressOrAlias
senderAlias Maybe ScrubbedBytes
mbPassword ByteString
opHash
  waitForOperation :: OperationHash -> MorleyClientM ()
waitForOperation = MorleyClientM () -> MorleyClientM ()
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
retryOnceOnTimeout (MorleyClientM () -> MorleyClientM ())
-> (OperationHash -> MorleyClientM ())
-> OperationHash
-> MorleyClientM ()
forall a b c. SuperComposition a b c => a -> b -> c
... OperationHash -> MorleyClientM ()
forall env (m :: * -> *).
(WithClientLog env m, HasTezosClientEnv env, MonadIO m,
 MonadCatch m) =>
OperationHash -> m ()
TezosClient.waitForOperationInclusion
  rememberContract :: Bool -> Address -> AliasOrAliasHint -> MorleyClientM ()
rememberContract = MorleyClientM () -> MorleyClientM ()
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
failOnTimeout (MorleyClientM () -> MorleyClientM ())
-> (Bool -> Address -> AliasOrAliasHint -> MorleyClientM ())
-> Bool
-> Address
-> AliasOrAliasHint
-> MorleyClientM ()
forall a b c. SuperComposition a b c => a -> b -> c
... Bool -> Address -> AliasOrAliasHint -> MorleyClientM ()
forall env (m :: * -> *).
(WithClientLog env m, HasTezosClientEnv env, MonadIO m,
 MonadCatch m) =>
Bool -> Address -> AliasOrAliasHint -> m ()
TezosClient.rememberContract
  importKey :: Bool -> AliasOrAliasHint -> SecretKey -> MorleyClientM Alias
importKey = MorleyClientM Alias -> MorleyClientM Alias
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
failOnTimeout (MorleyClientM Alias -> MorleyClientM Alias)
-> (Bool -> AliasOrAliasHint -> SecretKey -> MorleyClientM Alias)
-> Bool
-> AliasOrAliasHint
-> SecretKey
-> MorleyClientM Alias
forall a b c. SuperComposition a b c => a -> b -> c
... Bool -> AliasOrAliasHint -> SecretKey -> MorleyClientM Alias
forall env (m :: * -> *).
(WithClientLog env m, HasTezosClientEnv env, MonadIO m,
 MonadCatch m) =>
Bool -> AliasOrAliasHint -> SecretKey -> m Alias
TezosClient.importKey
  resolveAddressMaybe :: AddressOrAlias -> MorleyClientM (Maybe Address)
resolveAddressMaybe = MorleyClientM (Maybe Address) -> MorleyClientM (Maybe Address)
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
retryOnceOnTimeout (MorleyClientM (Maybe Address) -> MorleyClientM (Maybe Address))
-> (AddressOrAlias -> MorleyClientM (Maybe Address))
-> AddressOrAlias
-> MorleyClientM (Maybe Address)
forall a b c. SuperComposition a b c => a -> b -> c
... AddressOrAlias -> MorleyClientM (Maybe Address)
forall env (m :: * -> *).
(WithClientLog env m, HasTezosClientEnv env, MonadIO m,
 MonadCatch m) =>
AddressOrAlias -> m (Maybe Address)
TezosClient.resolveAddressMaybe
  getAlias :: AddressOrAlias -> MorleyClientM Alias
getAlias = MorleyClientM Alias -> MorleyClientM Alias
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
retryOnceOnTimeout (MorleyClientM Alias -> MorleyClientM Alias)
-> (AddressOrAlias -> MorleyClientM Alias)
-> AddressOrAlias
-> MorleyClientM Alias
forall a b c. SuperComposition a b c => a -> b -> c
... AddressOrAlias -> MorleyClientM Alias
forall env (m :: * -> *).
(WithClientLog env m, HasTezosClientEnv env, MonadIO m,
 MonadCatch m) =>
AddressOrAlias -> m Alias
TezosClient.getAlias
  getPublicKey :: AddressOrAlias -> MorleyClientM PublicKey
getPublicKey = MorleyClientM PublicKey -> MorleyClientM PublicKey
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
retryOnceOnTimeout (MorleyClientM PublicKey -> MorleyClientM PublicKey)
-> (AddressOrAlias -> MorleyClientM PublicKey)
-> AddressOrAlias
-> MorleyClientM PublicKey
forall a b c. SuperComposition a b c => a -> b -> c
... AddressOrAlias -> MorleyClientM PublicKey
forall env (m :: * -> *).
(WithClientLog env m, HasTezosClientEnv env, MonadIO m,
 MonadCatch m) =>
AddressOrAlias -> m PublicKey
TezosClient.getPublicKey
  -- This function doesn't perform any chain related operations with tezos-client,
  -- so @ECONNRESET@ cannot appear here
  getTezosClientConfig :: MorleyClientM TezosClientConfig
getTezosClientConfig = do
    FilePath
path <- TezosClientEnv -> FilePath
tceTezosClientPath (TezosClientEnv -> FilePath)
-> MorleyClientM TezosClientEnv -> MorleyClientM FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Getting TezosClientEnv MorleyClientEnv TezosClientEnv
-> MorleyClientM TezosClientEnv
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting TezosClientEnv MorleyClientEnv TezosClientEnv
forall env. HasTezosClientEnv env => Lens' env TezosClientEnv
tezosClientEnvL
    Maybe FilePath
mbDataDir <- TezosClientEnv -> Maybe FilePath
tceMbTezosClientDataDir (TezosClientEnv -> Maybe FilePath)
-> MorleyClientM TezosClientEnv -> MorleyClientM (Maybe FilePath)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Getting TezosClientEnv MorleyClientEnv TezosClientEnv
-> MorleyClientM TezosClientEnv
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting TezosClientEnv MorleyClientEnv TezosClientEnv
forall env. HasTezosClientEnv env => Lens' env TezosClientEnv
tezosClientEnvL
    IO TezosClientConfig -> MorleyClientM TezosClientConfig
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO TezosClientConfig -> MorleyClientM TezosClientConfig)
-> IO TezosClientConfig -> MorleyClientM TezosClientConfig
forall a b. (a -> b) -> a -> b
$ FilePath -> Maybe FilePath -> IO TezosClientConfig
TezosClient.getTezosClientConfig FilePath
path Maybe FilePath
mbDataDir
  genFreshKey :: AliasOrAliasHint -> MorleyClientM Address
genFreshKey = MorleyClientM Address -> MorleyClientM Address
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
retryOnceOnTimeout (MorleyClientM Address -> MorleyClientM Address)
-> (AliasOrAliasHint -> MorleyClientM Address)
-> AliasOrAliasHint
-> MorleyClientM Address
forall a b c. SuperComposition a b c => a -> b -> c
... AliasOrAliasHint -> MorleyClientM Address
forall (m :: * -> *) env.
(MonadThrow m, MonadCatch m, WithClientLog env m,
 HasTezosClientEnv env, MonadIO m, HasTezosClient m) =>
AliasOrAliasHint -> m Address
TezosClient.genFreshKey
  genKey :: AliasOrAliasHint -> MorleyClientM Address
genKey = MorleyClientM Address -> MorleyClientM Address
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
failOnTimeout (MorleyClientM Address -> MorleyClientM Address)
-> (AliasOrAliasHint -> MorleyClientM Address)
-> AliasOrAliasHint
-> MorleyClientM Address
forall a b c. SuperComposition a b c => a -> b -> c
... AliasOrAliasHint -> MorleyClientM Address
forall (m :: * -> *) env.
(MonadThrow m, MonadCatch m, WithClientLog env m,
 HasTezosClientEnv env, MonadIO m, HasTezosClient m) =>
AliasOrAliasHint -> m Address
TezosClient.genKey
  -- Key revealing cannot be safely retried, so we're not trying to recover it
  -- from @ECONNRESET@.
  revealKey :: Alias -> Maybe ScrubbedBytes -> MorleyClientM ()
revealKey = MorleyClientM () -> MorleyClientM ()
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
failOnTimeout (MorleyClientM () -> MorleyClientM ())
-> (Alias -> Maybe ScrubbedBytes -> MorleyClientM ())
-> Alias
-> Maybe ScrubbedBytes
-> MorleyClientM ()
forall a b c. SuperComposition a b c => a -> b -> c
... Alias -> Maybe ScrubbedBytes -> MorleyClientM ()
forall env (m :: * -> *).
(WithClientLog env m, HasTezosClientEnv env, MonadIO m,
 MonadCatch m) =>
Alias -> Maybe ScrubbedBytes -> m ()
TezosClient.revealKey
  registerDelegate :: AliasOrAliasHint -> Maybe ScrubbedBytes -> MorleyClientM ()
registerDelegate = MorleyClientM () -> MorleyClientM ()
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
failOnTimeout (MorleyClientM () -> MorleyClientM ())
-> (AliasOrAliasHint -> Maybe ScrubbedBytes -> MorleyClientM ())
-> AliasOrAliasHint
-> Maybe ScrubbedBytes
-> MorleyClientM ()
forall a b c. SuperComposition a b c => a -> b -> c
... AliasOrAliasHint -> Maybe ScrubbedBytes -> MorleyClientM ()
forall env (m :: * -> *).
(WithClientLog env m, HasTezosClientEnv env, MonadIO m,
 MonadCatch m) =>
AliasOrAliasHint -> Maybe ScrubbedBytes -> m ()
TezosClient.registerDelegate
  calcTransferFee :: AddressOrAlias
-> Maybe ScrubbedBytes
-> TezosInt64
-> [CalcTransferFeeData]
-> MorleyClientM [TezosMutez]
calcTransferFee = MorleyClientM [TezosMutez] -> MorleyClientM [TezosMutez]
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
retryOnceOnTimeout (MorleyClientM [TezosMutez] -> MorleyClientM [TezosMutez])
-> (AddressOrAlias
    -> Maybe ScrubbedBytes
    -> TezosInt64
    -> [CalcTransferFeeData]
    -> MorleyClientM [TezosMutez])
-> AddressOrAlias
-> Maybe ScrubbedBytes
-> TezosInt64
-> [CalcTransferFeeData]
-> MorleyClientM [TezosMutez]
forall a b c. SuperComposition a b c => a -> b -> c
... AddressOrAlias
-> Maybe ScrubbedBytes
-> TezosInt64
-> [CalcTransferFeeData]
-> MorleyClientM [TezosMutez]
forall env (m :: * -> *).
(WithClientLog env m, HasTezosClientEnv env, MonadIO m,
 MonadCatch m) =>
AddressOrAlias
-> Maybe ScrubbedBytes
-> TezosInt64
-> [CalcTransferFeeData]
-> m [TezosMutez]
TezosClient.calcTransferFee
  calcOriginationFee :: CalcOriginationFeeData cp st -> MorleyClientM TezosMutez
calcOriginationFee = MorleyClientM TezosMutez -> MorleyClientM TezosMutez
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
retryOnceOnTimeout (MorleyClientM TezosMutez -> MorleyClientM TezosMutez)
-> (CalcOriginationFeeData cp st -> MorleyClientM TezosMutez)
-> CalcOriginationFeeData cp st
-> MorleyClientM TezosMutez
forall a b c. SuperComposition a b c => a -> b -> c
... CalcOriginationFeeData cp st -> MorleyClientM TezosMutez
forall (st :: T) env (m :: * -> *) (cp :: T).
(UntypedValScope st, WithClientLog env m, HasTezosClientEnv env,
 MonadIO m, MonadCatch m) =>
CalcOriginationFeeData cp st -> m TezosMutez
TezosClient.calcOriginationFee
  getKeyPassword :: Address -> MorleyClientM (Maybe ScrubbedBytes)
getKeyPassword = MorleyClientM (Maybe ScrubbedBytes)
-> MorleyClientM (Maybe ScrubbedBytes)
forall (m :: * -> *) a.
(MonadUnliftIO m, MonadThrow m) =>
m a -> m a
retryOnceOnTimeout (MorleyClientM (Maybe ScrubbedBytes)
 -> MorleyClientM (Maybe ScrubbedBytes))
-> (Address -> MorleyClientM (Maybe ScrubbedBytes))
-> Address
-> MorleyClientM (Maybe ScrubbedBytes)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Address -> MorleyClientM (Maybe ScrubbedBytes)
forall env (m :: * -> *).
(WithClientLog env m, HasTezosClientEnv env, MonadIO m,
 MonadMask m) =>
Address -> m (Maybe ScrubbedBytes)
TezosClient.getKeyPassword

instance RunClient MorleyClientM where
  runRequestAcceptStatus :: Maybe [Status] -> Request -> MorleyClientM Response
  runRequestAcceptStatus :: Maybe [Status] -> Request -> MorleyClientM Response
runRequestAcceptStatus Maybe [Status]
statuses Request
req = do
    ClientEnv
env <- MorleyClientEnv -> ClientEnv
forall (m :: * -> *). MorleyClientEnv' m -> ClientEnv
mceClientEnv (MorleyClientEnv -> ClientEnv)
-> MorleyClientM MorleyClientEnv -> MorleyClientM ClientEnv
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MorleyClientM MorleyClientEnv
forall r (m :: * -> *). MonadReader r m => m r
ask
    ClientEnv -> Maybe [Status] -> Request -> MorleyClientM Response
forall env (m :: * -> *).
(WithClientLog env m, MonadIO m, MonadThrow m) =>
ClientEnv -> Maybe [Status] -> Request -> m Response
runRequestAcceptStatusImpl ClientEnv
env Maybe [Status]
statuses Request
req
  throwClientError :: ClientError -> MorleyClientM a
throwClientError = ClientError -> MorleyClientM a
forall (m :: * -> *) a. MonadThrow m => ClientError -> m a
throwClientErrorImpl

instance HasTezosRpc MorleyClientM where
  getBlockHash :: BlockId -> MorleyClientM Text
getBlockHash = BlockId -> MorleyClientM Text
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> m Text
getBlockHashImpl
  getCounterAtBlock :: BlockId -> Address -> MorleyClientM TezosInt64
getCounterAtBlock = BlockId -> Address -> MorleyClientM TezosInt64
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> Address -> m TezosInt64
getCounterImpl
  getBlockHeader :: BlockId -> MorleyClientM BlockHeader
getBlockHeader = BlockId -> MorleyClientM BlockHeader
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> m BlockHeader
getBlockHeaderImpl
  getBlockConstants :: BlockId -> MorleyClientM BlockConstants
getBlockConstants = BlockId -> MorleyClientM BlockConstants
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> m BlockConstants
getBlockConstantsImpl
  getBlockOperations :: BlockId -> MorleyClientM [[BlockOperation]]
getBlockOperations = BlockId -> MorleyClientM [[BlockOperation]]
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> m [[BlockOperation]]
getBlockOperationsImpl
  getProtocolParametersAtBlock :: BlockId -> MorleyClientM ProtocolParameters
getProtocolParametersAtBlock = BlockId -> MorleyClientM ProtocolParameters
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> m ProtocolParameters
getProtocolParametersImpl
  runOperationAtBlock :: BlockId -> RunOperation -> MorleyClientM RunOperationResult
runOperationAtBlock = BlockId -> RunOperation -> MorleyClientM RunOperationResult
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> RunOperation -> m RunOperationResult
runOperationImpl
  preApplyOperationsAtBlock :: BlockId
-> [PreApplyOperation] -> MorleyClientM [RunOperationResult]
preApplyOperationsAtBlock = BlockId
-> [PreApplyOperation] -> MorleyClientM [RunOperationResult]
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> [PreApplyOperation] -> m [RunOperationResult]
preApplyOperationsImpl
  forgeOperationAtBlock :: BlockId -> ForgeOperation -> MorleyClientM HexJSONByteString
forgeOperationAtBlock = BlockId -> ForgeOperation -> MorleyClientM HexJSONByteString
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> ForgeOperation -> m HexJSONByteString
forgeOperationImpl
  injectOperation :: HexJSONByteString -> MorleyClientM OperationHash
injectOperation = HexJSONByteString -> MorleyClientM OperationHash
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
HexJSONByteString -> m OperationHash
injectOperationImpl
  getContractScriptAtBlock :: BlockId -> Address -> MorleyClientM OriginationScript
getContractScriptAtBlock = BlockId -> Address -> MorleyClientM OriginationScript
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> Address -> m OriginationScript
getContractScriptImpl
  getContractStorageAtBlock :: BlockId -> Address -> MorleyClientM Expression
getContractStorageAtBlock = BlockId -> Address -> MorleyClientM Expression
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> Address -> m Expression
getContractStorageAtBlockImpl
  getContractBigMapAtBlock :: BlockId -> Address -> GetBigMap -> MorleyClientM GetBigMapResult
getContractBigMapAtBlock = BlockId -> Address -> GetBigMap -> MorleyClientM GetBigMapResult
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> Address -> GetBigMap -> m GetBigMapResult
getContractBigMapImpl
  getBigMapValueAtBlock :: BlockId -> Natural -> Text -> MorleyClientM Expression
getBigMapValueAtBlock = BlockId -> Natural -> Text -> MorleyClientM Expression
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> Natural -> Text -> m Expression
getBigMapValueAtBlockImpl
  getBigMapValuesAtBlock :: BlockId
-> Natural
-> Maybe Natural
-> Maybe Natural
-> MorleyClientM Expression
getBigMapValuesAtBlock = BlockId
-> Natural
-> Maybe Natural
-> Maybe Natural
-> MorleyClientM Expression
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId
-> Natural -> Maybe Natural -> Maybe Natural -> m Expression
getBigMapValuesAtBlockImpl
  getBalanceAtBlock :: BlockId -> Address -> MorleyClientM Mutez
getBalanceAtBlock = BlockId -> Address -> MorleyClientM Mutez
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> Address -> m Mutez
getBalanceImpl
  getDelegateAtBlock :: BlockId -> Address -> MorleyClientM (Maybe KeyHash)
getDelegateAtBlock = BlockId -> Address -> MorleyClientM (Maybe KeyHash)
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> Address -> m (Maybe KeyHash)
getDelegateImpl
  runCodeAtBlock :: BlockId -> RunCode -> MorleyClientM RunCodeResult
runCodeAtBlock = BlockId -> RunCode -> MorleyClientM RunCodeResult
forall (m :: * -> *).
(RunClient m, MonadCatch m) =>
BlockId -> RunCode -> m RunCodeResult
runCodeImpl
  getChainId :: MorleyClientM ChainId
getChainId = MorleyClientM ChainId
forall (m :: * -> *). (RunClient m, MonadCatch m) => m ChainId
getChainIdImpl
  getManagerKeyAtBlock :: BlockId -> Address -> MorleyClientM (Maybe PublicKey)
getManagerKeyAtBlock = BlockId -> Address -> MorleyClientM (Maybe PublicKey)
forall (m :: * -> *).
(RunClient m, MonadUnliftIO m, MonadCatch m) =>
BlockId -> Address -> m (Maybe PublicKey)
getManagerKeyImpl