module Morley.Client.Action.Operation
( Result
, runOperations
, runOperationsNonEmpty
, dryRunOperationsNonEmpty
) where
import Control.Lens (has, (%=), (&~))
import Data.List (zipWith4)
import Data.List.NonEmpty qualified as NE
import Data.Ratio ((%))
import Data.Singletons (Sing, SingI, demote, sing)
import Data.Text qualified as T
import Fmt (blockListF, blockListF', listF, nameF, pretty, (+|), (|+))
import Morley.Client.Action.Common
import Morley.Client.Logging
import Morley.Client.RPC.Class
import Morley.Client.RPC.Error
import Morley.Client.RPC.Getters
import Morley.Client.RPC.Types
import Morley.Client.TezosClient
import Morley.Client.Types
import Morley.Client.Types.AliasesAndAddresses
import Morley.Client.Util (epNameToTezosEp)
import Morley.Micheline (StringEncode(..), TezosInt64, TezosMutez(..), toExpression)
import Morley.Michelson.Typed (Value)
import Morley.Tezos.Address
import Morley.Tezos.Address.Alias
import Morley.Tezos.Core
import Morley.Tezos.Crypto
import Morley.Util.ByteString
import Morley.Util.Constrained
import Morley.Util.Named
data Result
instance OperationInfoDescriptor Result where
type TransferInfo Result = [WithSource EventOperation]
type TransferTicketInfo Result = [WithSource EventOperation]
type OriginationInfo Result = ContractAddress
type RevealInfo Result = ()
type DelegationInfo Result = ()
logOperations
:: forall env m kind.
( WithClientLog env m
, HasTezosClient m
)
=> AddressWithAlias kind
-> NonEmpty (OperationInfo ClientInput)
-> m ()
logOperations :: forall env (m :: * -> *) (kind :: AddressKind).
(WithClientLog env m, HasTezosClient m) =>
AddressWithAlias kind
-> NonEmpty (OperationInfo ClientInput) -> m ()
logOperations AddressWithAlias kind
sender NonEmpty (OperationInfo ClientInput)
ops = do
let opName :: Doc
opName =
if | (Element (NonEmpty (OperationInfo ClientInput)) -> Bool)
-> NonEmpty (OperationInfo ClientInput) -> Bool
forall c b.
(Container c, BooleanMonoid b) =>
(Element c -> b) -> c -> b
all (Getting Any (OperationInfo ClientInput) (TransferInfo ClientInput)
-> OperationInfo ClientInput -> Bool
forall s a. Getting Any s a -> s -> Bool
has Getting Any (OperationInfo ClientInput) (TransferInfo ClientInput)
forall i (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (TransferInfo i) (f (TransferInfo i))
-> p (OperationInfo i) (f (OperationInfo i))
_OpTransfer) NonEmpty (OperationInfo ClientInput)
ops -> Doc
"transactions"
| (Element (NonEmpty (OperationInfo ClientInput)) -> Bool)
-> NonEmpty (OperationInfo ClientInput) -> Bool
forall c b.
(Container c, BooleanMonoid b) =>
(Element c -> b) -> c -> b
all (Getting
Any (OperationInfo ClientInput) (OriginationInfo ClientInput)
-> OperationInfo ClientInput -> Bool
forall s a. Getting Any s a -> s -> Bool
has Getting
Any (OperationInfo ClientInput) (OriginationInfo ClientInput)
forall i (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (OriginationInfo i) (f (OriginationInfo i))
-> p (OperationInfo i) (f (OperationInfo i))
_OpOriginate) NonEmpty (OperationInfo ClientInput)
ops -> Doc
"originations"
| (Element (NonEmpty (OperationInfo ClientInput)) -> Bool)
-> NonEmpty (OperationInfo ClientInput) -> Bool
forall c b.
(Container c, BooleanMonoid b) =>
(Element c -> b) -> c -> b
all (Getting Any (OperationInfo ClientInput) (RevealInfo ClientInput)
-> OperationInfo ClientInput -> Bool
forall s a. Getting Any s a -> s -> Bool
has Getting Any (OperationInfo ClientInput) (RevealInfo ClientInput)
forall i (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (RevealInfo i) (f (RevealInfo i))
-> p (OperationInfo i) (f (OperationInfo i))
_OpReveal) NonEmpty (OperationInfo ClientInput)
ops -> Doc
"reveals"
| (Element (NonEmpty (OperationInfo ClientInput)) -> Bool)
-> NonEmpty (OperationInfo ClientInput) -> Bool
forall c b.
(Container c, BooleanMonoid b) =>
(Element c -> b) -> c -> b
all (Getting
Any (OperationInfo ClientInput) (TransferTicketInfo ClientInput)
-> OperationInfo ClientInput -> Bool
forall s a. Getting Any s a -> s -> Bool
has Getting
Any (OperationInfo ClientInput) (TransferTicketInfo ClientInput)
forall i (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (TransferTicketInfo i) (f (TransferTicketInfo i))
-> p (OperationInfo i) (f (OperationInfo i))
_OpTransferTicket) NonEmpty (OperationInfo ClientInput)
ops -> Doc
"ticket transfers"
| Bool
otherwise -> Doc
"operations"
buildOp :: (OperationInfo ClientInput, Maybe SomeAlias) -> Doc
buildOp = \case
(OpTransfer TransferInfo ClientInput
tx, Maybe SomeAlias
mbAlias) ->
Maybe SomeAlias -> TransactionData -> Doc
buildTxDataWithAlias Maybe SomeAlias
mbAlias TransferInfo ClientInput
TransactionData
tx
(OpTransferTicket TransferTicketInfo ClientInput
tx, Maybe SomeAlias
mbAlias) ->
Maybe SomeAlias -> TransferTicketData -> Doc
buildTxTicketDataWithAlias Maybe SomeAlias
mbAlias TransferTicketInfo ClientInput
TransferTicketData
tx
(OpOriginate OriginationInfo ClientInput
orig, Maybe SomeAlias
_) ->
OriginationData -> ContractAlias
odName OriginationInfo ClientInput
OriginationData
orig ContractAlias -> Doc -> Doc
forall a b. (Buildable a, FromDoc b) => a -> Doc -> b
|+ Doc
" (temporary alias)"
(OpReveal RevealInfo ClientInput
rv, Maybe SomeAlias
mbAlias) ->
Doc
"Key " Doc -> Doc -> Doc
forall b. FromDoc b => Doc -> Doc -> b
+| RevealData -> PublicKey
rdPublicKey RevealInfo ClientInput
RevealData
rv PublicKey -> Doc -> Doc
forall a b. (Buildable a, FromDoc b) => a -> Doc -> b
|+ Doc -> (SomeAlias -> Doc) -> Maybe SomeAlias -> Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
"" (\SomeAlias
a -> Doc
" (" Doc -> Doc -> Doc
forall b. FromDoc b => Doc -> Doc -> b
+| SomeAlias
a SomeAlias -> Doc -> Doc
forall a b. (Buildable a, FromDoc b) => a -> Doc -> b
|+ Doc
")") Maybe SomeAlias
mbAlias
(OpDelegation DelegationInfo ClientInput
delegate, Maybe SomeAlias
mbAlias) ->
Doc
"Key Hash " Doc -> Doc -> Doc
forall b. FromDoc b => Doc -> Doc -> b
+| DelegationData -> Maybe KeyHash
ddDelegate DelegationInfo ClientInput
DelegationData
delegate Maybe KeyHash -> Doc -> Doc
forall a b. (Buildable a, FromDoc b) => a -> Doc -> b
|+ Doc -> (SomeAlias -> Doc) -> Maybe SomeAlias -> Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
"" (\SomeAlias
a -> Doc
" (" Doc -> Doc -> Doc
forall b. FromDoc b => Doc -> Doc -> b
+| SomeAlias
a SomeAlias -> Doc -> Doc
forall a b. (Buildable a, FromDoc b) => a -> Doc -> b
|+ Doc
")") Maybe SomeAlias
mbAlias
let needsAliasStore :: Bool
needsAliasStore = ((Element (NonEmpty (OperationInfo ClientInput)) -> Bool)
-> NonEmpty (OperationInfo ClientInput) -> Bool
forall c b.
(Container c, BooleanMonoid b) =>
(Element c -> b) -> c -> b
`any` NonEmpty (OperationInfo ClientInput)
ops) \case
OpTransfer{} -> Bool
True
OpTransferTicket{} -> Bool
True
OpOriginate{} -> Bool
False
OpReveal{} -> Bool
True
OpDelegation{} -> Bool
True
AliasesAndAddresses
anas <- if Bool
needsAliasStore
then m AliasesAndAddresses
forall (m :: * -> *). HasTezosClient m => m AliasesAndAddresses
getAliasesAndAddresses
else AliasesAndAddresses -> m AliasesAndAddresses
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AliasesAndAddresses
emptyAliasesAndAddresses
let mbAlias :: KindedAddress k -> Maybe SomeAlias
mbAlias :: forall (k :: AddressKind). KindedAddress k -> Maybe SomeAlias
mbAlias = (Alias k -> SomeAlias) -> Maybe (Alias k) -> Maybe SomeAlias
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Alias k -> SomeAlias
forall {k} (c :: k -> Constraint) (f :: k -> *) (a :: k).
c a =>
f a -> Constrained c f
Constrained (Maybe (Alias k) -> Maybe SomeAlias)
-> (KindedAddress k -> Maybe (Alias k))
-> KindedAddress k
-> Maybe SomeAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (KindedAddress k -> AliasesAndAddresses -> Maybe (Alias k))
-> AliasesAndAddresses -> KindedAddress k -> Maybe (Alias k)
forall a b c. (a -> b -> c) -> b -> a -> c
flip KindedAddress k -> AliasesAndAddresses -> Maybe (Alias k)
forall (kind :: AddressKind).
KindedAddress kind -> AliasesAndAddresses -> Maybe (Alias kind)
lookupAlias AliasesAndAddresses
anas
let aliases :: NonEmpty (Maybe SomeAlias)
aliases = NonEmpty (OperationInfo ClientInput)
ops NonEmpty (OperationInfo ClientInput)
-> (OperationInfo ClientInput -> Maybe SomeAlias)
-> NonEmpty (Maybe SomeAlias)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
OpTransfer (TransactionData TD (Value t)
tx) -> Constrained
(ConstrainAddressKind
'[ 'AddressKindImplicit, 'AddressKindContract])
KindedAddress
-> (forall (t :: AddressKind).
ConstrainAddressKind
'[ 'AddressKindImplicit, 'AddressKindContract] t =>
KindedAddress t -> Maybe SomeAlias)
-> Maybe SomeAlias
forall {k} (c :: k -> Constraint) (f :: k -> *) r.
Constrained c f -> (forall (t :: k). c t => f t -> r) -> r
withConstrained (TD (Value t)
-> Constrained
(ConstrainAddressKind
'[ 'AddressKindImplicit, 'AddressKindContract])
KindedAddress
forall t.
TD t
-> Constrained
(ConstrainAddressKind
'[ 'AddressKindImplicit, 'AddressKindContract])
KindedAddress
tdReceiver TD (Value t)
tx) KindedAddress t -> Maybe SomeAlias
forall (t :: AddressKind).
ConstrainAddressKind
'[ 'AddressKindImplicit, 'AddressKindContract] t =>
KindedAddress t -> Maybe SomeAlias
forall (k :: AddressKind). KindedAddress k -> Maybe SomeAlias
mbAlias
OpTransferTicket TransferTicketData{Natural
Maybe Mutez
EpName
Address
Value t
ttdTicketContents :: Value t
ttdTicketTicketer :: Address
ttdTicketAmount :: Natural
ttdDestination :: Address
ttdEntrypoint :: EpName
ttdMbFee :: Maybe Mutez
ttdTicketContents :: ()
ttdTicketTicketer :: TransferTicketData -> Address
ttdTicketAmount :: TransferTicketData -> Natural
ttdDestination :: TransferTicketData -> Address
ttdEntrypoint :: TransferTicketData -> EpName
ttdMbFee :: TransferTicketData -> Maybe Mutez
..} -> Address
-> (forall (t :: AddressKind).
NullConstraint t =>
KindedAddress t -> Maybe SomeAlias)
-> Maybe SomeAlias
forall {k} (c :: k -> Constraint) (f :: k -> *) r.
Constrained c f -> (forall (t :: k). c t => f t -> r) -> r
withConstrained Address
ttdDestination KindedAddress t -> Maybe SomeAlias
forall (k :: AddressKind). KindedAddress k -> Maybe SomeAlias
forall (t :: AddressKind).
NullConstraint t =>
KindedAddress t -> Maybe SomeAlias
mbAlias
OpOriginate OriginationInfo ClientInput
_ -> Maybe SomeAlias
forall a. Maybe a
Nothing
OpReveal RevealInfo ClientInput
r -> KindedAddress 'AddressKindImplicit -> Maybe SomeAlias
forall (k :: AddressKind). KindedAddress k -> Maybe SomeAlias
mbAlias (KindedAddress 'AddressKindImplicit -> Maybe SomeAlias)
-> (PublicKey -> KindedAddress 'AddressKindImplicit)
-> PublicKey
-> Maybe SomeAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PublicKey -> KindedAddress 'AddressKindImplicit
mkKeyAddress (PublicKey -> Maybe SomeAlias) -> PublicKey -> Maybe SomeAlias
forall a b. (a -> b) -> a -> b
$ RevealData -> PublicKey
rdPublicKey RevealInfo ClientInput
RevealData
r
OpDelegation DelegationInfo ClientInput
d -> KindedAddress 'AddressKindImplicit -> Maybe SomeAlias
forall (k :: AddressKind). KindedAddress k -> Maybe SomeAlias
mbAlias (KindedAddress 'AddressKindImplicit -> Maybe SomeAlias)
-> (KeyHash -> KindedAddress 'AddressKindImplicit)
-> KeyHash
-> Maybe SomeAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KeyHash -> KindedAddress 'AddressKindImplicit
ImplicitAddress (KeyHash -> Maybe SomeAlias) -> Maybe KeyHash -> Maybe SomeAlias
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< DelegationData -> Maybe KeyHash
ddDelegate DelegationInfo ClientInput
DelegationData
d
Text -> m ()
forall env (m :: * -> *). WithLog env Message m => Text -> m ()
logInfo (Text -> m ()) -> Text -> m ()
forall a b. (a -> b) -> a -> b
$ Text -> Text
T.strip (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$
Doc
"Running " Doc -> Doc -> Text
forall b. FromDoc b => Doc -> Doc -> b
+| Doc
opName Doc -> Doc -> Doc
forall b. FromDoc b => Doc -> Doc -> b
+| Doc
" by " Doc -> Doc -> Doc
forall b. FromDoc b => Doc -> Doc -> b
+| AddressWithAlias kind
sender AddressWithAlias kind -> Doc -> Doc
forall a b. (Buildable a, FromDoc b) => a -> Doc -> b
|+ Doc
":\n" Doc -> Doc -> Doc
forall b. FromDoc b => Doc -> Doc -> b
+|
Doc
-> ((OperationInfo ClientInput, Maybe SomeAlias) -> Doc)
-> NonEmpty (OperationInfo ClientInput, Maybe SomeAlias)
-> Doc
forall (f :: * -> *) a.
Foldable f =>
Doc -> (a -> Doc) -> f a -> Doc
blockListF' Doc
"-" (OperationInfo ClientInput, Maybe SomeAlias) -> Doc
buildOp (NonEmpty (OperationInfo ClientInput)
ops NonEmpty (OperationInfo ClientInput)
-> NonEmpty (Maybe SomeAlias)
-> NonEmpty (OperationInfo ClientInput, Maybe SomeAlias)
forall a b. NonEmpty a -> NonEmpty b -> NonEmpty (a, b)
`NE.zip` NonEmpty (Maybe SomeAlias)
aliases)
runOperations
:: forall m env.
( HasTezosRpc m
, HasTezosClient m
, WithClientLog env m
)
=> ImplicitAddressWithAlias
-> [OperationInfo ClientInput]
-> m (Maybe OperationHash, [OperationInfo Result])
runOperations :: forall (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m) =>
ImplicitAddressWithAlias
-> [OperationInfo ClientInput]
-> m (Maybe OperationHash, [OperationInfo Result])
runOperations ImplicitAddressWithAlias
sender [OperationInfo ClientInput]
operations = case [OperationInfo ClientInput]
operations of
[] -> (Maybe OperationHash, [OperationInfo Result])
-> m (Maybe OperationHash, [OperationInfo Result])
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe OperationHash
forall a. Maybe a
Nothing, [])
OperationInfo ClientInput
op : [OperationInfo ClientInput]
ops -> do
(OperationHash
opHash, NonEmpty (OperationInfo Result)
res) <- 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)))
-> NonEmpty (OperationInfo ClientInput)
-> m (OperationHash, NonEmpty (OperationInfo Result))
forall a b. (a -> b) -> a -> b
$ OperationInfo ClientInput
op OperationInfo ClientInput
-> [OperationInfo ClientInput]
-> NonEmpty (OperationInfo ClientInput)
forall a. a -> [a] -> NonEmpty a
:| [OperationInfo ClientInput]
ops
(Maybe OperationHash, [OperationInfo Result])
-> m (Maybe OperationHash, [OperationInfo Result])
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Maybe OperationHash, [OperationInfo Result])
-> m (Maybe OperationHash, [OperationInfo Result]))
-> (Maybe OperationHash, [OperationInfo Result])
-> m (Maybe OperationHash, [OperationInfo Result])
forall a b. (a -> b) -> a -> b
$ (OperationHash -> Maybe OperationHash
forall a. a -> Maybe a
Just OperationHash
opHash, NonEmpty (OperationInfo Result)
-> [Element (NonEmpty (OperationInfo Result))]
forall t. Container t => t -> [Element t]
toList NonEmpty (OperationInfo Result)
res)
injectionRetryCount :: Natural
injectionRetryCount :: Natural
injectionRetryCount = Natural
2
runOperationsNonEmpty
:: forall m env.
( HasTezosRpc m
, HasTezosClient m
, WithClientLog env m
)
=> ImplicitAddressWithAlias
-> NonEmpty (OperationInfo ClientInput)
-> m (OperationHash, NonEmpty (OperationInfo Result))
runOperationsNonEmpty :: 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)
operations =
forall (runMode :: RunMode) (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m,
SingI runMode) =>
Natural
-> ImplicitAddressWithAlias
-> NonEmpty (OperationInfo ClientInput)
-> m (RunResult runMode)
runOperationsNonEmptyHelper @'RealRun Natural
injectionRetryCount ImplicitAddressWithAlias
sender NonEmpty (OperationInfo ClientInput)
operations
data RunMode = DryRun | RealRun
isRealRun :: forall (runMode :: RunMode). (SingI runMode) => Bool
isRealRun :: forall (runMode :: RunMode). SingI runMode => Bool
isRealRun = case forall {k} (a :: k). SingI a => Sing a
forall (a :: RunMode). SingI a => Sing a
sing @runMode of
Sing runMode
SingRunResult runMode
SRealRun -> Bool
True
Sing runMode
SingRunResult runMode
SDryRun -> Bool
False
type family RunResult (a :: RunMode) where
RunResult 'DryRun = NonEmpty (AppliedResult, TezosMutez)
RunResult 'RealRun = (OperationHash, NonEmpty (OperationInfo Result))
data SingRunResult :: RunMode -> Type where
SDryRun :: SingRunResult 'DryRun
SRealRun :: SingRunResult 'RealRun
type instance Sing = SingRunResult
instance SingI 'DryRun where
sing :: Sing 'DryRun
sing = Sing 'DryRun
SingRunResult 'DryRun
SDryRun
instance SingI 'RealRun where
sing :: Sing 'RealRun
sing = Sing 'RealRun
SingRunResult 'RealRun
SRealRun
dryRunOperationsNonEmpty
:: forall m env.
( HasTezosRpc m
, HasTezosClient m
, WithClientLog env m
)
=> ImplicitAddressWithAlias
-> NonEmpty (OperationInfo ClientInput)
-> m (NonEmpty (AppliedResult, TezosMutez))
dryRunOperationsNonEmpty :: forall (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m) =>
ImplicitAddressWithAlias
-> NonEmpty (OperationInfo ClientInput)
-> m (NonEmpty (AppliedResult, TezosMutez))
dryRunOperationsNonEmpty ImplicitAddressWithAlias
sender NonEmpty (OperationInfo ClientInput)
operations =
forall (runMode :: RunMode) (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m,
SingI runMode) =>
Natural
-> ImplicitAddressWithAlias
-> NonEmpty (OperationInfo ClientInput)
-> m (RunResult runMode)
runOperationsNonEmptyHelper @'DryRun Natural
0 ImplicitAddressWithAlias
sender NonEmpty (OperationInfo ClientInput)
operations
runOperationsNonEmptyHelper
:: forall (runMode :: RunMode) m env.
( HasTezosRpc m
, HasTezosClient m
, WithClientLog env m
, SingI runMode
)
=> Natural
-> ImplicitAddressWithAlias
-> NonEmpty (OperationInfo ClientInput)
-> m (RunResult runMode)
runOperationsNonEmptyHelper :: forall (runMode :: RunMode) (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m,
SingI runMode) =>
Natural
-> ImplicitAddressWithAlias
-> NonEmpty (OperationInfo ClientInput)
-> m (RunResult runMode)
runOperationsNonEmptyHelper Natural
retryCount sender :: ImplicitAddressWithAlias
sender@(AddressWithAlias KindedAddress 'AddressKindImplicit
senderAddress Alias 'AddressKindImplicit
_) NonEmpty (OperationInfo ClientInput)
operations' = do
NonEmpty (OperationInfo ClientInput)
operations <- NonEmpty (OperationInfo ClientInput)
-> Maybe (NonEmpty (OperationInfo ClientInput))
-> NonEmpty (OperationInfo ClientInput)
forall a. a -> Maybe a -> a
fromMaybe NonEmpty (OperationInfo ClientInput)
operations' (Maybe (NonEmpty (OperationInfo ClientInput))
-> NonEmpty (OperationInfo ClientInput))
-> m (Maybe (NonEmpty (OperationInfo ClientInput)))
-> m (NonEmpty (OperationInfo ClientInput))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MaybeT m (NonEmpty (OperationInfo ClientInput))
-> m (Maybe (NonEmpty (OperationInfo ClientInput)))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
Bool -> MaybeT m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> MaybeT m ()) -> Bool -> MaybeT m ()
forall a b. (a -> b) -> a -> b
$ forall (runMode :: RunMode). SingI runMode => Bool
isRealRun @runMode Bool -> Bool -> Bool
forall a. Boolean a => a -> a -> a
&& [OperationInfo ClientInput] -> Bool
forall i. [OperationInfo i] -> Bool
mayNeedSenderRevealing (NonEmpty (OperationInfo ClientInput)
-> [Element (NonEmpty (OperationInfo ClientInput))]
forall t. Container t => t -> [Element t]
toList NonEmpty (OperationInfo ClientInput)
operations')
Maybe PublicKey
Nothing <- m (Maybe PublicKey) -> MaybeT m (Maybe PublicKey)
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Maybe PublicKey) -> MaybeT m (Maybe PublicKey))
-> m (Maybe PublicKey) -> MaybeT m (Maybe PublicKey)
forall a b. (a -> b) -> a -> b
$ KindedAddress 'AddressKindImplicit -> m (Maybe PublicKey)
forall (m :: * -> *).
HasTezosRpc m =>
KindedAddress 'AddressKindImplicit -> m (Maybe PublicKey)
getManagerKey KindedAddress 'AddressKindImplicit
senderAddress
PublicKey
pk <- m PublicKey -> MaybeT m PublicKey
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m PublicKey -> MaybeT m PublicKey)
-> m PublicKey -> MaybeT m PublicKey
forall a b. (a -> b) -> a -> b
$ ImplicitAddressWithAlias -> m PublicKey
forall (m :: * -> *).
HasTezosClient m =>
ImplicitAddressWithAlias -> m PublicKey
getPublicKey ImplicitAddressWithAlias
sender
pure $ RevealInfo ClientInput -> OperationInfo ClientInput
forall i. RevealInfo i -> OperationInfo i
OpReveal (PublicKey -> Maybe Mutez -> RevealData
RevealData PublicKey
pk Maybe Mutez
forall a. Maybe a
Nothing) OperationInfo ClientInput
-> [OperationInfo ClientInput]
-> NonEmpty (OperationInfo ClientInput)
forall a. a -> [a] -> NonEmpty a
:| NonEmpty (OperationInfo ClientInput)
-> [Element (NonEmpty (OperationInfo ClientInput))]
forall t. Container t => t -> [Element t]
toList NonEmpty (OperationInfo ClientInput)
operations'
ImplicitAddressWithAlias
-> NonEmpty (OperationInfo ClientInput) -> m ()
forall env (m :: * -> *) (kind :: AddressKind).
(WithClientLog env m, HasTezosClient m) =>
AddressWithAlias kind
-> NonEmpty (OperationInfo ClientInput) -> m ()
logOperations ImplicitAddressWithAlias
sender NonEmpty (OperationInfo ClientInput)
operations
NonEmpty (OperationInfo ClientInput)
-> (Element (NonEmpty (OperationInfo ClientInput)) -> m ()) -> m ()
forall t (m :: * -> *) b.
(Container t, Monad m) =>
t -> (Element t -> m b) -> m ()
forM_ NonEmpty (OperationInfo ClientInput)
operations ((Element (NonEmpty (OperationInfo ClientInput)) -> m ()) -> m ())
-> (Element (NonEmpty (OperationInfo ClientInput)) -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \case
OpOriginate OriginationData{odAliasBehavior :: OriginationData -> AliasBehavior
odAliasBehavior = AliasBehavior
ForbidDuplicateAlias, Maybe Mutez
Maybe KeyHash
Mutez
ContractAlias
Value st
Contract cp st
odName :: OriginationData -> ContractAlias
odName :: ContractAlias
odBalance :: Mutez
odContract :: Contract cp st
odStorage :: Value st
odDelegate :: Maybe KeyHash
odMbFee :: Maybe Mutez
odBalance :: OriginationData -> Mutez
odContract :: ()
odStorage :: ()
odDelegate :: OriginationData -> Maybe KeyHash
odMbFee :: OriginationData -> Maybe Mutez
..} -> do
Maybe (KindedAddress 'AddressKindContract)
resolved <- ContractAlias -> m (Maybe (ResolvedAddress ContractAlias))
forall addressOrAlias (m :: * -> *).
(HasTezosClient m, MonadThrow m, Resolve addressOrAlias) =>
addressOrAlias -> m (Maybe (ResolvedAddress addressOrAlias))
resolveAddressMaybe ContractAlias
odName
Maybe (KindedAddress 'AddressKindContract)
-> (KindedAddress 'AddressKindContract -> m ()) -> m ()
forall (f :: * -> *) a.
Applicative f =>
Maybe a -> (a -> f ()) -> f ()
whenJust Maybe (KindedAddress 'AddressKindContract)
resolved ((KindedAddress 'AddressKindContract -> m ()) -> m ())
-> (KindedAddress 'AddressKindContract -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ m () -> KindedAddress 'AddressKindContract -> m ()
forall a b. a -> b -> a
const (m () -> KindedAddress 'AddressKindContract -> m ())
-> m () -> KindedAddress 'AddressKindContract -> m ()
forall a b. (a -> b) -> a -> b
$ TezosClientError -> m ()
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (TezosClientError -> m ()) -> TezosClientError -> m ()
forall a b. (a -> b) -> a -> b
$ Text -> TezosClientError
DuplicateAlias (ContractAlias -> Text
forall (kind :: AddressKind). Alias kind -> Text
unAlias ContractAlias
odName)
Element (NonEmpty (OperationInfo ClientInput))
_ -> m ()
forall (f :: * -> *). Applicative f => f ()
pass
Maybe ScrubbedBytes
mbPassword <- ImplicitAddressWithAlias -> m (Maybe ScrubbedBytes)
forall (m :: * -> *).
HasTezosClient m =>
ImplicitAddressWithAlias -> m (Maybe ScrubbedBytes)
getKeyPassword ImplicitAddressWithAlias
sender
ProtocolParameters
pp <- m ProtocolParameters
forall (m :: * -> *). HasTezosRpc m => m ProtocolParameters
getProtocolParameters
OperationConstants{StringEncode Int64
FeeConstants
BlockHash
BlockConstants
ocLastBlockHash :: BlockHash
ocBlockConstants :: BlockConstants
ocFeeConstants :: FeeConstants
ocCounter :: StringEncode Int64
ocLastBlockHash :: OperationConstants -> BlockHash
ocBlockConstants :: OperationConstants -> BlockConstants
ocFeeConstants :: OperationConstants -> FeeConstants
ocCounter :: OperationConstants -> StringEncode Int64
..} <- KindedAddress 'AddressKindImplicit -> m OperationConstants
forall (m :: * -> *).
HasTezosRpc m =>
KindedAddress 'AddressKindImplicit -> m OperationConstants
preProcessOperation KindedAddress 'AddressKindImplicit
senderAddress
let convertOps :: StringEncode Int64
-> OperationInfo ClientInput
-> WithCommonOperationData (OperationInfo RPCInput)
convertOps StringEncode Int64
i = CommonOperationData
-> OperationInfo RPCInput
-> WithCommonOperationData (OperationInfo RPCInput)
forall a. CommonOperationData -> a -> WithCommonOperationData a
WithCommonOperationData CommonOperationData
commonData (OperationInfo RPCInput
-> WithCommonOperationData (OperationInfo RPCInput))
-> (OperationInfo ClientInput -> OperationInfo RPCInput)
-> OperationInfo ClientInput
-> WithCommonOperationData (OperationInfo RPCInput)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
OpTransfer (TransactionData TD {tdReceiver :: forall t.
TD t
-> Constrained
(ConstrainAddressKind
'[ 'AddressKindImplicit, 'AddressKindContract])
KindedAddress
tdReceiver=Constrained KindedAddress a
tdReceiver, Maybe Mutez
EpName
Mutez
Value t
tdAmount :: Mutez
tdEpName :: EpName
tdParam :: Value t
tdMbFee :: Maybe Mutez
tdAmount :: forall t. TD t -> Mutez
tdEpName :: forall t. TD t -> EpName
tdParam :: forall t. TD t -> t
tdMbFee :: forall t. TD t -> Maybe Mutez
..}) ->
TransferInfo RPCInput -> OperationInfo RPCInput
forall i. TransferInfo i -> OperationInfo i
OpTransfer TransactionOperation
{ toDestination :: Address
toDestination = KindedAddress a -> Address
forall (kind :: AddressKind). KindedAddress kind -> Address
MkAddress KindedAddress a
tdReceiver
, toAmount :: TezosMutez
toAmount = Mutez -> TezosMutez
TezosMutez Mutez
tdAmount
, toParameters :: ParametersInternal
toParameters = EpName -> Value t -> ParametersInternal
forall (t :: T).
ParameterScope t =>
EpName -> Value t -> ParametersInternal
toParametersInternals EpName
tdEpName Value t
tdParam
}
OpTransferTicket (TransferTicketData {Natural
Maybe Mutez
EpName
Address
Value t
ttdTicketContents :: ()
ttdTicketTicketer :: TransferTicketData -> Address
ttdTicketAmount :: TransferTicketData -> Natural
ttdDestination :: TransferTicketData -> Address
ttdEntrypoint :: TransferTicketData -> EpName
ttdMbFee :: TransferTicketData -> Maybe Mutez
ttdTicketContents :: Value t
ttdTicketTicketer :: Address
ttdTicketAmount :: Natural
ttdDestination :: Address
ttdEntrypoint :: EpName
ttdMbFee :: Maybe Mutez
..})
| Value t
_ :: Value t <- Value t
ttdTicketContents ->
TransferTicketInfo RPCInput -> OperationInfo RPCInput
forall i. TransferTicketInfo i -> OperationInfo i
OpTransferTicket TransferTicketOperation
{ ttoTicketContents :: Expression
ttoTicketContents = Value t -> Expression
forall a. ToExpression a => a -> Expression
toExpression Value t
ttdTicketContents
, ttoTicketTy :: Expression
ttoTicketTy = T -> Expression
forall a. ToExpression a => a -> Expression
toExpression (forall {k} (a :: k). (SingKind k, SingI a) => Demote k
forall (a :: T). (SingKind T, SingI a) => Demote T
demote @t)
, ttoTicketTicketer :: Address
ttoTicketTicketer = Address
ttdTicketTicketer
, ttoTicketAmount :: TezosNat
ttoTicketAmount = Natural -> TezosNat
forall a. a -> StringEncode a
StringEncode Natural
ttdTicketAmount
, ttoDestination :: Address
ttoDestination = Address
ttdDestination
, ttoEntrypoint :: Text
ttoEntrypoint = EpName -> Text
epNameToTezosEp EpName
ttdEntrypoint
}
OpOriginate OriginationData{Maybe Mutez
Maybe KeyHash
Mutez
ContractAlias
Value st
Contract cp st
AliasBehavior
odName :: OriginationData -> ContractAlias
odAliasBehavior :: OriginationData -> AliasBehavior
odBalance :: OriginationData -> Mutez
odContract :: ()
odStorage :: ()
odDelegate :: OriginationData -> Maybe KeyHash
odMbFee :: OriginationData -> Maybe Mutez
odAliasBehavior :: AliasBehavior
odName :: ContractAlias
odBalance :: Mutez
odContract :: Contract cp st
odStorage :: Value st
odDelegate :: Maybe KeyHash
odMbFee :: Maybe Mutez
..} ->
OriginationInfo RPCInput -> OperationInfo RPCInput
forall i. OriginationInfo i -> OperationInfo i
OpOriginate OriginationOperation
{ ooBalance :: TezosMutez
ooBalance = Mutez -> TezosMutez
TezosMutez Mutez
odBalance
, ooDelegate :: Maybe KeyHash
ooDelegate = Maybe KeyHash
odDelegate
, ooScript :: OriginationScript
ooScript = Contract cp st -> Value st -> OriginationScript
forall (cp :: T) (st :: T).
Contract cp st -> Value st -> OriginationScript
mkOriginationScript Contract cp st
odContract Value st
odStorage
}
OpReveal RevealData{Maybe Mutez
PublicKey
rdPublicKey :: RevealData -> PublicKey
rdPublicKey :: PublicKey
rdMbFee :: Maybe Mutez
rdMbFee :: RevealData -> Maybe Mutez
..} ->
RevealInfo RPCInput -> OperationInfo RPCInput
forall i. RevealInfo i -> OperationInfo i
OpReveal RevealOperation
{ roPublicKey :: PublicKey
roPublicKey = PublicKey
rdPublicKey
}
OpDelegation DelegationData{Maybe Mutez
Maybe KeyHash
ddDelegate :: DelegationData -> Maybe KeyHash
ddDelegate :: Maybe KeyHash
ddMbFee :: Maybe Mutez
ddMbFee :: DelegationData -> Maybe Mutez
..} ->
DelegationInfo RPCInput -> OperationInfo RPCInput
forall i. DelegationInfo i -> OperationInfo i
OpDelegation DelegationOperation
{ doDelegate :: Maybe KeyHash
doDelegate = Maybe KeyHash
ddDelegate
}
where
commonData :: CommonOperationData
commonData = ProtocolParameters
-> NamedF Identity (KindedAddress 'AddressKindImplicit) "sender"
-> NamedF Identity (StringEncode Int64) "counter"
-> NamedF Maybe Int64 "num_operations"
-> CommonOperationData
mkCommonOperationData ProtocolParameters
pp
(NamedF Identity (KindedAddress 'AddressKindImplicit) "sender"
-> NamedF Identity (StringEncode Int64) "counter"
-> NamedF Maybe Int64 "num_operations"
-> CommonOperationData)
-> Param
(NamedF Identity (KindedAddress 'AddressKindImplicit) "sender")
-> NamedF Identity (StringEncode Int64) "counter"
-> NamedF Maybe Int64 "num_operations"
-> CommonOperationData
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! KindedAddress 'AddressKindImplicit
-> Param
(NamedF Identity (KindedAddress 'AddressKindImplicit) "sender")
forall (x :: Symbol) a. IsLabel x a => a
#sender KindedAddress 'AddressKindImplicit
senderAddress
(NamedF Identity (StringEncode Int64) "counter"
-> NamedF Maybe Int64 "num_operations" -> CommonOperationData)
-> Param (NamedF Identity (StringEncode Int64) "counter")
-> NamedF Maybe Int64 "num_operations"
-> CommonOperationData
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! StringEncode Int64
-> Param (NamedF Identity (StringEncode Int64) "counter")
forall (x :: Symbol) a. IsLabel x a => a
#counter (StringEncode Int64
ocCounter StringEncode Int64 -> StringEncode Int64 -> StringEncode Int64
forall a. Num a => a -> a -> a
+ StringEncode Int64
i)
(NamedF Maybe Int64 "num_operations" -> CommonOperationData)
-> Param (NamedF Maybe Int64 "num_operations")
-> CommonOperationData
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! Int64 -> Param (NamedF Maybe Int64 "num_operations")
forall (x :: Symbol) a. IsLabel x a => a
#num_operations (forall i a.
(Integral i, Container a,
DefaultToInt (IsIntSubType Length i) i) =>
a -> i
length @Int64 NonEmpty (OperationInfo ClientInput)
operations)
let opsToRun :: NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
opsToRun = (StringEncode Int64
-> OperationInfo ClientInput
-> WithCommonOperationData (OperationInfo RPCInput))
-> NonEmpty (StringEncode Int64)
-> NonEmpty (OperationInfo ClientInput)
-> NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
forall a b c.
(a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c
NE.zipWith StringEncode Int64
-> OperationInfo ClientInput
-> WithCommonOperationData (OperationInfo RPCInput)
convertOps (StringEncode Int64
1 StringEncode Int64
-> [StringEncode Int64] -> NonEmpty (StringEncode Int64)
forall a. a -> [a] -> NonEmpty a
:| [(StringEncode Int64
2 :: TezosInt64)..]) NonEmpty (OperationInfo ClientInput)
operations
mbFees :: NonEmpty (Maybe Mutez)
mbFees = NonEmpty (OperationInfo ClientInput)
operations NonEmpty (OperationInfo ClientInput)
-> (OperationInfo ClientInput -> Maybe Mutez)
-> NonEmpty (Maybe Mutez)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
OpTransfer (TransactionData TD {Maybe Mutez
EpName
Mutez
Constrained
(ConstrainAddressKind
'[ 'AddressKindImplicit, 'AddressKindContract])
KindedAddress
Value t
tdReceiver :: forall t.
TD t
-> Constrained
(ConstrainAddressKind
'[ 'AddressKindImplicit, 'AddressKindContract])
KindedAddress
tdAmount :: forall t. TD t -> Mutez
tdEpName :: forall t. TD t -> EpName
tdParam :: forall t. TD t -> t
tdMbFee :: forall t. TD t -> Maybe Mutez
tdReceiver :: Constrained
(ConstrainAddressKind
'[ 'AddressKindImplicit, 'AddressKindContract])
KindedAddress
tdAmount :: Mutez
tdEpName :: EpName
tdParam :: Value t
tdMbFee :: Maybe Mutez
..}) -> Maybe Mutez
tdMbFee
OpTransferTicket TransferTicketData{Natural
Maybe Mutez
EpName
Address
Value t
ttdTicketContents :: ()
ttdTicketTicketer :: TransferTicketData -> Address
ttdTicketAmount :: TransferTicketData -> Natural
ttdDestination :: TransferTicketData -> Address
ttdEntrypoint :: TransferTicketData -> EpName
ttdMbFee :: TransferTicketData -> Maybe Mutez
ttdTicketContents :: Value t
ttdTicketTicketer :: Address
ttdTicketAmount :: Natural
ttdDestination :: Address
ttdEntrypoint :: EpName
ttdMbFee :: Maybe Mutez
..} -> Maybe Mutez
ttdMbFee
OpOriginate OriginationData{Maybe Mutez
Maybe KeyHash
Mutez
ContractAlias
Value st
Contract cp st
AliasBehavior
odName :: OriginationData -> ContractAlias
odAliasBehavior :: OriginationData -> AliasBehavior
odBalance :: OriginationData -> Mutez
odContract :: ()
odStorage :: ()
odDelegate :: OriginationData -> Maybe KeyHash
odMbFee :: OriginationData -> Maybe Mutez
odAliasBehavior :: AliasBehavior
odName :: ContractAlias
odBalance :: Mutez
odContract :: Contract cp st
odStorage :: Value st
odDelegate :: Maybe KeyHash
odMbFee :: Maybe Mutez
..} -> Maybe Mutez
odMbFee
OpReveal RevealData{Maybe Mutez
PublicKey
rdPublicKey :: RevealData -> PublicKey
rdMbFee :: RevealData -> Maybe Mutez
rdPublicKey :: PublicKey
rdMbFee :: Maybe Mutez
..} -> Maybe Mutez
rdMbFee
OpDelegation DelegationData {Maybe Mutez
Maybe KeyHash
ddDelegate :: DelegationData -> Maybe KeyHash
ddMbFee :: DelegationData -> Maybe Mutez
ddDelegate :: Maybe KeyHash
ddMbFee :: Maybe Mutez
..} -> Maybe Mutez
ddMbFee
let runOp :: RunOperation
runOp = RunOperation
{ roOperation :: RunOperationInternal
roOperation = RunOperationInternal
{ roiBranch :: BlockHash
roiBranch = BlockHash
ocLastBlockHash
, roiContents :: NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
roiContents = NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
opsToRun
, roiSignature :: Signature
roiSignature = Signature
stubSignature
}
, roChainId :: Text
roChainId = BlockConstants -> Text
bcChainId BlockConstants
ocBlockConstants
}
(NonEmpty AppliedResult
results, [OperationResp WithSource]
_) <- Either RunOperation PreApplyOperation
-> m (NonEmpty AppliedResult, [OperationResp WithSource])
forall (m :: * -> *).
HasTezosRpc m =>
Either RunOperation PreApplyOperation
-> m (NonEmpty AppliedResult, [OperationResp WithSource])
getAppliedResults (RunOperation -> Either RunOperation PreApplyOperation
forall a b. a -> Either a b
Left RunOperation
runOp)
let
forgeOp :: NonEmpty OperationInput -> m ByteString
forgeOp :: NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
-> m ByteString
forgeOp NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
ops =
(HexJSONByteString -> ByteString)
-> m HexJSONByteString -> m ByteString
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap HexJSONByteString -> ByteString
unHexJSONByteString (m HexJSONByteString -> m ByteString)
-> (ForgeOperation -> m HexJSONByteString)
-> ForgeOperation
-> m ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForgeOperation -> m HexJSONByteString
forall (m :: * -> *).
HasTezosRpc m =>
ForgeOperation -> m HexJSONByteString
forgeOperation (ForgeOperation -> m ByteString) -> ForgeOperation -> m ByteString
forall a b. (a -> b) -> a -> b
$ ForgeOperation
{ foBranch :: BlockHash
foBranch = BlockHash
ocLastBlockHash
, foContents :: NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
foContents = NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
ops
}
let
signForgedOp :: ByteString -> m (Signature, ByteString)
signForgedOp :: ByteString -> m (Signature, ByteString)
signForgedOp ByteString
op = do
Signature
signature' <- ImplicitAddressWithAlias
-> Maybe ScrubbedBytes -> ByteString -> m Signature
forall (m :: * -> *).
HasTezosClient m =>
ImplicitAddressWithAlias
-> Maybe ScrubbedBytes -> ByteString -> m Signature
signBytes ImplicitAddressWithAlias
sender Maybe ScrubbedBytes
mbPassword (ByteString -> ByteString
addOperationPrefix ByteString
op)
return (Signature
signature', ByteString -> Signature -> ByteString
prepareOpForInjection ByteString
op Signature
signature')
let
updateOp :: OperationInput -> Maybe Mutez -> AppliedResult -> Bool -> m (OperationInput, Maybe (Signature, ByteString))
updateOp :: WithCommonOperationData (OperationInfo RPCInput)
-> Maybe Mutez
-> AppliedResult
-> Bool
-> m (WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString))
updateOp opToRun :: WithCommonOperationData (OperationInfo RPCInput)
opToRun@(WithCommonOperationData CommonOperationData
_ OperationInfo RPCInput
internalOp) Maybe Mutez
mbFee AppliedResult
ar Bool
isFirst = do
let gasSafetyGuard :: StringEncode Int64
gasSafetyGuard = StringEncode Int64
100
additionalGas :: StringEncode Int64
additionalGas = case OperationInfo RPCInput
internalOp of
OpTransferTicket{} -> StringEncode Int64
gasSafetyGuard
OpOriginate OriginationInfo RPCInput
_ -> StringEncode Int64
gasSafetyGuard
OpTransfer (TransactionOperation {Address
TezosMutez
ParametersInternal
toDestination :: TransactionOperation -> Address
toAmount :: TransactionOperation -> TezosMutez
toParameters :: TransactionOperation -> ParametersInternal
toAmount :: TezosMutez
toDestination :: Address
toParameters :: ParametersInternal
..}) -> case Address
toDestination of
MkAddress ImplicitAddress{} -> StringEncode Int64
0
MkAddress ContractAddress{} -> StringEncode Int64
gasSafetyGuard
MkAddress SmartRollupAddress{} -> StringEncode Int64
gasSafetyGuard
OpReveal RevealInfo RPCInput
_ -> StringEncode Int64
0
OpDelegation DelegationInfo RPCInput
_ -> StringEncode Int64
0
let storageLimit :: StringEncode Int64
storageLimit = [AppliedResult] -> ProtocolParameters -> StringEncode Int64
computeStorageLimit [AppliedResult
ar] ProtocolParameters
pp StringEncode Int64 -> StringEncode Int64 -> StringEncode Int64
forall a. Num a => a -> a -> a
+ StringEncode Int64
20
let gasLimit :: StringEncode Int64
gasLimit = Ratio (StringEncode Int64) -> StringEncode Int64
forall b. Integral b => Ratio (StringEncode Int64) -> b
forall a b. (RealFrac a, Integral b) => a -> b
ceiling (AppliedResult -> StringEncode Int64
arConsumedMilliGas AppliedResult
ar StringEncode Int64
-> StringEncode Int64 -> Ratio (StringEncode Int64)
forall a. Integral a => a -> a -> Ratio a
% StringEncode Int64
1000) StringEncode Int64 -> StringEncode Int64 -> StringEncode Int64
forall a. Num a => a -> a -> a
+ StringEncode Int64
additionalGas
updateCommonDataForFee :: Mutez -> CommonOperationData -> CommonOperationData
updateCommonDataForFee Mutez
fee =
StringEncode Int64
-> StringEncode Int64
-> TezosMutez
-> CommonOperationData
-> CommonOperationData
updateCommonData StringEncode Int64
gasLimit StringEncode Int64
storageLimit (Mutez -> TezosMutez
TezosMutez Mutez
fee)
(Mutez
_fee, WithCommonOperationData (OperationInfo RPCInput)
op, Maybe (Signature, ByteString)
mReadySignedOp) <- forall op extra (m :: * -> *).
Monad m =>
(Mutez -> m op) -> (op -> m (Mutez, extra)) -> m (Mutez, op, extra)
convergingFee
@OperationInput
@(Maybe (Signature, ByteString))
(\Mutez
fee ->
WithCommonOperationData (OperationInfo RPCInput)
-> m (WithCommonOperationData (OperationInfo RPCInput))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (WithCommonOperationData (OperationInfo RPCInput)
-> m (WithCommonOperationData (OperationInfo RPCInput)))
-> WithCommonOperationData (OperationInfo RPCInput)
-> m (WithCommonOperationData (OperationInfo RPCInput))
forall a b. (a -> b) -> a -> b
$ WithCommonOperationData (OperationInfo RPCInput)
opToRun WithCommonOperationData (OperationInfo RPCInput)
-> State (WithCommonOperationData (OperationInfo RPCInput)) ()
-> WithCommonOperationData (OperationInfo RPCInput)
forall s a. s -> State s a -> s
&~
(CommonOperationData -> Identity CommonOperationData)
-> WithCommonOperationData (OperationInfo RPCInput)
-> Identity (WithCommonOperationData (OperationInfo RPCInput))
forall a (f :: * -> *).
Functor f =>
(CommonOperationData -> f CommonOperationData)
-> WithCommonOperationData a -> f (WithCommonOperationData a)
wcoCommonDataL ((CommonOperationData -> Identity CommonOperationData)
-> WithCommonOperationData (OperationInfo RPCInput)
-> Identity (WithCommonOperationData (OperationInfo RPCInput)))
-> (CommonOperationData -> CommonOperationData)
-> State (WithCommonOperationData (OperationInfo RPCInput)) ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Mutez -> CommonOperationData -> CommonOperationData
updateCommonDataForFee Mutez
fee
)
(\WithCommonOperationData (OperationInfo RPCInput)
op -> do
ByteString
forgedOp <- NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
-> m ByteString
forgeOp (NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
-> m ByteString)
-> NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
-> m ByteString
forall a b. (a -> b) -> a -> b
$ OneItem
(NonEmpty (WithCommonOperationData (OperationInfo RPCInput)))
-> NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
forall x. One x => OneItem x -> x
one OneItem
(NonEmpty (WithCommonOperationData (OperationInfo RPCInput)))
WithCommonOperationData (OperationInfo RPCInput)
op
(Int
fullForgedOpLength, Maybe (Signature, ByteString)
mExtra) <-
if Bool
isFirst
then do
res :: (Signature, ByteString)
res@(Signature
_signature, ByteString
signedOp) <- ByteString -> m (Signature, ByteString)
signForgedOp ByteString
forgedOp
(Int, Maybe (Signature, ByteString))
-> m (Int, Maybe (Signature, ByteString))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> Int
forall i a.
(Integral i, Container a,
DefaultToInt (IsIntSubType Length i) i) =>
a -> i
length ByteString
signedOp, (Signature, ByteString) -> Maybe (Signature, ByteString)
forall a. a -> Maybe a
Just (Signature, ByteString)
res)
else
(Int, Maybe (Signature, ByteString))
-> m (Int, Maybe (Signature, ByteString))
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ByteString -> Int
forall i a.
(Integral i, Container a,
DefaultToInt (IsIntSubType Length i) i) =>
a -> i
length ByteString
forgedOp Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
32, Maybe (Signature, ByteString)
forall a. Maybe a
Nothing)
(Mutez, Maybe (Signature, ByteString))
-> m (Mutez, Maybe (Signature, ByteString))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
( Mutez -> (Mutez -> Mutez) -> Maybe Mutez -> Mutez
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (FeeConstants -> Int -> StringEncode Int64 -> Mutez
computeFee FeeConstants
ocFeeConstants Int
fullForgedOpLength StringEncode Int64
gasLimit) Mutez -> Mutez
forall a. a -> a
id Maybe Mutez
mbFee
, Maybe (Signature, ByteString)
mExtra
)
)
(WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString))
-> m (WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (WithCommonOperationData (OperationInfo RPCInput)
op, Maybe (Signature, ByteString)
mReadySignedOp)
let
zipWith4NE
:: (a -> b -> c -> d -> e) -> NonEmpty a -> NonEmpty b -> NonEmpty c -> NonEmpty d
-> NonEmpty e
zipWith4NE :: forall a b c d e.
(a -> b -> c -> d -> e)
-> NonEmpty a
-> NonEmpty b
-> NonEmpty c
-> NonEmpty d
-> NonEmpty e
zipWith4NE a -> b -> c -> d -> e
f (a
a :| [a]
as) (b
b :| [b]
bs) (c
c :| [c]
cs) (d
d :| [d]
ds) =
(a -> b -> c -> d -> e
f a
a b
b c
c d
d) e -> [e] -> NonEmpty e
forall a. a -> [a] -> NonEmpty a
:| (a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]
forall a b c d e.
(a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]
zipWith4 a -> b -> c -> d -> e
f [a]
as [b]
bs [c]
cs [d]
ds
(NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
updOps, NonEmpty (Maybe (Signature, ByteString))
readySignedOps) <- (NonEmpty
(WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString))
-> (NonEmpty (WithCommonOperationData (OperationInfo RPCInput)),
NonEmpty (Maybe (Signature, ByteString))))
-> m (NonEmpty
(WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString)))
-> m (NonEmpty (WithCommonOperationData (OperationInfo RPCInput)),
NonEmpty (Maybe (Signature, ByteString)))
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NonEmpty
(WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString))
-> (NonEmpty (WithCommonOperationData (OperationInfo RPCInput)),
NonEmpty (Maybe (Signature, ByteString)))
forall (f :: * -> *) a b. Functor f => f (a, b) -> (f a, f b)
NE.unzip (m (NonEmpty
(WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString)))
-> m (NonEmpty (WithCommonOperationData (OperationInfo RPCInput)),
NonEmpty (Maybe (Signature, ByteString))))
-> (NonEmpty
(m (WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString)))
-> m (NonEmpty
(WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString))))
-> NonEmpty
(m (WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString)))
-> m (NonEmpty (WithCommonOperationData (OperationInfo RPCInput)),
NonEmpty (Maybe (Signature, ByteString)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty
(m (WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString)))
-> m (NonEmpty
(WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString)))
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a.
Applicative f =>
NonEmpty (f a) -> f (NonEmpty a)
sequenceA (NonEmpty
(m (WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString)))
-> m (NonEmpty (WithCommonOperationData (OperationInfo RPCInput)),
NonEmpty (Maybe (Signature, ByteString))))
-> NonEmpty
(m (WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString)))
-> m (NonEmpty (WithCommonOperationData (OperationInfo RPCInput)),
NonEmpty (Maybe (Signature, ByteString)))
forall a b. (a -> b) -> a -> b
$
(WithCommonOperationData (OperationInfo RPCInput)
-> Maybe Mutez
-> AppliedResult
-> Bool
-> m (WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString)))
-> NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
-> NonEmpty (Maybe Mutez)
-> NonEmpty AppliedResult
-> NonEmpty Bool
-> NonEmpty
(m (WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString)))
forall a b c d e.
(a -> b -> c -> d -> e)
-> NonEmpty a
-> NonEmpty b
-> NonEmpty c
-> NonEmpty d
-> NonEmpty e
zipWith4NE WithCommonOperationData (OperationInfo RPCInput)
-> Maybe Mutez
-> AppliedResult
-> Bool
-> m (WithCommonOperationData (OperationInfo RPCInput),
Maybe (Signature, ByteString))
updateOp NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
opsToRun NonEmpty (Maybe Mutez)
mbFees NonEmpty AppliedResult
results (Bool
True Bool -> [Bool] -> NonEmpty Bool
forall a. a -> [a] -> NonEmpty a
:| Bool -> [Bool]
forall a. a -> [a]
repeat Bool
False)
(Signature
signature', ByteString
signedOp) <- case NonEmpty (Maybe (Signature, ByteString))
readySignedOps of
Just (Signature, ByteString)
readyOp :| [] -> (Signature, ByteString) -> m (Signature, ByteString)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Signature, ByteString)
readyOp
NonEmpty (Maybe (Signature, ByteString))
_ -> NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
-> m ByteString
forgeOp NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
updOps m ByteString
-> (ByteString -> m (Signature, ByteString))
-> m (Signature, ByteString)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ByteString -> m (Signature, ByteString)
signForgedOp
let preApplyOp :: PreApplyOperation
preApplyOp = PreApplyOperation
{ paoProtocol :: Text
paoProtocol = BlockConstants -> Text
bcProtocol BlockConstants
ocBlockConstants
, paoBranch :: BlockHash
paoBranch = BlockHash
ocLastBlockHash
, paoContents :: NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
paoContents = NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
updOps
, paoSignature :: Signature
paoSignature = Signature
signature'
}
(NonEmpty AppliedResult
ars2, [OperationResp WithSource]
iopsData) <- Either RunOperation PreApplyOperation
-> m (NonEmpty AppliedResult, [OperationResp WithSource])
forall (m :: * -> *).
HasTezosRpc m =>
Either RunOperation PreApplyOperation
-> m (NonEmpty AppliedResult, [OperationResp WithSource])
getAppliedResults (PreApplyOperation -> Either RunOperation PreApplyOperation
forall a b. b -> Either a b
Right PreApplyOperation
preApplyOp)
case forall {k} (a :: k). SingI a => Sing a
forall (a :: RunMode). SingI a => Sing a
sing @runMode of
Sing runMode
SingRunResult runMode
SDryRun -> do
let fees :: NonEmpty TezosMutez
fees = (WithCommonOperationData (OperationInfo RPCInput) -> TezosMutez)
-> NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
-> NonEmpty TezosMutez
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map (CommonOperationData -> TezosMutez
codFee (CommonOperationData -> TezosMutez)
-> (WithCommonOperationData (OperationInfo RPCInput)
-> CommonOperationData)
-> WithCommonOperationData (OperationInfo RPCInput)
-> TezosMutez
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithCommonOperationData (OperationInfo RPCInput)
-> CommonOperationData
forall a. WithCommonOperationData a -> CommonOperationData
wcoCommon) NonEmpty (WithCommonOperationData (OperationInfo RPCInput))
updOps
RunResult runMode -> m (RunResult runMode)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
return (RunResult runMode -> m (RunResult runMode))
-> RunResult runMode -> m (RunResult runMode)
forall a b. (a -> b) -> a -> b
$ NonEmpty AppliedResult
-> NonEmpty TezosMutez -> NonEmpty (AppliedResult, TezosMutez)
forall a b. NonEmpty a -> NonEmpty b -> NonEmpty (a, b)
NE.zip NonEmpty AppliedResult
ars2 NonEmpty TezosMutez
fees
Sing runMode
SingRunResult runMode
SRealRun -> do
OperationHash
operationHash <- m OperationHash -> m OperationHash
forall (m :: * -> *).
HasTezosRpc m =>
m OperationHash -> m OperationHash
waitForOperation (m OperationHash -> m OperationHash)
-> m OperationHash -> m OperationHash
forall a b. (a -> b) -> a -> b
$ HexJSONByteString -> m OperationHash
forall (m :: * -> *).
HasTezosRpc m =>
HexJSONByteString -> m OperationHash
injectOperation (ByteString -> HexJSONByteString
HexJSONByteString ByteString
signedOp)
let contractAddrs :: NonEmpty [KindedAddress 'AddressKindContract]
contractAddrs = AppliedResult -> [KindedAddress 'AddressKindContract]
arOriginatedContracts (AppliedResult -> [KindedAddress 'AddressKindContract])
-> NonEmpty AppliedResult
-> NonEmpty [KindedAddress 'AddressKindContract]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty AppliedResult
ars2
NonEmpty (OperationInfo Result)
opsRes <- NonEmpty
(OperationInfo ClientInput, [KindedAddress 'AddressKindContract])
-> ((OperationInfo ClientInput,
[KindedAddress 'AddressKindContract])
-> m (OperationInfo Result))
-> m (NonEmpty (OperationInfo Result))
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM (NonEmpty (OperationInfo ClientInput)
-> NonEmpty [KindedAddress 'AddressKindContract]
-> NonEmpty
(OperationInfo ClientInput, [KindedAddress 'AddressKindContract])
forall a b. NonEmpty a -> NonEmpty b -> NonEmpty (a, b)
NE.zip NonEmpty (OperationInfo ClientInput)
operations NonEmpty [KindedAddress 'AddressKindContract]
contractAddrs) (((OperationInfo ClientInput, [KindedAddress 'AddressKindContract])
-> m (OperationInfo Result))
-> m (NonEmpty (OperationInfo Result)))
-> ((OperationInfo ClientInput,
[KindedAddress 'AddressKindContract])
-> m (OperationInfo Result))
-> m (NonEmpty (OperationInfo Result))
forall a b. (a -> b) -> a -> b
$ \case
(OpTransfer TransferInfo ClientInput
_, [KindedAddress 'AddressKindContract]
addrs) -> do
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([KindedAddress 'AddressKindContract] -> Bool
forall t. Container t => t -> Bool
null [KindedAddress 'AddressKindContract]
addrs) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
Text -> m ()
forall env (m :: * -> *). WithLog env Message m => Text -> m ()
logInfo (Text -> m ()) -> (Text -> Text) -> Text -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.strip (Text -> m ()) -> Text -> m ()
forall a b. (a -> b) -> a -> b
$
Doc
"The following contracts were originated during transactions: " Doc -> Doc -> Text
forall b. FromDoc b => Doc -> Doc -> b
+|
[KindedAddress 'AddressKindContract] -> Doc
forall a (f :: * -> *). (Buildable a, Foldable f) => f a -> Doc
listF [KindedAddress 'AddressKindContract]
addrs Doc -> Doc -> Doc
forall a b. (Buildable a, FromDoc b) => a -> Doc -> b
|+ Doc
""
return $ TransferInfo Result -> OperationInfo Result
forall i. TransferInfo i -> OperationInfo i
OpTransfer (TransferInfo Result -> OperationInfo Result)
-> TransferInfo Result -> OperationInfo Result
forall a b. (a -> b) -> a -> b
$ (OperationResp WithSource -> Maybe (WithSource EventOperation))
-> [OperationResp WithSource] -> [WithSource EventOperation]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe OperationResp WithSource -> Maybe (WithSource EventOperation)
iopsDataToEmitOp [OperationResp WithSource]
iopsData
(OpTransferTicket TransferTicketInfo ClientInput
_, [KindedAddress 'AddressKindContract]
addrs) -> do
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([KindedAddress 'AddressKindContract] -> Bool
forall t. Container t => t -> Bool
null [KindedAddress 'AddressKindContract]
addrs) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
Text -> m ()
forall env (m :: * -> *). WithLog env Message m => Text -> m ()
logInfo (Text -> m ()) -> (Text -> Text) -> Text -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.strip (Text -> m ()) -> Text -> m ()
forall a b. (a -> b) -> a -> b
$
Doc
"The following contracts were originated during transactions: " Doc -> Doc -> Text
forall b. FromDoc b => Doc -> Doc -> b
+|
[KindedAddress 'AddressKindContract] -> Doc
forall a (f :: * -> *). (Buildable a, Foldable f) => f a -> Doc
listF [KindedAddress 'AddressKindContract]
addrs Doc -> Doc -> Doc
forall a b. (Buildable a, FromDoc b) => a -> Doc -> b
|+ Doc
""
return $ TransferTicketInfo Result -> OperationInfo Result
forall i. TransferTicketInfo i -> OperationInfo i
OpTransferTicket (TransferTicketInfo Result -> OperationInfo Result)
-> TransferTicketInfo Result -> OperationInfo Result
forall a b. (a -> b) -> a -> b
$ (OperationResp WithSource -> Maybe (WithSource EventOperation))
-> [OperationResp WithSource] -> [WithSource EventOperation]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe OperationResp WithSource -> Maybe (WithSource EventOperation)
iopsDataToEmitOp [OperationResp WithSource]
iopsData
(OpOriginate OriginationInfo ClientInput
_, []) ->
IncorrectRpcResponse -> m (OperationInfo Result)
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM IncorrectRpcResponse
RpcOriginatedNoContracts
(OpOriginate OriginationData{Maybe Mutez
Maybe KeyHash
Mutez
ContractAlias
Value st
Contract cp st
AliasBehavior
odName :: OriginationData -> ContractAlias
odAliasBehavior :: OriginationData -> AliasBehavior
odBalance :: OriginationData -> Mutez
odContract :: ()
odStorage :: ()
odDelegate :: OriginationData -> Maybe KeyHash
odMbFee :: OriginationData -> Maybe Mutez
odAliasBehavior :: AliasBehavior
odName :: ContractAlias
odBalance :: Mutez
odContract :: Contract cp st
odStorage :: Value st
odDelegate :: Maybe KeyHash
odMbFee :: Maybe Mutez
..}, [KindedAddress 'AddressKindContract
addr]) -> do
Text -> m ()
forall env (m :: * -> *). WithLog env Message m => Text -> m ()
logDebug (Text -> m ()) -> Text -> m ()
forall a b. (a -> b) -> a -> b
$ Doc
"Saving " Doc -> Doc -> Text
forall b. FromDoc b => Doc -> Doc -> b
+| KindedAddress 'AddressKindContract
addr KindedAddress 'AddressKindContract -> Doc -> Doc
forall a b. (Buildable a, FromDoc b) => a -> Doc -> b
|+ Doc
" for " Doc -> Doc -> Doc
forall b. FromDoc b => Doc -> Doc -> b
+| ContractAlias
odName ContractAlias -> Doc -> Doc
forall a b. (Buildable a, FromDoc b) => a -> Doc -> b
|+ Doc
"\n"
AliasBehavior
-> KindedAddress 'AddressKindContract -> ContractAlias -> m ()
forall (m :: * -> *).
HasTezosClient m =>
AliasBehavior
-> KindedAddress 'AddressKindContract -> ContractAlias -> m ()
rememberContract AliasBehavior
odAliasBehavior KindedAddress 'AddressKindContract
addr ContractAlias
odName
Text -> m ()
forall env (m :: * -> *). WithLog env Message m => Text -> m ()
logInfo (Text -> m ()) -> Text -> m ()
forall a b. (a -> b) -> a -> b
$ Text
"Originated contract: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ContractAlias -> Text
forall a b. (Buildable a, FromDoc b) => a -> b
pretty ContractAlias
odName
return $ OriginationInfo Result -> OperationInfo Result
forall i. OriginationInfo i -> OperationInfo i
OpOriginate KindedAddress 'AddressKindContract
OriginationInfo Result
addr
(OpOriginate OriginationInfo ClientInput
_, addrs :: [KindedAddress 'AddressKindContract]
addrs@(KindedAddress 'AddressKindContract
_ : KindedAddress 'AddressKindContract
_ : [KindedAddress 'AddressKindContract]
_)) ->
IncorrectRpcResponse -> m (OperationInfo Result)
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (IncorrectRpcResponse -> m (OperationInfo Result))
-> IncorrectRpcResponse -> m (OperationInfo Result)
forall a b. (a -> b) -> a -> b
$ [KindedAddress 'AddressKindContract] -> IncorrectRpcResponse
RpcOriginatedMoreContracts [KindedAddress 'AddressKindContract]
addrs
(OpReveal RevealInfo ClientInput
_, [KindedAddress 'AddressKindContract]
_) ->
OperationInfo Result -> m (OperationInfo Result)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (OperationInfo Result -> m (OperationInfo Result))
-> OperationInfo Result -> m (OperationInfo Result)
forall a b. (a -> b) -> a -> b
$ RevealInfo Result -> OperationInfo Result
forall i. RevealInfo i -> OperationInfo i
OpReveal ()
(OpDelegation DelegationInfo ClientInput
_, [KindedAddress 'AddressKindContract]
_) ->
OperationInfo Result -> m (OperationInfo Result)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (OperationInfo Result -> m (OperationInfo Result))
-> OperationInfo Result -> m (OperationInfo Result)
forall a b. (a -> b) -> a -> b
$ DelegationInfo Result -> OperationInfo Result
forall i. DelegationInfo i -> OperationInfo i
OpDelegation ()
NonEmpty AppliedResult
-> (Element (NonEmpty AppliedResult) -> m ()) -> m ()
forall t (m :: * -> *) b.
(Container t, Monad m) =>
t -> (Element t -> m b) -> m ()
forM_ NonEmpty AppliedResult
ars2 Element (NonEmpty AppliedResult) -> m ()
AppliedResult -> m ()
logStatistics
return (OperationHash
operationHash, NonEmpty (OperationInfo Result)
opsRes)
m (RunResult runMode)
-> (UnexpectedErrors -> m (RunResult runMode))
-> m (RunResult runMode)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
`catch` \case
(UnexpectedRunErrors [RunError]
errs) | Natural
retryCount Natural -> Natural -> Bool
forall a. Ord a => a -> a -> Bool
> Natural
0 -> do
Text -> m ()
forall env (m :: * -> *). WithLog env Message m => Text -> m ()
logError (Text -> m ()) -> Text -> m ()
forall a b. (a -> b) -> a -> b
$ Doc -> Text
forall a b. (Buildable a, FromDoc b) => a -> b
pretty (Doc -> Text) -> Doc -> Text
forall a b. (a -> b) -> a -> b
$ Doc -> Doc -> Doc
forall a. Buildable a => Doc -> a -> Doc
nameF Doc
"When injecting operations, there were unexpected errors" (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$
[RunError] -> Doc
forall a (f :: * -> *). (Buildable a, Foldable f) => f a -> Doc
blockListF [RunError]
errs
forall (runMode :: RunMode) (m :: * -> *) env.
(HasTezosRpc m, HasTezosClient m, WithClientLog env m,
SingI runMode) =>
Natural
-> ImplicitAddressWithAlias
-> NonEmpty (OperationInfo ClientInput)
-> m (RunResult runMode)
runOperationsNonEmptyHelper @runMode (Natural
retryCount Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
- Natural
1) ImplicitAddressWithAlias
sender NonEmpty (OperationInfo ClientInput)
operations
UnexpectedErrors
e -> UnexpectedErrors -> m (RunResult runMode)
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM UnexpectedErrors
e
where
iopsDataToEmitOp :: OperationResp WithSource -> Maybe (WithSource EventOperation)
iopsDataToEmitOp :: OperationResp WithSource -> Maybe (WithSource EventOperation)
iopsDataToEmitOp = \case
EventOpResp WithSource EventOperation
evt -> WithSource EventOperation -> Maybe (WithSource EventOperation)
forall a. a -> Maybe a
Just WithSource EventOperation
evt
OperationResp WithSource
_ -> Maybe (WithSource EventOperation)
forall a. Maybe a
Nothing
mayNeedSenderRevealing :: [OperationInfo i] -> Bool
mayNeedSenderRevealing :: forall i. [OperationInfo i] -> Bool
mayNeedSenderRevealing = (Element [OperationInfo i] -> Bool) -> [OperationInfo i] -> Bool
forall c b.
(Container c, BooleanMonoid b) =>
(Element c -> b) -> c -> b
any \case
OpTransfer{} -> Bool
True
OpTransferTicket{} -> Bool
True
OpOriginate{} -> Bool
True
OpReveal{} -> Bool
False
OpDelegation{} -> Bool
True
logStatistics :: AppliedResult -> m ()
logStatistics :: AppliedResult -> m ()
logStatistics AppliedResult
ar = do
let showTezosInt64 :: StringEncode Int64 -> Text
showTezosInt64 = Int64 -> Text
forall b a. (PrettyShow a, Show a, IsString b) => a -> b
show (Int64 -> Text)
-> (StringEncode Int64 -> Int64) -> StringEncode Int64 -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StringEncode Int64 -> Int64
forall a. StringEncode a -> a
unStringEncode
Text -> m ()
forall env (m :: * -> *). WithLog env Message m => Text -> m ()
logInfo (Text -> m ()) -> Text -> m ()
forall a b. (a -> b) -> a -> b
$ Text
"Consumed milli-gas: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> StringEncode Int64 -> Text
showTezosInt64 (AppliedResult -> StringEncode Int64
arConsumedMilliGas AppliedResult
ar)
Text -> m ()
forall env (m :: * -> *). WithLog env Message m => Text -> m ()
logInfo (Text -> m ()) -> Text -> m ()
forall a b. (a -> b) -> a -> b
$ Text
"Storage size: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> StringEncode Int64 -> Text
showTezosInt64 (AppliedResult -> StringEncode Int64
arStorageSize AppliedResult
ar)
Text -> m ()
forall env (m :: * -> *). WithLog env Message m => Text -> m ()
logInfo (Text -> m ()) -> Text -> m ()
forall a b. (a -> b) -> a -> b
$ Text
"Paid storage size diff: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> StringEncode Int64 -> Text
showTezosInt64 (AppliedResult -> StringEncode Int64
arPaidStorageDiff AppliedResult
ar)