Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Core primitive Tezos types.
Synopsis
- newtype Mutez = UnsafeMutez {}
- tz :: QuasiQuoter
- mkMutez :: Integral i => i -> Either Text Mutez
- toMutez :: (Integral a, CheckIntSubType a Word63) => a -> Mutez
- addMutez :: Mutez -> Mutez -> Maybe Mutez
- unsafeAddMutez :: HasCallStack => Mutez -> Mutez -> Mutez
- subMutez :: Mutez -> Mutez -> Maybe Mutez
- unsafeSubMutez :: HasCallStack => Mutez -> Mutez -> Mutez
- mulMutez :: Integral a => Mutez -> a -> Maybe Mutez
- unsafeMulMutez :: Mutez -> Natural -> Mutez
- divModMutez :: Mutez -> Mutez -> Maybe (Word63, Mutez)
- divModMutezInt :: Integral a => Mutez -> a -> Maybe (Mutez, Mutez)
- zeroMutez :: Mutez
- oneMutez :: Mutez
- prettyTez :: Mutez -> Text
- newtype Timestamp = Timestamp {}
- timestampToSeconds :: Integral a => Timestamp -> a
- timestampFromSeconds :: Integer -> Timestamp
- timestampFromUTCTime :: UTCTime -> Timestamp
- timestampToUTCTime :: Timestamp -> UTCTime
- timestampPlusSeconds :: Timestamp -> Integer -> Timestamp
- formatTimestamp :: Timestamp -> Text
- parseTimestamp :: Text -> Maybe Timestamp
- timestampQuote :: QuasiQuoter
- getCurrentTime :: IO Timestamp
- farFuture :: Timestamp
- farPast :: Timestamp
- newtype ChainId = UnsafeChainId {}
- mkChainId :: ByteString -> Either ParseChainIdError ChainId
- dummyChainId :: ChainId
- formatChainId :: ChainId -> Text
- mformatChainId :: ChainId -> MText
- parseChainId :: Text -> Either ParseChainIdError ChainId
- chainIdLength :: Int
Mutez
Mutez is a wrapper over integer data type. 1 mutez is 1 token (μTz).
The constructor is marked Unsafe since GHC does not warn on overflowing
literals (exceeding custom Word63
type bounds), thus the resultant
Mutez
value may get truncated silently.
>>>
UnsafeMutez 9223372036854775809
UnsafeMutez {unMutez = 1}
Instances
FromJSON Mutez Source # | |
ToJSON Mutez Source # | |
Defined in Morley.Tezos.Core | |
Bounded Mutez Source # | |
Enum Mutez Source # | |
Generic Mutez Source # | |
Show Mutez Source # | |
NFData Mutez Source # | |
Defined in Morley.Tezos.Core | |
Buildable Mutez Source # | |
Defined in Morley.Tezos.Core | |
Eq Mutez Source # | |
Ord Mutez Source # | |
HasRPCRepr Mutez Source # | |
Defined in Morley.AsRPC | |
TypeHasDoc Mutez Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc | |
IsoValue Mutez Source # | |
HasCLReader Mutez Source # | |
Defined in Morley.Tezos.Core | |
type Rep Mutez Source # | |
Defined in Morley.Tezos.Core | |
type AsRPC Mutez Source # | |
Defined in Morley.AsRPC | |
type TypeDocFieldDescriptions Mutez Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc | |
type ToT Mutez Source # | |
Defined in Morley.Michelson.Typed.Haskell.Value |
tz :: QuasiQuoter Source #
Quotes a Mutez
value.
The value is in XTZ, i.e. 1e6 Mutez
, with optional suffix representing
a unit:
k
,kilo
-- 1000 XTZM
,Mega
,mega
-- 1000000 XTZm
,milli
-- 0.001 XTZu
,μ
,micro
-- 0.000001 XTZ
This is the safest and recommended way to create Mutez
from a numeric literal.
The suffix can be separated from the number by whitespace.
You can also use underscores as a delimiter (those will be ignored), and
scientific notation, e.g. 123.456e6
. Note that if the scientific notation
represents a mutez fraction, that is a compile-time error.
>>>
[tz|123|]
UnsafeMutez {unMutez = 123000000}
>>>
[tz|123k|]
UnsafeMutez {unMutez = 123000000000}
>>>
[tz|123 kilo|]
UnsafeMutez {unMutez = 123000000000}
>>>
[tz|123M|]
UnsafeMutez {unMutez = 123000000000000}
>>>
[tz|123 Mega|]
UnsafeMutez {unMutez = 123000000000000}
>>>
[tz|123 mega|]
UnsafeMutez {unMutez = 123000000000000}
>>>
[tz|123e6|]
UnsafeMutez {unMutez = 123000000000000}
>>>
[tz|123m|]
UnsafeMutez {unMutez = 123000}
>>>
[tz|123 milli|]
UnsafeMutez {unMutez = 123000}
>>>
[tz|123u|]
UnsafeMutez {unMutez = 123}
>>>
[tz|123μ|]
UnsafeMutez {unMutez = 123}
>>>
[tz|123 micro|]
UnsafeMutez {unMutez = 123}
>>>
[tz| 123.456_789 |]
UnsafeMutez {unMutez = 123456789}
>>>
[tz|123.456u|]
... ... error: ... • The number is a mutez fraction. The smallest possible subdivision is 0.000001 XTZ ...
>>>
[tz|0.012_345_6|]
... ... error: ... • The number is a mutez fraction. The smallest possible subdivision is 0.000001 XTZ ...
>>>
[tz| 9223372.036854775807 M |]
UnsafeMutez {unMutez = 9223372036854775807}
>>>
[tz| 9223372.036854775808 M |]
... ... error: ... • The number is out of mutez bounds. It must be between 0 and 9223372036854.775807 XTZ (inclusive). ...
>>>
[tz| -1 |]
... ... error: ... • The number is out of mutez bounds. It must be between 0 and 9223372036854.775807 XTZ (inclusive). ...
mkMutez :: Integral i => i -> Either Text Mutez Source #
Safely creates Mutez
checking for
overflow and underflow. Accepts a number of any type.
unsafeAddMutez :: HasCallStack => Mutez -> Mutez -> Mutez Source #
Partial addition of Mutez
, should be used only if you're
sure there'll be no overflow.
unsafeSubMutez :: HasCallStack => Mutez -> Mutez -> Mutez Source #
Partial subtraction of Mutez
, should be used only if you're
sure there'll be no underflow.
unsafeMulMutez :: Mutez -> Natural -> Mutez Source #
Partial multiplication of Mutez
and an Natural number.
Should be used only if you're sure there'll be no overflow.
divModMutez :: Mutez -> Mutez -> Maybe (Word63, Mutez) Source #
Euclidian division of two Mutez
values.
divModMutezInt :: Integral a => Mutez -> a -> Maybe (Mutez, Mutez) Source #
Euclidian division of Mutez
and a number.
prettyTez :: Mutez -> Text Source #
>>>
putTextLn $ prettyTez [tz|420u|]
0.00042 ꜩ
>>>
putTextLn $ prettyTez [tz|42|]
42 ꜩ
Timestamp
Time in the real world. Use the functions below to convert it to/from Unix time in seconds.
Instances
timestampToSeconds :: Integral a => Timestamp -> a Source #
timestampPlusSeconds :: Timestamp -> Integer -> Timestamp Source #
Add given amount of seconds to a Timestamp
.
formatTimestamp :: Timestamp -> Text Source #
Display timestamp in human-readable way as used by Michelson. Uses UTC timezone, though maybe we should take it as an argument.
NB: this will render timestamp with up to seconds precision.
timestampQuote :: QuasiQuoter Source #
Quote a value of type Timestamp
in yyyy-mm-ddThh:mm:ss[.sss]Z
format.
>>>
formatTimestamp [timestampQuote| 2019-02-21T16:54:12.2344523Z |]
"2019-02-21T16:54:12Z"
Inspired by 'time-quote' library.
farFuture :: Timestamp Source #
Timestamp which is always greater than result of getCurrentTime
.
Timestamp which is always less than result of getCurrentTime
.
ChainId
Identifier of a network (babylonnet, mainnet, test network or other). Evaluated as hash of the genesis block.
The only operation supported for this type is packing. Use case: multisig contract, for instance, now includes chain ID into signed data "in order to add extra replay protection between the main chain and the test chain".
Instances
FromJSON ChainId Source # | |
ToJSON ChainId Source # | |
Defined in Morley.Tezos.Core | |
Generic ChainId Source # | |
Show ChainId Source # | |
NFData ChainId Source # | |
Defined in Morley.Tezos.Core | |
Buildable ChainId Source # | |
Defined in Morley.Tezos.Core | |
Eq ChainId Source # | |
Ord ChainId Source # | |
HasRPCRepr ChainId Source # | |
Defined in Morley.AsRPC | |
TypeHasDoc ChainId Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc | |
IsoValue ChainId Source # | |
type Rep ChainId Source # | |
Defined in Morley.Tezos.Core type Rep ChainId = D1 ('MetaData "ChainId" "Morley.Tezos.Core" "morley-1.19.1-inplace" 'True) (C1 ('MetaCons "UnsafeChainId" 'PrefixI 'True) (S1 ('MetaSel ('Just "unChainId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |
type AsRPC ChainId Source # | |
Defined in Morley.AsRPC | |
type TypeDocFieldDescriptions ChainId Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc | |
type ToT ChainId Source # | |
Defined in Morley.Michelson.Typed.Haskell.Value |
mkChainId :: ByteString -> Either ParseChainIdError ChainId Source #
Construct chain ID from raw bytes.
dummyChainId :: ChainId Source #
Identifier of a pseudo network.
formatChainId :: ChainId -> Text Source #
Pretty print ChainId
as it is displayed e.g. in
octez-client rpc get chainsmain/chain_id
call.
Example of produced value: NetXUdfLh6Gm88t
.
mformatChainId :: ChainId -> MText Source #
chainIdLength :: Int Source #