module Morley.Client.Action.Delegation
( setDelegateOp
, registerDelegateOp
) where
import Colog.Core.Class (HasLog)
import Colog.Message (Message)
import Morley.Client.Action.Common
import Morley.Client.Action.Operation
import Morley.Client.RPC.Class
import Morley.Client.RPC.Types
import Morley.Client.TezosClient.Class
import Morley.Client.Types
import Morley.Tezos.Address
import Morley.Tezos.Crypto
setDelegateOp
:: ( HasTezosRpc m
, HasTezosClient m
, MonadReader env m
, HasLog env Message m)
=> ImplicitAddressWithAlias
-> Maybe KeyHash
-> m OperationHash
setDelegateOp :: forall (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, MonadReader env m,
HasLog env Message m) =>
ImplicitAddressWithAlias -> Maybe KeyHash -> m OperationHash
setDelegateOp ImplicitAddressWithAlias
sender Maybe KeyHash
delegate =
((OperationHash, NonEmpty (OperationInfo Result)) -> OperationHash)
-> m (OperationHash, NonEmpty (OperationInfo Result))
-> m OperationHash
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (OperationHash, NonEmpty (OperationInfo Result)) -> OperationHash
forall a b. (a, b) -> a
fst (m (OperationHash, NonEmpty (OperationInfo Result))
-> m OperationHash)
-> (DelegationData
-> m (OperationHash, NonEmpty (OperationInfo Result)))
-> DelegationData
-> m OperationHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ImplicitAddressWithAlias
-> NonEmpty (OperationInfo ClientInput)
-> m (OperationHash, NonEmpty (OperationInfo Result))
forall (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m) =>
ImplicitAddressWithAlias
-> NonEmpty (OperationInfo ClientInput)
-> m (OperationHash, NonEmpty (OperationInfo Result))
runOperationsNonEmpty ImplicitAddressWithAlias
sender (NonEmpty (OperationInfo ClientInput)
-> m (OperationHash, NonEmpty (OperationInfo Result)))
-> (DelegationData -> NonEmpty (OperationInfo ClientInput))
-> DelegationData
-> m (OperationHash, NonEmpty (OperationInfo Result))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OneItem (NonEmpty (OperationInfo ClientInput))
-> NonEmpty (OperationInfo ClientInput)
OperationInfo ClientInput -> NonEmpty (OperationInfo ClientInput)
forall x. One x => OneItem x -> x
one (OperationInfo ClientInput -> NonEmpty (OperationInfo ClientInput))
-> (DelegationData -> OperationInfo ClientInput)
-> DelegationData
-> NonEmpty (OperationInfo ClientInput)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DelegationInfo ClientInput -> OperationInfo ClientInput
DelegationData -> OperationInfo ClientInput
forall i. DelegationInfo i -> OperationInfo i
OpDelegation (DelegationData -> m OperationHash)
-> DelegationData -> m OperationHash
forall a b. (a -> b) -> a -> b
$ Maybe KeyHash -> Maybe Mutez -> DelegationData
DelegationData Maybe KeyHash
delegate Maybe Mutez
forall a. Maybe a
Nothing
registerDelegateOp
:: ( HasTezosRpc m
, HasTezosClient m
, MonadReader env m
, HasLog env Message m)
=> ImplicitAddressWithAlias
-> m OperationHash
registerDelegateOp :: forall (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, MonadReader env m,
HasLog env Message m) =>
ImplicitAddressWithAlias -> m OperationHash
registerDelegateOp ImplicitAddressWithAlias
sender = do
let senderKh :: KeyHash
senderKh = ImplicitAddress -> KeyHash
unImplicitAddress (ImplicitAddress -> KeyHash) -> ImplicitAddress -> KeyHash
forall a b. (a -> b) -> a -> b
$ ImplicitAddressWithAlias -> ImplicitAddress
forall (kind :: AddressKind).
AddressWithAlias kind -> KindedAddress kind
awaAddress ImplicitAddressWithAlias
sender
ImplicitAddressWithAlias -> Maybe KeyHash -> m OperationHash
forall (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, MonadReader env m,
HasLog env Message m) =>
ImplicitAddressWithAlias -> Maybe KeyHash -> m OperationHash
setDelegateOp ImplicitAddressWithAlias
sender (KeyHash -> Maybe KeyHash
forall a. a -> Maybe a
Just KeyHash
senderKh)