module Morley.Client.Action.Transaction
( runTransactions
, lRunTransactions
, transfer
, lTransfer
, TD (..)
, LTransactionData (..)
, TransactionData (..)
) where
import Lorentz.Constraints
import Morley.Client.Action.Common
import Morley.Client.Action.Operation
import Morley.Client.Logging
import Morley.Client.RPC.Class
import Morley.Client.RPC.Error
import Morley.Client.RPC.Types
import Morley.Client.TezosClient.Class
import Morley.Client.Types
import Morley.Michelson.Typed qualified as T
import Morley.Michelson.Typed.Scope
import Morley.Michelson.Untyped.Entrypoints
import Morley.Tezos.Address
import Morley.Tezos.Address.Alias (AddressOrAlias(..))
import Morley.Tezos.Core (Mutez)
runTransactions
:: forall m env.
( HasTezosRpc m
, HasTezosClient m
, WithClientLog env m
)
=> ImplicitAddress -> [TransactionData]
-> m (Maybe OperationHash)
runTransactions :: forall (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m) =>
ImplicitAddress -> [TransactionData] -> m (Maybe OperationHash)
runTransactions ImplicitAddress
sender [TransactionData]
transactions = do
(Maybe OperationHash
opHash, [OperationInfo Result]
_) <- ImplicitAddressOrAlias
-> [OperationInfo ClientInput]
-> m (Maybe OperationHash, [OperationInfo Result])
forall (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m) =>
ImplicitAddressOrAlias
-> [OperationInfo ClientInput]
-> m (Maybe OperationHash, [OperationInfo Result])
runOperations (ImplicitAddress -> ImplicitAddressOrAlias
forall (kind :: AddressKind).
KindedAddress kind -> AddressOrAlias kind
AddressResolved ImplicitAddress
sender) (TransactionData -> OperationInfo ClientInput
forall i. TransferInfo i -> OperationInfo i
OpTransfer (TransactionData -> OperationInfo ClientInput)
-> [TransactionData] -> [OperationInfo ClientInput]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TransactionData]
transactions)
Maybe OperationHash -> m (Maybe OperationHash)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe OperationHash
opHash
data LTransactionData where
LTransactionData ::
forall (t :: Type). NiceParameter t =>
TD t -> LTransactionData
lRunTransactions
:: forall m env.
( HasTezosRpc m
, HasTezosClient m
, WithClientLog env m
)
=> ImplicitAddress
-> [LTransactionData]
-> m (Maybe OperationHash)
lRunTransactions :: forall (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m) =>
ImplicitAddress -> [LTransactionData] -> m (Maybe OperationHash)
lRunTransactions ImplicitAddress
sender [LTransactionData]
transactions =
ImplicitAddress -> [TransactionData] -> m (Maybe OperationHash)
forall (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m) =>
ImplicitAddress -> [TransactionData] -> m (Maybe OperationHash)
runTransactions ImplicitAddress
sender ([TransactionData] -> m (Maybe OperationHash))
-> [TransactionData] -> m (Maybe OperationHash)
forall a b. (a -> b) -> a -> b
$ (LTransactionData -> TransactionData)
-> [LTransactionData] -> [TransactionData]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map LTransactionData -> TransactionData
convertLTransactionData [LTransactionData]
transactions
where
convertLTransactionData :: LTransactionData -> TransactionData
convertLTransactionData :: LTransactionData -> TransactionData
convertLTransactionData (LTransactionData (TD {t
Maybe Mutez
L1Address
Mutez
EpName
tdMbFee :: forall t. TD t -> Maybe Mutez
tdParam :: forall t. TD t -> t
tdEpName :: forall t. TD t -> EpName
tdAmount :: forall t. TD t -> Mutez
tdReceiver :: forall t. TD t -> L1Address
tdMbFee :: Maybe Mutez
tdParam :: t
tdEpName :: EpName
tdAmount :: Mutez
tdReceiver :: L1Address
..} :: TD t))=
(NiceParameter t :- ParameterScope (ToT t))
-> (ParameterScope (ToT t) => TransactionData) -> TransactionData
forall (c :: Constraint) e r. HasDict c e => e -> (c => r) -> r
withDict (forall a. NiceParameter a :- ParameterScope (ToT a)
niceParameterEvi @t) ((ParameterScope (ToT t) => TransactionData) -> TransactionData)
-> (ParameterScope (ToT t) => TransactionData) -> TransactionData
forall a b. (a -> b) -> a -> b
$
TD (Value (ToT t)) -> TransactionData
forall (t :: T).
ParameterScope t =>
TD (Value t) -> TransactionData
TransactionData TD :: forall t. L1Address -> Mutez -> EpName -> t -> Maybe Mutez -> TD t
TD
{ tdReceiver :: L1Address
tdReceiver = L1Address
tdReceiver
, tdEpName :: EpName
tdEpName = EpName
tdEpName
, tdAmount :: Mutez
tdAmount = Mutez
tdAmount
, tdParam :: Value (ToT t)
tdParam = t -> Value (ToT t)
forall a. IsoValue a => a -> Value (ToT a)
T.toVal t
tdParam
, tdMbFee :: Maybe Mutez
tdMbFee = Maybe Mutez
tdMbFee
}
transfer
:: forall m t env kind.
( HasTezosRpc m
, HasTezosClient m
, WithClientLog env m
, ParameterScope t
, L1AddressKind kind
)
=> ImplicitAddress
-> KindedAddress kind
-> Mutez
-> EpName
-> T.Value t
-> Maybe Mutez
-> m OperationHash
transfer :: forall (m :: * -> *) (t :: T) env (kind :: AddressKind).
(HasTezosRpc m, HasTezosClient m, WithClientLog env m,
ParameterScope t, L1AddressKind kind) =>
ImplicitAddress
-> KindedAddress kind
-> Mutez
-> EpName
-> Value t
-> Maybe Mutez
-> m OperationHash
transfer ImplicitAddress
from KindedAddress kind
to Mutez
amount EpName
epName Value t
param Maybe Mutez
mbFee = do
Maybe OperationHash
res <- ImplicitAddress -> [TransactionData] -> m (Maybe OperationHash)
forall (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m) =>
ImplicitAddress -> [TransactionData] -> m (Maybe OperationHash)
runTransactions ImplicitAddress
from ([TransactionData] -> m (Maybe OperationHash))
-> [TransactionData] -> m (Maybe OperationHash)
forall a b. (a -> b) -> a -> b
$
[TD (Value t) -> TransactionData
forall (t :: T).
ParameterScope t =>
TD (Value t) -> TransactionData
TransactionData TD :: forall t. L1Address -> Mutez -> EpName -> t -> Maybe Mutez -> TD t
TD
{ tdReceiver :: L1Address
tdReceiver = KindedAddress kind -> L1Address
forall (ks :: [AddressKind]) (kind :: AddressKind).
ConstrainAddressKind ks kind =>
KindedAddress kind -> ConstrainedAddress ks
MkConstrainedAddress KindedAddress kind
to
, tdAmount :: Mutez
tdAmount = Mutez
amount
, tdEpName :: EpName
tdEpName = EpName
epName
, tdParam :: Value t
tdParam = Value t
param
, tdMbFee :: Maybe Mutez
tdMbFee = Maybe Mutez
mbFee
}
]
case Maybe OperationHash
res of
Just OperationHash
hash -> OperationHash -> m OperationHash
forall (m :: * -> *) a. Monad m => a -> m a
return OperationHash
hash
Maybe OperationHash
_ -> IncorrectRpcResponse -> m OperationHash
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM IncorrectRpcResponse
RpcNoOperationsRun
lTransfer
:: forall m t env kind.
( HasTezosRpc m
, HasTezosClient m
, WithClientLog env m
, NiceParameter t
, L1AddressKind kind
)
=> ImplicitAddress
-> KindedAddress kind
-> Mutez
-> EpName
-> t
-> Maybe Mutez
-> m OperationHash
lTransfer :: forall (m :: * -> *) t env (kind :: AddressKind).
(HasTezosRpc m, HasTezosClient m, WithClientLog env m,
NiceParameter t, L1AddressKind kind) =>
ImplicitAddress
-> KindedAddress kind
-> Mutez
-> EpName
-> t
-> Maybe Mutez
-> m OperationHash
lTransfer ImplicitAddress
from KindedAddress kind
to Mutez
amount EpName
epName t
param Maybe Mutez
mbFee =
(NiceParameter t :- ParameterScope (ToT t))
-> (ParameterScope (ToT t) => m OperationHash) -> m OperationHash
forall (c :: Constraint) e r. HasDict c e => e -> (c => r) -> r
withDict (forall a. NiceParameter a :- ParameterScope (ToT a)
niceParameterEvi @t) ((ParameterScope (ToT t) => m OperationHash) -> m OperationHash)
-> (ParameterScope (ToT t) => m OperationHash) -> m OperationHash
forall a b. (a -> b) -> a -> b
$
ImplicitAddress
-> KindedAddress kind
-> Mutez
-> EpName
-> Value (ToT t)
-> Maybe Mutez
-> m OperationHash
forall (m :: * -> *) (t :: T) env (kind :: AddressKind).
(HasTezosRpc m, HasTezosClient m, WithClientLog env m,
ParameterScope t, L1AddressKind kind) =>
ImplicitAddress
-> KindedAddress kind
-> Mutez
-> EpName
-> Value t
-> Maybe Mutez
-> m OperationHash
transfer ImplicitAddress
from KindedAddress kind
to Mutez
amount EpName
epName (t -> Value (ToT t)
forall a. IsoValue a => a -> Value (ToT a)
T.toVal t
param) Maybe Mutez
mbFee