module Morley.Client.Action.Batched
( OperationsBatch (..)
, originateContractM
, runTransactionM
, revealKeyM
, delegateM
, runOperationsBatch
) where
import Control.Lens (Prism')
import Fmt (Buildable(..))
import Morley.Client.Action.Common
import Morley.Client.Action.Operation
import Morley.Client.Logging
import Morley.Client.RPC.Class
import Morley.Client.RPC.Types
import Morley.Client.TezosClient
import Morley.Client.Types
import Morley.Tezos.Address
import Morley.Util.Batching
newtype OperationsBatch a = OperationsBatch
{ forall a.
OperationsBatch a
-> BatchingM
(OperationInfo ClientInput)
(OperationInfo Result)
BatchedOperationError
a
unOperationsBatch
:: BatchingM
(OperationInfo ClientInput)
(OperationInfo Result)
BatchedOperationError
a
} deriving newtype ((forall a b. (a -> b) -> OperationsBatch a -> OperationsBatch b)
-> (forall a b. a -> OperationsBatch b -> OperationsBatch a)
-> Functor OperationsBatch
forall a b. a -> OperationsBatch b -> OperationsBatch a
forall a b. (a -> b) -> OperationsBatch a -> OperationsBatch b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> OperationsBatch a -> OperationsBatch b
fmap :: forall a b. (a -> b) -> OperationsBatch a -> OperationsBatch b
$c<$ :: forall a b. a -> OperationsBatch b -> OperationsBatch a
<$ :: forall a b. a -> OperationsBatch b -> OperationsBatch a
Functor, Functor OperationsBatch
Functor OperationsBatch
-> (forall a. a -> OperationsBatch a)
-> (forall a b.
OperationsBatch (a -> b) -> OperationsBatch a -> OperationsBatch b)
-> (forall a b c.
(a -> b -> c)
-> OperationsBatch a -> OperationsBatch b -> OperationsBatch c)
-> (forall a b.
OperationsBatch a -> OperationsBatch b -> OperationsBatch b)
-> (forall a b.
OperationsBatch a -> OperationsBatch b -> OperationsBatch a)
-> Applicative OperationsBatch
forall a. a -> OperationsBatch a
forall a b.
OperationsBatch a -> OperationsBatch b -> OperationsBatch a
forall a b.
OperationsBatch a -> OperationsBatch b -> OperationsBatch b
forall a b.
OperationsBatch (a -> b) -> OperationsBatch a -> OperationsBatch b
forall a b c.
(a -> b -> c)
-> OperationsBatch a -> OperationsBatch b -> OperationsBatch 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
$cpure :: forall a. a -> OperationsBatch a
pure :: forall a. a -> OperationsBatch a
$c<*> :: forall a b.
OperationsBatch (a -> b) -> OperationsBatch a -> OperationsBatch b
<*> :: forall a b.
OperationsBatch (a -> b) -> OperationsBatch a -> OperationsBatch b
$cliftA2 :: forall a b c.
(a -> b -> c)
-> OperationsBatch a -> OperationsBatch b -> OperationsBatch c
liftA2 :: forall a b c.
(a -> b -> c)
-> OperationsBatch a -> OperationsBatch b -> OperationsBatch c
$c*> :: forall a b.
OperationsBatch a -> OperationsBatch b -> OperationsBatch b
*> :: forall a b.
OperationsBatch a -> OperationsBatch b -> OperationsBatch b
$c<* :: forall a b.
OperationsBatch a -> OperationsBatch b -> OperationsBatch a
<* :: forall a b.
OperationsBatch a -> OperationsBatch b -> OperationsBatch a
Applicative)
data BatchedOperationError
= UnexpectedOperationResult
instance Buildable BatchedOperationError where
build :: BatchedOperationError -> Doc
build = \case
BatchedOperationError
UnexpectedOperationResult ->
Doc
"Got unexpected operation type within result of batched operation"
runOperationM
:: (inp -> OperationInfo ClientInput)
-> (Prism' (OperationInfo Result) out)
-> inp
-> OperationsBatch out
runOperationM :: forall inp out.
(inp -> OperationInfo ClientInput)
-> Prism' (OperationInfo Result) out -> inp -> OperationsBatch out
runOperationM inp -> OperationInfo ClientInput
wrapInp Prism' (OperationInfo Result) out
unwrapOut inp
inp = BatchingM
(OperationInfo ClientInput)
(OperationInfo Result)
BatchedOperationError
out
-> OperationsBatch out
forall a.
BatchingM
(OperationInfo ClientInput)
(OperationInfo Result)
BatchedOperationError
a
-> OperationsBatch a
OperationsBatch (BatchingM
(OperationInfo ClientInput)
(OperationInfo Result)
BatchedOperationError
out
-> OperationsBatch out)
-> BatchingM
(OperationInfo ClientInput)
(OperationInfo Result)
BatchedOperationError
out
-> OperationsBatch out
forall a b. (a -> b) -> a -> b
$
inp -> OperationInfo ClientInput
wrapInp inp
inp OperationInfo ClientInput
-> (OperationInfo Result -> Either BatchedOperationError out)
-> BatchingM
(OperationInfo ClientInput)
(OperationInfo Result)
BatchedOperationError
out
forall i o e a. i -> (o -> Either e a) -> BatchingM i o e a
`submitThenParse`
BatchedOperationError
-> Maybe out -> Either BatchedOperationError out
forall l r. l -> Maybe r -> Either l r
maybeToRight BatchedOperationError
UnexpectedOperationResult (Maybe out -> Either BatchedOperationError out)
-> (OperationInfo Result -> Maybe out)
-> OperationInfo Result
-> Either BatchedOperationError out
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OperationInfo Result
-> Getting (First out) (OperationInfo Result) out -> Maybe out
forall s a. s -> Getting (First a) s a -> Maybe a
^? Getting (First out) (OperationInfo Result) out
Prism' (OperationInfo Result) out
unwrapOut)
runTransactionM :: TransactionData -> OperationsBatch [WithSource EventOperation]
runTransactionM :: TransactionData -> OperationsBatch [WithSource EventOperation]
runTransactionM = (TransactionData -> OperationInfo ClientInput)
-> Prism' (OperationInfo Result) [WithSource EventOperation]
-> TransactionData
-> OperationsBatch [WithSource EventOperation]
forall inp out.
(inp -> OperationInfo ClientInput)
-> Prism' (OperationInfo Result) out -> inp -> OperationsBatch out
runOperationM TransferInfo ClientInput -> OperationInfo ClientInput
TransactionData -> OperationInfo ClientInput
forall i. TransferInfo i -> OperationInfo i
OpTransfer p [WithSource EventOperation] (f [WithSource EventOperation])
-> p (OperationInfo Result) (f (OperationInfo Result))
p (TransferInfo Result) (f (TransferInfo Result))
-> p (OperationInfo Result) (f (OperationInfo Result))
forall i (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (TransferInfo i) (f (TransferInfo i))
-> p (OperationInfo i) (f (OperationInfo i))
Prism' (OperationInfo Result) [WithSource EventOperation]
_OpTransfer
originateContractM :: OriginationData -> OperationsBatch ContractAddress
originateContractM :: OriginationData -> OperationsBatch ContractAddress
originateContractM = (OriginationData -> OperationInfo ClientInput)
-> Prism' (OperationInfo Result) ContractAddress
-> OriginationData
-> OperationsBatch ContractAddress
forall inp out.
(inp -> OperationInfo ClientInput)
-> Prism' (OperationInfo Result) out -> inp -> OperationsBatch out
runOperationM OriginationInfo ClientInput -> OperationInfo ClientInput
OriginationData -> OperationInfo ClientInput
forall i. OriginationInfo i -> OperationInfo i
OpOriginate p ContractAddress (f ContractAddress)
-> p (OperationInfo Result) (f (OperationInfo Result))
p (OriginationInfo Result) (f (OriginationInfo Result))
-> p (OperationInfo Result) (f (OperationInfo Result))
forall i (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (OriginationInfo i) (f (OriginationInfo i))
-> p (OperationInfo i) (f (OperationInfo i))
Prism' (OperationInfo Result) ContractAddress
_OpOriginate
revealKeyM :: RevealData -> OperationsBatch ()
revealKeyM :: RevealData -> OperationsBatch ()
revealKeyM = (RevealData -> OperationInfo ClientInput)
-> Prism' (OperationInfo Result) ()
-> RevealData
-> OperationsBatch ()
forall inp out.
(inp -> OperationInfo ClientInput)
-> Prism' (OperationInfo Result) out -> inp -> OperationsBatch out
runOperationM RevealInfo ClientInput -> OperationInfo ClientInput
RevealData -> OperationInfo ClientInput
forall i. RevealInfo i -> OperationInfo i
OpReveal p () (f ()) -> p (OperationInfo Result) (f (OperationInfo Result))
p (RevealInfo Result) (f (RevealInfo Result))
-> p (OperationInfo Result) (f (OperationInfo Result))
forall i (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (RevealInfo i) (f (RevealInfo i))
-> p (OperationInfo i) (f (OperationInfo i))
Prism' (OperationInfo Result) ()
_OpReveal
delegateM :: DelegationData -> OperationsBatch ()
delegateM :: DelegationData -> OperationsBatch ()
delegateM = (DelegationData -> OperationInfo ClientInput)
-> Prism' (OperationInfo Result) ()
-> DelegationData
-> OperationsBatch ()
forall inp out.
(inp -> OperationInfo ClientInput)
-> Prism' (OperationInfo Result) out -> inp -> OperationsBatch out
runOperationM DelegationInfo ClientInput -> OperationInfo ClientInput
DelegationData -> OperationInfo ClientInput
forall i. DelegationInfo i -> OperationInfo i
OpDelegation p () (f ()) -> p (OperationInfo Result) (f (OperationInfo Result))
p (DelegationInfo Result) (f (DelegationInfo Result))
-> p (OperationInfo Result) (f (OperationInfo Result))
forall i (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (DelegationInfo i) (f (DelegationInfo i))
-> p (OperationInfo i) (f (OperationInfo i))
Prism' (OperationInfo Result) ()
_OpDelegation
runOperationsBatch
:: ( HasTezosRpc m
, HasTezosClient m
, WithClientLog env m
)
=> ImplicitAddressWithAlias
-> OperationsBatch a
-> m (Maybe OperationHash, a)
runOperationsBatch :: forall (m :: * -> *) env a.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m) =>
ImplicitAddressWithAlias
-> OperationsBatch a -> m (Maybe OperationHash, a)
runOperationsBatch ImplicitAddressWithAlias
sender (OperationsBatch BatchingM
(OperationInfo ClientInput)
(OperationInfo Result)
BatchedOperationError
a
batch) =
([OperationInfo ClientInput]
-> m (Maybe OperationHash, [OperationInfo Result]))
-> BatchingM
(OperationInfo ClientInput)
(OperationInfo Result)
BatchedOperationError
a
-> m (Maybe OperationHash, a)
forall (m :: * -> *) e i r o a.
(Functor m, Buildable e) =>
([i] -> m (r, [o])) -> BatchingM i o e a -> m (r, a)
unsafeRunBatching (ImplicitAddressWithAlias
-> [OperationInfo ClientInput]
-> m (Maybe OperationHash, [OperationInfo Result])
forall (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m) =>
ImplicitAddressWithAlias
-> [OperationInfo ClientInput]
-> m (Maybe OperationHash, [OperationInfo Result])
runOperations ImplicitAddressWithAlias
sender) BatchingM
(OperationInfo ClientInput)
(OperationInfo Result)
BatchedOperationError
a
batch