module Morley.Client.TezosClient.Types
( CmdArg (..)
, CalcOriginationFeeData (..)
, CalcTransferFeeData (..)
, TezosClientEnv (..)
, HasTezosClientEnv (..)
, SecretKeyEncryption (..)
, AliasBehavior (..)
, tceEndpointUrlL
, tceTezosClientPathL
, tceMbTezosClientDataDirL
, tceAliasMapL
) where
import Data.Aeson (KeyValue(..), ToJSON(..), object)
import Data.ByteArray (ScrubbedBytes)
import Data.Fixed (E6, Fixed(..))
import Fmt (Buildable(..), pretty, prettyText)
import Morley.Util.Lens (makeLensesWith, postfixLFields)
import Servant.Client (BaseUrl(..), showBaseUrl)
import Text.Hex (encodeHex)
import Morley.Client.RPC.Types (OperationHash)
import Morley.Client.Types.AliasesAndAddresses
import Morley.Client.Util
import Morley.Micheline
import Morley.Michelson.Printer
import Morley.Michelson.Typed (Contract, EpName, Value)
import Morley.Michelson.Typed qualified as T
import Morley.Tezos.Address
import Morley.Tezos.Address.Alias (AddressOrAlias(..), Alias)
import Morley.Tezos.Core
import Morley.Tezos.Crypto
class CmdArg a where
toCmdArg :: a -> String
default toCmdArg :: Buildable a => a -> String
toCmdArg = a -> String
forall a b. (Buildable a, FromDoc b) => a -> b
pretty
instance CmdArg Text where
instance CmdArg LText where
instance CmdArg Word16 where
instance CmdArg SecretKey where
toCmdArg :: SecretKey -> String
toCmdArg = Text -> String
forall a. CmdArg a => a -> String
toCmdArg (Text -> String) -> (SecretKey -> Text) -> SecretKey -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SecretKey -> Text
formatSecretKey
instance CmdArg (KindedAddress kind) where
instance CmdArg Address where
instance CmdArg ByteString where
toCmdArg :: ByteString -> String
toCmdArg = Text -> String
forall a. CmdArg a => a -> String
toCmdArg (Text -> String) -> (ByteString -> Text) -> ByteString -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text
"0x" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> (ByteString -> Text) -> ByteString -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
encodeHex
instance CmdArg EpName where
toCmdArg :: EpName -> String
toCmdArg = Text -> String
forall a. CmdArg a => a -> String
toCmdArg (Text -> String) -> (EpName -> Text) -> EpName -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EpName -> Text
epNameToTezosEp
instance CmdArg Mutez where
toCmdArg :: Mutez -> String
toCmdArg Mutez
m = Fixed E6 -> String
forall b a. (PrettyShow a, Show a, IsString b) => a -> b
show (Fixed E6 -> String) -> (Integer -> Fixed E6) -> Integer -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (a :: k). Integer -> Fixed a
MkFixed @_ @E6 (Integer -> String) -> Integer -> String
forall a b. (a -> b) -> a -> b
$ Word63 -> Integer
forall a b. (Integral a, Integral b, CheckIntSubType a b) => a -> b
fromIntegral (Mutez -> Word63
unMutez Mutez
m)
instance T.UntypedValScope t => CmdArg (Value t) where
toCmdArg :: Value t -> String
toCmdArg = LText -> String
forall a. CmdArg a => a -> String
toCmdArg (LText -> String) -> (Value t -> LText) -> Value t -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Value t -> LText
forall (t :: T). UntypedValScope t => Bool -> Value t -> LText
printTypedValue Bool
True
instance CmdArg (Contract cp st) where
toCmdArg :: Contract cp st -> String
toCmdArg = LText -> String
forall a. ToString a => a -> String
toString (LText -> String)
-> (Contract cp st -> LText) -> Contract cp st -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Contract cp st -> LText
forall (p :: T) (s :: T). Bool -> Contract p s -> LText
printTypedContract Bool
True
instance CmdArg BaseUrl where
toCmdArg :: BaseUrl -> String
toCmdArg = BaseUrl -> String
showBaseUrl
instance CmdArg OperationHash
instance CmdArg (Alias kind) where
instance CmdArg (AddressOrAlias kind) where
data SecretKeyEncryption
= UnencryptedKey
| EncryptedKey
| LedgerKey
deriving stock (SecretKeyEncryption -> SecretKeyEncryption -> Bool
(SecretKeyEncryption -> SecretKeyEncryption -> Bool)
-> (SecretKeyEncryption -> SecretKeyEncryption -> Bool)
-> Eq SecretKeyEncryption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SecretKeyEncryption -> SecretKeyEncryption -> Bool
$c/= :: SecretKeyEncryption -> SecretKeyEncryption -> Bool
== :: SecretKeyEncryption -> SecretKeyEncryption -> Bool
$c== :: SecretKeyEncryption -> SecretKeyEncryption -> Bool
Eq, Int -> SecretKeyEncryption -> ShowS
[SecretKeyEncryption] -> ShowS
SecretKeyEncryption -> String
(Int -> SecretKeyEncryption -> ShowS)
-> (SecretKeyEncryption -> String)
-> ([SecretKeyEncryption] -> ShowS)
-> Show SecretKeyEncryption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SecretKeyEncryption] -> ShowS
$cshowList :: [SecretKeyEncryption] -> ShowS
show :: SecretKeyEncryption -> String
$cshow :: SecretKeyEncryption -> String
showsPrec :: Int -> SecretKeyEncryption -> ShowS
$cshowsPrec :: Int -> SecretKeyEncryption -> ShowS
Show)
data TezosClientEnv = TezosClientEnv
{ TezosClientEnv -> BaseUrl
tceEndpointUrl :: BaseUrl
, TezosClientEnv -> String
tceTezosClientPath :: FilePath
, TezosClientEnv -> Maybe String
tceMbTezosClientDataDir :: Maybe FilePath
, TezosClientEnv -> MVar (Maybe AliasesAndAddresses)
tceAliasMap :: MVar (Maybe AliasesAndAddresses)
}
makeLensesWith postfixLFields ''TezosClientEnv
class HasTezosClientEnv env where
tezosClientEnvL :: Lens' env TezosClientEnv
data CalcTransferFeeData = forall t kind. T.UntypedValScope t => CalcTransferFeeData
{ ()
ctfdTo :: AddressOrAlias kind
, ()
ctfdParam :: Value t
, CalcTransferFeeData -> EpName
ctfdEp :: EpName
, CalcTransferFeeData -> TezosMutez
ctfdAmount :: TezosMutez
}
instance ToJSON CalcTransferFeeData where
toJSON :: CalcTransferFeeData -> Value
toJSON CalcTransferFeeData{EpName
AddressOrAlias kind
Value t
TezosMutez
ctfdAmount :: TezosMutez
ctfdEp :: EpName
ctfdParam :: Value t
ctfdTo :: AddressOrAlias kind
ctfdAmount :: CalcTransferFeeData -> TezosMutez
ctfdEp :: CalcTransferFeeData -> EpName
ctfdParam :: ()
ctfdTo :: ()
..} = [Pair] -> Value
object
[ Key
"destination" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= AddressOrAlias kind -> Text
forall a. Buildable a => a -> Text
prettyText AddressOrAlias kind
ctfdTo
, Key
"amount" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (forall a. IsString a => String -> a
fromString @Text (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Mutez -> String
forall a. CmdArg a => a -> String
toCmdArg (Mutez -> String) -> Mutez -> String
forall a b. (a -> b) -> a -> b
$ TezosMutez -> Mutez
unTezosMutez TezosMutez
ctfdAmount)
, Key
"arg" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (forall a. IsString a => String -> a
fromString @Text (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Value t -> String
forall a. CmdArg a => a -> String
toCmdArg Value t
ctfdParam)
, Key
"entrypoint" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (forall a. IsString a => String -> a
fromString @Text (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ EpName -> String
forall a. CmdArg a => a -> String
toCmdArg EpName
ctfdEp)
]
data CalcOriginationFeeData cp st = forall kind. CalcOriginationFeeData
{ ()
cofdFrom :: AddressOrAlias kind
, forall (cp :: T) (st :: T).
CalcOriginationFeeData cp st -> TezosMutez
cofdBalance :: TezosMutez
, forall (cp :: T) (st :: T).
CalcOriginationFeeData cp st -> Maybe ScrubbedBytes
cofdMbFromPassword :: Maybe ScrubbedBytes
, forall (cp :: T) (st :: T).
CalcOriginationFeeData cp st -> Contract cp st
cofdContract :: Contract cp st
, forall (cp :: T) (st :: T).
CalcOriginationFeeData cp st -> Value st
cofdStorage :: Value st
, forall (cp :: T) (st :: T).
CalcOriginationFeeData cp st -> TezosInt64
cofdBurnCap :: TezosInt64
}
data AliasBehavior
= DontSaveAlias
| KeepDuplicateAlias
| OverwriteDuplicateAlias
| ForbidDuplicateAlias
deriving stock (AliasBehavior -> AliasBehavior -> Bool
(AliasBehavior -> AliasBehavior -> Bool)
-> (AliasBehavior -> AliasBehavior -> Bool) -> Eq AliasBehavior
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AliasBehavior -> AliasBehavior -> Bool
$c/= :: AliasBehavior -> AliasBehavior -> Bool
== :: AliasBehavior -> AliasBehavior -> Bool
$c== :: AliasBehavior -> AliasBehavior -> Bool
Eq, Eq AliasBehavior
Eq AliasBehavior
-> (AliasBehavior -> AliasBehavior -> Ordering)
-> (AliasBehavior -> AliasBehavior -> Bool)
-> (AliasBehavior -> AliasBehavior -> Bool)
-> (AliasBehavior -> AliasBehavior -> Bool)
-> (AliasBehavior -> AliasBehavior -> Bool)
-> (AliasBehavior -> AliasBehavior -> AliasBehavior)
-> (AliasBehavior -> AliasBehavior -> AliasBehavior)
-> Ord AliasBehavior
AliasBehavior -> AliasBehavior -> Bool
AliasBehavior -> AliasBehavior -> Ordering
AliasBehavior -> AliasBehavior -> AliasBehavior
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: AliasBehavior -> AliasBehavior -> AliasBehavior
$cmin :: AliasBehavior -> AliasBehavior -> AliasBehavior
max :: AliasBehavior -> AliasBehavior -> AliasBehavior
$cmax :: AliasBehavior -> AliasBehavior -> AliasBehavior
>= :: AliasBehavior -> AliasBehavior -> Bool
$c>= :: AliasBehavior -> AliasBehavior -> Bool
> :: AliasBehavior -> AliasBehavior -> Bool
$c> :: AliasBehavior -> AliasBehavior -> Bool
<= :: AliasBehavior -> AliasBehavior -> Bool
$c<= :: AliasBehavior -> AliasBehavior -> Bool
< :: AliasBehavior -> AliasBehavior -> Bool
$c< :: AliasBehavior -> AliasBehavior -> Bool
compare :: AliasBehavior -> AliasBehavior -> Ordering
$ccompare :: AliasBehavior -> AliasBehavior -> Ordering
Ord, Int -> AliasBehavior
AliasBehavior -> Int
AliasBehavior -> [AliasBehavior]
AliasBehavior -> AliasBehavior
AliasBehavior -> AliasBehavior -> [AliasBehavior]
AliasBehavior -> AliasBehavior -> AliasBehavior -> [AliasBehavior]
(AliasBehavior -> AliasBehavior)
-> (AliasBehavior -> AliasBehavior)
-> (Int -> AliasBehavior)
-> (AliasBehavior -> Int)
-> (AliasBehavior -> [AliasBehavior])
-> (AliasBehavior -> AliasBehavior -> [AliasBehavior])
-> (AliasBehavior -> AliasBehavior -> [AliasBehavior])
-> (AliasBehavior
-> AliasBehavior -> AliasBehavior -> [AliasBehavior])
-> Enum AliasBehavior
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: AliasBehavior -> AliasBehavior -> AliasBehavior -> [AliasBehavior]
$cenumFromThenTo :: AliasBehavior -> AliasBehavior -> AliasBehavior -> [AliasBehavior]
enumFromTo :: AliasBehavior -> AliasBehavior -> [AliasBehavior]
$cenumFromTo :: AliasBehavior -> AliasBehavior -> [AliasBehavior]
enumFromThen :: AliasBehavior -> AliasBehavior -> [AliasBehavior]
$cenumFromThen :: AliasBehavior -> AliasBehavior -> [AliasBehavior]
enumFrom :: AliasBehavior -> [AliasBehavior]
$cenumFrom :: AliasBehavior -> [AliasBehavior]
fromEnum :: AliasBehavior -> Int
$cfromEnum :: AliasBehavior -> Int
toEnum :: Int -> AliasBehavior
$ctoEnum :: Int -> AliasBehavior
pred :: AliasBehavior -> AliasBehavior
$cpred :: AliasBehavior -> AliasBehavior
succ :: AliasBehavior -> AliasBehavior
$csucc :: AliasBehavior -> AliasBehavior
Enum)